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 field not recognized inside an enclosing class #1313

Closed
joelhecht opened this issue Nov 28, 2022 · 2 comments
Closed

Private field not recognized inside an enclosing class #1313

joelhecht opened this issue Nov 28, 2022 · 2 comments
Labels

Comments

@joelhecht
Copy link

Bug report

Hello,
It seems that there's a regression when handling with private fileds introduced in version 5.16.0.
I did not encounter this problem with version 5.15.1.

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

Complete CLI command or minify() options used
npx terser my-class.js

terser input

Content of my-class.js file:

class My_class {
    #private_field = 123;

    fn() {
        const c = new (class b {})(); // <-- removing this line removes the parse error
        return this.#private_field;
    }
}

terser output or error

Parse error at my-class.js:6,14
                return this.#private_field;
                            ^
ERROR: Private field must be used in an enclosing class
    at js_error (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:554:11)
    at croak (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:1278:9)
    at subscripts (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:3235:17)
    at expr_atom (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:2556:20)
    at maybe_unary (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:3374:19)
    at expr_ops (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:3425:24)
    at maybe_conditional (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:3430:20)
    at maybe_assign (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:3507:20)
    at expression (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:3532:24)
    at statement (C:\dev.local\ui-test\packages\atomics\node_modules\terser\dist\bundle.min.js:1491:29)

Expected result
(obtained with terser 5.15.1)

class My_class{#private_field=123;fn(){const c=new class b{};return this.#private_field}}
@fabiosantoscode
Copy link
Collaborator

Thanks for reporting this!

@iz-iznogood
Copy link

Hello,

we are experiencing the same error when using terser plugin in webpack
Any chance of a workaround?
I cannot locate the problematic file, the project is very large

Thanks

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

No branches or pull requests

3 participants