google / google/closure-compiler

Unused static method on class declared inside a function is not removed

Open
#2,806 0 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

[Input:](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%2540formatting%2520pretty_print%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F%252F%2520ADD%2520YOUR%2520CODE%2520HERE%250Afunction%2520zaa()%2520%257B%250A%2520%2520class%2520Foo%2520%257B%250A%2520%2520%2520%2520static%2520fee()%2520%257B%2520console.log('fee')%2520%257D%250A%2520%2520%2520%2520static%2520baa()%2520%257B%2520console.log('baa')%2520%257D%250A%2520%2520%257D%250A%2520%2520Foo.baa()%250A%257D%253B%250Azaa()%253B)

```
function zaa() {
class Foo {
static fee() { console.log('fee') }
static baa() { console.log('baa') }
}
Foo.baa()
};
zaa();
```

Output:
```
(function() {
function a() {
}
a.b = function() {
console.log("fee");
};
a.a = function() {
console.log("baa");
};
a.a();
})();
```

Expected the unused fee method to be removed.

Compare to global scope declaration, input:
```
class Foo {
static fee() { console.log('fee') }
static baa() { console.log('baa') }
}
Foo.baa();
```

output:
```
console.log("baa");
```

Object literal, input:
```
function zaa() {
const Foo = {
fee() { console.log('fee') },
baa() { console.log('baa') }
}
Foo.baa()

};
zaa();
```
output:
```
console.log("baa");
```

Prototype methods, input:
```
function zaa() {
class Foo {
fee() { console.log('fee') }
baa() { console.log('baa') }
}
new Foo().baa()

};
zaa();
```

output:
```
(function() {
function a() {
}
a.prototype.a = function() {
console.log("baa");
};
(new a).a();
})();
```

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.