google / google/closure-compiler
Extending ES6 class with static method leads to undefined function call
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
## sample code
``` js
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @language ECMASCRIPT6_STRICT
// @language_out ES5_STRICT
// @formatting pretty_print
// ==/ClosureCompiler==
class BaseClass {
static run() {
console.log(this._isBaseClass() ? 'base class' : 'extended class');
}
static _isBaseClass() {
return true;
}
}
class ExtendedClass extends BaseClass {
static _isBaseClass() {
return false;
}
}
class ClassImpl extends ExtendedClass {
static doRun() {
this.run();
}
}
ClassImpl.doRun();
```
## compiled code
``` js
'use strict';(function() {
this.a();
})();
```
## demo link
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%2520ECMASCRIPT6_STRICT%250A%252F%252F%2520%2540language_out%2520ES5_STRICT%250A%252F%252F%2520%2540formatting%2520pretty_print%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250Aclass%2520BaseClass%2520%257B%250A%2520%2520static%2520run()%2520%257B%250A%2520%2520%2520%2520console.log(this._isBaseClass()%2520%253F%2520%27base%2520class%27%2520%253A%2520%27extended%2520class%27)%253B%250A%2520%2520%257D%250A%250A%2520%2520static%2520_isBaseClass()%2520%257B%250A%2520%2520%2520%2520return%2520true%253B%250A%2520%2520%257D%250A%257D%250A%250Aclass%2520ExtendedClass%2520extends%2520BaseClass%2520%257B%250A%2520%2520static%2520_isBaseClass()%2520%257B%250A%2520%2520%2520%2520return%2520false%253B%250A%2520%2520%257D%250A%257D%250A%250Aclass%2520ClassImpl%2520extends%2520ExtendedClass%2520%257B%250A%2520%2520static%2520doRun()%2520%257B%250A%2520%2520%2520%2520this.run()%253B%250A%2520%2520%257D%250A%257D%250A%250AClassImpl.doRun()%253B
## actual output
- `TypeError: this is undefined`
- `Uncaught (in promise) TypeError: this.a is not a function(…)`
## expected output
`"extended class"`
Contributor guide
Assessment
This issue has not been assessed yet.