overlookmotel/livepack

Instrumentation throws on `new.target` at top level in CommonJS files or in `eval()`

overlookmotel opened this issue · 4 comments

new.target is legal anywhere in CommonJS files (as they're in a function wrapper).

Instrumentation throws when parsing such code:

SyntaxError: `new.target` can only be used in functions or class properties.

Ditto in code in eval() which is nested in a function e.g.:

function f() {
  return eval('new.target');
}
f();

Can only be fixed once babel/babel#15114 is merged.

Can only be fixed once babel/babel#15114 is merged.

errorRecovery can be enabled, which will allow you to ignore this error.
https://astexplorer.net/#/gist/98fb8d9b7576f17dd25833a501d5ffc2/888a4d9d492797d45cef8a76f319f8d86498d7d3

I wasn't aware of the errorRecovery option. Thanks loads for your help @liuxingbaoyu.

babel/babel#15114 has now been merged, adding a allowNewTargetOutsideFunction option for parser. So can remove the errorRecovery workaround once new release of Babel drops.

allowNewTargetOutsideFunction option is in Babel v7.21.0.