-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
@pureOrBreakMyCode
can't handle when left-hand side is array pattern
#4178
Comments
@pureOrBreakMyCode
can't handle when left-hand side is already eliminated@pureOrBreakMyCode
can't handle destructuring assignment and left-hand side is eliminated
Hi @rishipal thanks for looking into this |
It would be nice to have RemoveUnusedCode recognize this annotation and remove the call. Perhaps the /** @pureOrBreakMyCode */ isn't getting attached correctly and needs parens? In any case, we must better document this annotation for ourselves. |
Thanks @rishipal and @rahul-kamat |
@pureOrBreakMyCode
can't handle destructuring assignment and left-hand side is eliminated@pureOrBreakMyCode
can't handle when left-hand side is array pattern
CLA signed |
This might be a problem with the compiler's RemoveUnusedCode pass If we can repro this with a unit test in RemoveUnusedCodeTest.java, we can confirm that |
@rahul-kamat this can be a potential unit test
in this example, only |
I've spent some time looking into this, your latest example shows I also added these 2 examples as unit tests for example1 shows code being removed, example2 does not. But in RemoveUnusedCode, the only thing removed from both examples is:
so these 2 examples have the exact same behavior in RemoveUnusedCode I'll need to spend more time figuring out what's going on |
Closure compiler looks for these based on the resolved name, which no longer works in es6 modules. So we inline what the compiler would do. - object.create -> object literal - object.createSet -> object literal with `true` values - reflect.objectProperty -> JSCompiler_renameProperty - reflect.object => multiple JSCompiler_renameProperty - add @pureOrBreakMyCode to reflect.cache calls There's no documentation for @pureOrBreakMyCode, but Steve Hicks from Google said that's the correct solution and this seems to be the syntax based on google/closure-compiler#4178 It seems like adding this to reflect.cache itself would work if the call is inlined. However I don't know if that always happens, so I also added it at the callsites.
command
java -jar closure-compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --formatting PRETTY_PRINT --js input.js --js_output_file compiled.js
the example code is trimmed from tc39 stage 3 decorator compiled by swc.
in the example,
@pureOrBreakMyCode
is added manually to({ e: [_init_p3] } = /** @pureOrBreakMyCode */_apply_decs_2203_r(...)
however, because left-hand side is destructuring assignment, so closure-compiler need to traverse the
lhs
andvalueNode
respectively, it can't eliminate the pure valueNode.reproducible code
The text was updated successfully, but these errors were encountered: