google / google/closure-compiler

NTI: error on any class with getter and CUSTOM env (requires window in externs?)

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

Description

For any class with a getter, e.g.
```js
// test-class.js
class Test {
get value() {
return 1;
}
}
```
compiling with `java -jar compiler.jar --new_type_inf --language_out=ECMASCRIPT5_STRICT --js test-class.js --env=CUSTOM` gives error
```
test-class.js:1: WARNING - Property Object never defined on any type in the program
class Test {
^^^^^^^^^^^^
```

With the default externs there was no error. I narrowed down what they were providing that made this error go away to just
```js
// externs.js
function Window() {}
/** @type {!Window} */
var window;
```

The compiled output with and without `Window` in externs was identical:

```js
'use strict';var $jscomp = $jscomp || {};
$jscomp.scope = {};
$jscomp.getGlobal = function(a) {
return "undefined" != typeof window && window === a ? a : "undefined" != typeof global && null != global ? global : a;
};
$jscomp.global = $jscomp.getGlobal(this);
var Test = function() {
};
$jscomp.global.Object.defineProperties(Test.prototype, {value:{configurable:!0, enumerable:!0, get:function() {
return 1;
}}});
```

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.