Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
overlookmotel opened this issue Nov 5, 2022 · 4 comments
Labels
bug Something isn't working eval Issue related to `eval`

Comments

@overlookmotel
Copy link
Owner

overlookmotel commented Nov 5, 2022

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.

@overlookmotel overlookmotel added bug Something isn't working eval Issue related to `eval` labels Nov 5, 2022
@liuxingbaoyu
Copy link

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

@overlookmotel
Copy link
Owner Author

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

@overlookmotel overlookmotel reopened this Feb 18, 2023
@overlookmotel
Copy link
Owner Author

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.

@overlookmotel
Copy link
Owner Author

allowNewTargetOutsideFunction option is in Babel v7.21.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working eval Issue related to `eval`
Projects
None yet
Development

No branches or pull requests

2 participants