google / google/closure-compiler

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

Open
#2,132 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

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

```js
(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](https://closure-compiler-debugger.appspot.com/#input0%3D%2528function%2528%2529%2520%257B%250A%2520%2520%252F**%2520%2540final%2520*%252F%250A%2520%2520class%2520Foo%2520%257B%250A%2520%2520%2520%2520get%2528%2529%2520%257B%257D%250A%2520%2520%2520%2520foo%2528%2529%2520%257B%257D%250A%2520%2520%257D%250A%250A%2520%2520new%2520Foo%2528%2529.get%2528%2529%253B%250A%2520%2520new%2520Foo%2528%2529.foo%2528%2529%253B%250A%257D%2529%2528%2529%253B%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26CLOSURE_PASS%3D1%26COMPUTE_FUNCTION_SIDE_EFFECTS%3D1%26INLINE_FUNCTIONS%3D1%26MISSING_PROPERTIES%3D1%26PRESERVE_TYPE_ANNOTATIONS%3D1%26PRETTY_PRINT%3D1%26REMOVE_DEAD_CODE%3D1%26REMOVE_UNUSED_CLASS_PROPERTIES%3D1%26REMOVE_UNUSED_PROTOTYPE_PROPERTIES%3D1%26REMOVE_UNUSED_VARIABLES%3D1%26TRANSPILE%3D1)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.