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
Static class properties not referenced properly in obfuscated code #1362
Comments
Are you also using Rollup, and then feeding the output to Webpack? I ran into this issue here: webpack/webpack#16763 A potential fix could be for Terser to not shadow the imports. |
Yes, the same issue. This potential fix is welcome. |
This seems safe to me. The name So If you start referencing |
As a side note, Terser doesn't create |
I believe this change started in Rollup at rollup/rollup#4827 and that this isn't a Terser bug, but is a Webpack bug, and any change to Terser, would be a workaround to avoid the Webpack bug, so I'd completely understand if you don't want to make any changes. |
Just to confirm, rollup creates |
Bug report or Feature request? Bug report
Version 5.16.8
The problem could be observed with a lot of code. Small piece cannot reproduce the problem. I'll try to explain with some pseudo code and short description of it.
The problem affects only es syntax. Example class A constructor has an argument 'type' and static property 'Type'. After bundling something curious is observed. import 'ns' is transformed as 'e' in obfuscated code. For some reason class A is also named 'e'. Terser tries to fix this with 'let Ht = class e', so class 'e' is 'Ht'. Next references looks fine and on class 'Ht' is assigned property 'Type'. But in constructor we can find 'e.Type.TypeA', which should be 'Ht.Type.TypeA'. The questions here is if namespace 'e' is reserved already, why is needed this assignment: 'let Ht = class e', it could be just 'class Ht'. If keeping of the assignment is needed for some reason, static props should be properly referenced from the transforming code.
terser
inputterser
outputOutside of any other context this is properly interpreted from browser, but if this code is imported in wider context then 'e.Type.TypeA' is ambiguous and could be treated as 'ns.Type.TypeA' which results to exception.
Expected result
From my point of view the best result would be
to be
The text was updated successfully, but these errors were encountered: