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.

Same-name extern methods preventing code removal for provably side-effect-free code

See original GitHub issue

The compiler should be able to compile the following example to zero:

(function() {
  /** @final */
  class Foo {
    get() {}
    foo() {}
  }

  new Foo().get();
  new Foo().foo();
})();

Instead, it can remove the call to foo(), but it cannot remove the call to get(), presumably because of an extern that’s being conflated somewhere.

Debugger link

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shickscommented, Jun 8, 2017

I don’t see any class in the output:

(function() {
  /** @final @struct @constructor */ var Foo = function() {
  };
  Foo.prototype.foo = function() {
  };
  Foo.prototype.bar = function() {
  };
  (new Foo).foo();
  (new Foo).bar();
})();

In any case, it looks like I needed to turn on DisambiguateProperties. With that on, it does in fact behave as you say.

0reactions
ChadKillingsworthcommented, Jun 7, 2017

@shicks Something else going on with the debugger there. The code isn’t being transpiled (there’s a class in the output).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Releases · google/closure-compiler Wiki - GitHub
This fixes a dead code removal with TypeScript 4.4, which uses this pattern for functions imported from modules. When the special first parameter...
Read more >
SideEffectFree (checker-framework 3.27.0 API)
A method is called side-effect-free if it has no visible side-effects, such as setting a field of an object that existed before the...
Read more >
Bug patterns
Each bug pattern includes code examples of both positive and negative cases; these examples are used in our regression test suite.
Read more >
It's probably time to stop recommending Clean Code (2020)
The idea of code telling a story is that a unit of work should explain what it does through its use of well...
Read more >
API - esbuild
External paths are applied both before and after path resolution, which lets you match against both the import path in the source code...
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