google / google/closure-compiler

Can not extend protected method from a class defined in a function

Open
#2,696 3 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

The following case causes a compiler error:
```js
// parent.js
goog.provide('Parent');
Parent = class {
/** @protected */
method() { }
};
```

```js
// wrapper.js
goog.provide('Wrapper');
goog.require('Parent');
/**
* @constructor
*/
Wrapper = function() {
var Child = class extends Parent {
/** @override */
method() {
super.method();
}
};
new Child();
};
new Wrapper();
```

```bash
# Compilation
java -jar compiler.jar --entry_point=Wrapper --js *.js --jscomp_error "*"
```

The issue only occurs when the Child class is defined inside the Wrapper constructor.
The build passes when moving the definition to the top level (and adding a goog.provide).

Tested with google-closure-compiler `20171023.0.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.