escodegen
escodegen copied to clipboard
Wrong code generation for new.target meta node
Example source code
class Foo {
constructor() {
if (new.target === Foo) {}
}
}
AST: http://esprima.org/demo/parse.html?code=class%20Foo%20%7B%0A%20%20%20%20constructor()%20%7B%0A%20%20%20%20%20%20%20%20if%20(new.target%20%3D%3D%3D%20Foo)%20%7B%7D%0A%20%20%20%20%7D%0A%7D%0A
Generated code from AST will be like:
class Foo {
constructor() {
if ([object Object].[object Object] === Foo) {}
}
}
Bumped into this when adding ES6 support to UglifyJS.
Had to insert an ugly string.replace.
https://github.com/fabiosantoscode/terser/blob/master/test/mocha/spidermonkey.js#L146