LivelyKernel / lively.vm

Controlled JavaScript code execution and instrumentation.
12 stars 2 forks source link

new.target not supported #6

Closed JensLincke closed 7 years ago

JensLincke commented 8 years ago

The following code cannot be executed:

class Foo {
  constructor() {
    if (new.target === Foo) {
      throw new TypeError('Cannot construct Foo directly');
    }
  }
}

And produces the following error

lively.vm evalCodeTransform not working: SyntaxError: workspace://1: Unexpected token (8:28)
   6 |             key: Symbol.for('lively-instance-initialize'),
   7 |             value: function Foo_initialize_() {
>  8 |                 if ([object Object].[object Object] === __lvVarRecorder.Foo) {
     |                             ^
   9 |                     throw new TypeError('Cannot construct Foo directly');
  10 |                 }
  11 |             }
    at Parser.pp.raise (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:65149:13)
    at Parser.pp.unexpected (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:66379:8)
    at Parser.pp.expect (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:66373:33)
    at Parser.pp.parseExprList (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:64962:12)
    at Parser.pp.parseExprAtom (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:64564:28)
    at Parser.eval [as parseExprAtom] (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:67755:22)
    at Parser.pp.parseExprSubscripts (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:64413:19)
    at Parser.pp.parseMaybeUnary (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:64394:19)
    at Parser.pp.parseExprOps (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:64340:19)
    at Parser.pp.parseMaybeConditional (https://livelykernel.github.io/lively4-core/src/external/babel-browser.js:64322:19)

original error report: https://github.com/LivelyKernel/lively4-core/issues/66

rksm commented 8 years ago

This is an escodegen bug. I created a PR here: https://github.com/estools/escodegen/pull/319 While that isn't part of the main escodegen lib I'll switch over to our fork.

rksm commented 8 years ago

Leaving this open until escodegen merges. It's fixed in lively.ast/lively.vm/lively.modules in the recent version though.