escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Wrong code generation for new.target meta node

Open sanex3339 opened this issue 6 years ago • 1 comments

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) {}
    }
}

sanex3339 avatar Apr 18 '18 22:04 sanex3339

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

fabiosantoscode avatar Jun 24 '18 21:06 fabiosantoscode