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

Private fields, in and precedence (?) #1519

Closed
jakubledl opened this issue Apr 18, 2024 · 1 comment
Closed

Private fields, in and precedence (?) #1519

jakubledl opened this issue Apr 18, 2024 · 1 comment

Comments

@jakubledl
Copy link

Bug report

Version (complete output of terser -V or specific git commit)

terser 5.30.3

Complete CLI command or minify() options used

terser input.js --compress --mangle

terser input

class Test {
    #test;

    test(num, obj) {
        return num === 2 && #test in obj;
    }
}

const t = new Test();
console.log(t.test(2, {}));

terser output or error

Parse error at input.js:5,28
        return num === 2 && #test in obj;
                            ^
ERROR: Unexpected token: privatename (test)
    at ...

Expected result

class Test{#t;test(t,s){return 2===t&&#t in s}}const t=new Test;console.log(t.test(2,{}));

Version 5.30.2 works and gives the expected output, 5.30.3 gives the error. The input is valid code, works in browsers and node.

Changing the offending line to

return (num === 2) && (#test in obj);

makes the error goes away, so maybe the problem is with operator precedence and 0e04a22 might be to blame? Both in and === have higher precedence than &&, so the two return statements should be entirely equivalent.

@fabiosantoscode
Copy link
Collaborator

I've fixed it. Since a lone #privateprop is not a valid expression, the detection for #private in needs to happen in more places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants