calls to the querySelector method are cut off in case of ADVANCED_OPTIMIZATIONS and turned off checkTypes warnings
See original GitHub issueThe compilation of a file, which contains only one line:
document.querySelector(".test").some_prop = true;
leads to an empty output when using the compiler with these flags:
java -jar compiler.jar --compilation_level=ADVANCED_OPTIMIZATIONS --jscomp_off=checkTypes --js=in.js --js_output_file=out.js
However, enabling the checkTypes warnings (--jscomp_warning=checkTypes
) fixes it and the output is ok: document.querySelector(".test").a=!0;
It doesn’t matter if the altered property is a custom “some_prop” or a built-in one like the “className” or “id”. Also, the querySelectorAll method doesn’t have such an issue and the following code is compiled without problems:
document.querySelectorAll(".test")[0].some_prop = true;
It’s reproduced in GCC v20161201.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top GitHub Comments
@ChadKillingsworth thanks for that info. It’s a bit more than that, though.
Suppose we have code like this:
someExternFunction()
might return a value that is part of global state, so settingsomeProperty
on it affects global state and is unsafe to remove. We should assume that this is the case for extern functions unless type info tells us otherwise.PureFunctionIdentifier
is incorrectly assuming the opposite when it has no type information.I have a change to fix this in internal review.
@brad4d Yeah - that was just a reminder for external viewers.