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.

RemoveUnusedCode regression in v20180204

See original GitHub issue

There seems to be an issue with the v20180204 Closure Compiler release where some code seems to be altered that shouldn’t be. The previous v20180101 (and others) work without issue. The reported warnings seem to be identical and can be ignored.

This was reported by a shadow-cljs user but I managed to trace this down to the recent Closure release and reproduced it with just the distributed .jar files.

Originially this was discovered as part of a ClojureScript build which imported the quill npm package via react-quill, which stopped working when I released a new shadow-cljs version using v20180204.

Steps To Reproduce

Download necessary things

curl -O https://unpkg.com/quill@1.3.5/dist/quill.js
curl -O http://repo1.maven.org/maven2/com/google/javascript/closure-compiler/v20180204/closure-compiler-v20180204.jar
curl -O http://repo1.maven.org/maven2/com/google/javascript/closure-compiler/v20180101/closure-compiler-v20180101.jar

Compile with bad version

java -jar closure-compiler-v20180204.jar --js quill.js -O SIMPLE --js_output_file compiled.js

Open Browser

<div id="app"></div>
<script src="compiled.js"></script>
<script>
    new Quill("#app", {});
</script>
open index.html

Fails with Error (See Browser Console)

Uncaught TypeError: Cannot call a class as a function
    at e.a (compiled.js:102)
    at new e (compiled.js:229)
    at a.value (compiled.js:218)
    at new c (compiled.js:76)
    at index.html:4

Compile with good version

java -jar closure-compiler-v20180101.jar --js quill.js -O SIMPLE --js_output_file compiled.js

Reload browser and Error is gone.

Running git bisect traced down this issue to this commit:

6b807c063d42a463e3c32e5911c695a0976e2b67 is the first bad commit
commit 6b807c063d42a463e3c32e5911c695a0976e2b67
Author: bradfordcsmith <bradfordcsmith@google.com>
Date:   Wed Jan 17 14:24:56 2018 -0800

    RemoveUnusedCode: remove `x instanceof UnusedName`

    -------------
    Created by MOE: https://github.com/google/moe
    MOE_MIGRATED_REVID=182269894

:040000 040000 d44ac3cdd98601b33b21192fada4fc0957a18efc ac0a44df4d8bee7350d32e3bbe4933a15f9d5151 M      src
:040000 040000 a6510a4aa77bde61508ea6c33fbdf6601f8b61e0 feb62fb9bd9b4cd4cea6f3b32ee552b293971c70 M      test

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
concavelenzcommented, Feb 23, 2018

Ok, there is the “instanceof”. I think I can guess the chain of events: “Constructor” is not used for anything but the “instanceof” check. The logic added in the problematic change is trying to remove definitions only used for instanceof checks. It incorrectly replaces the “instanceof” expression with “false”. The function is that inlined, and the rest of the constructor body removed.

Thanks for the details, this should be easy enough to back off when the definition of the variable isn’t a known object.

0reactions
brad4dcommented, Feb 27, 2018

fix sent for internal review

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove unused code - web.dev
To fix this issue, analyze your bundle to detect unused code. Then remove unused and unnecessary libraries. Impact on Core Web Vitals #....
Read more >
How to remove unused code at compile time? - Stack Overflow
We've built a Go package that is used by many of us. It's imported using the standard import ("package-name") method. At compile time...
Read more >
Five reasons why removing unused code matters - LinkedIn
Removing unused code from your existing SAP systems is a prime example of this type of technical debt that often goes unaddressed.
Read more >
Detect and Remove Dead Code - NDepend
Detect dead code and unused code in your .net application with some smart rule that will avoid false positives.
Read more >
How to: Remove Unused Members from Code | CodeRush
This refactoring allows you to remove an unused member. For example, the a4 private variable is never used in the following code snippet:....
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