google / google/closure-compiler

Unused instances of de-referenced classes are not dead code eliminated

Open
#3,947 1 comment 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

Input:

```
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @language_out ECMASCRIPT_2015
// ==/ClosureCompiler==

const A = class {
constructor(opts) {
}
};

new A(1);
```

Expected output:

```
'use strict';
```

Actual output:

```
'use strict';new class{constructor(){}}(1);
```

Works as expected with language_out `ECMASCRIPT5`,
but any language_out `ECMASCRIPT_2015` or above does not DCE the unused instance.

https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540language_out%2520ECMASCRIPT_2015%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250Aconst%2520A%2520%253D%2520class%2520%257B%250A%2520%2520constructor(opts)%2520%257B%250A%2520%2520%257D%250A%257D%253B%250A%250Anew%2520A(1)%253B%250A%250Aclass%2520B%2520%257B%250A%2520%2520constructor(opts)%2520%257B%250A%2520%2520%257D%250A%257D%250A%250Anew%2520B(2)%253B%250A%250Aconsole.log(1)%253B%250A

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.