question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

calls to the querySelector method are cut off in case of ADVANCED_OPTIMIZATIONS and turned off checkTypes warnings

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
brad4dcommented, Nov 29, 2017

@ChadKillingsworth thanks for that info. It’s a bit more than that, though.

Suppose we have code like this:

someExternFunction().someProperty = something;

someExternFunction() might return a value that is part of global state, so setting someProperty 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.

0reactions
ChadKillingsworthcommented, Nov 29, 2017

@brad4d Yeah - that was just a reminder for external viewers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document.querySelector() - Web APIs | MDN
The Document method querySelector() returns the first Element within the document that matches the specified selector, or group of selectors ...
Read more >
This is calling more than 1 function onclick in javascript, what ...
The query means search for a selector and in this case, a class with the name ourText. I think the div class name...
Read more >
Writing a safe querySelector: the one-way street from values to ...
The querySelector method lets you retrieve DOM elements from ... that the selector will match any element, in which case it returns null...
Read more >
Searching: getElement*, querySelector*
If an element has the id attribute, we can get the element using the method document.getElementById(id) , no matter where it is.
Read more >
HTML DOM querySelector() Method - W3Schools
For multiple selectors, separate each selector with a comma. The returned element depends on which element that is first found in the document...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found