google / google/closure-compiler
Invalid ES6->ES5 lowering of static name & length methods
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Function.[length](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Function/length) and Function.[name](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Function/name) are not writable, which means the following valid ES6 code is not lowered properly:
``` javascript
class Foo {
static name() {}
static length() {}
}
console.log(typeof Foo.name); // function
console.log(typeof Foo.length); // function
```
Is [currently lowered to](http://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520SIMPLE_OPTIMIZATIONS%250A%252F%252F%2520%2540language_in%2520ES6%250A%252F%252F%2520%2540language_out%2520ES5%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250Aclass%2520Foo%2520%257B%250A%2520%2520static%2520name%28%29%2520%257B%257D%250A%2520%2520static%2520length%28%29%2520%257B%257D%250A%257D%250Aconsole.log%28typeof%2520Foo.name%29%253B%250Aconsole.log%28typeof%2520Foo.length%29%253B):
``` javascript
var Foo=function(){};
Foo.name=function(){};
Foo.length=function(){};
console.log(typeof Foo.name); // string
console.log(typeof Foo.length); // number
```
And should be lowered to something like:
``` javascript
var Foo=function(){};
Object.defineProperty(Foo, 'name', {value: function(){}});
Object.defineProperty(Foo, 'length', {value: function(){}});
console.log(typeof Foo.name); // function
console.log(typeof Foo.length); // function
```
(this bug came up in some [DDC](https://github.com/dart-lang/dev_compiler)-compiled Dart code)
Contributor guide
Assessment
This issue has not been assessed yet.