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.

Better dead code elimination

See original GitHub issue

no-unreachable fails to detect some of the cases of unreachable code. For example,

(function() {
  var foo = null;
  if (!foo) {
    return;
  } 
  (function dead(){})();
})();

should warn about dead function (since it’s statically determinable).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
ilyavolodincommented, May 27, 2016

If we were to add something like this to ESLint, I would seriously consider adding it to Escope instead. Escope already checked all of the declarations in the AST, so enhancing it to track type inference would be simpler then adding something like that to ESLint core itself.

1reaction
sebmckcommented, May 27, 2016

We’re working on some Babel tooling that uses it’s APIs. Babel scope tracking tracks constant values and knows that foo will always be null. Then some of our evaluation helpers determine that if (!foo) will always be true. There’s no Flow type information required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dead-code elimination - Wikipedia
In compiler theory, dead-code elimination is a compiler optimization to remove code which does not affect the program results. Removing such code has ......
Read more >
Dead Code Elimination
Removing such code has several benefits: it shrinks program size and it allows the running program to avoid executing irrelevant operations, which reduces...
Read more >
How to Find and Remove Dead Code - LinearB
This optimization technique is called dead code elimination. Since the mid-2010s, similar technology has been used in IDEs to highlight lines ...
Read more >
Better dead code elimination for swc minify. #3629 - GitHub
It's problem of top-level . swc emits identical output if you set toplevel: true. All reactions.
Read more >
Chapter 4. Improve Code by Removing It - O'Reilly
There is no harm in removing dead code. Amputate it. It's not like you're throwing it away. Whenever you realise that you need...
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