[parser] Disallow static fields named constructor (#10461)
* Disallow static fields named `constructor` in a class
- Disallowed static fields named `constructor` in a class (previously only non-static were disallowed)
- Updated the text for the error for one consolidated warning, for both static and non-static fields
- Added a test
- Updated an existing test in the `flow` test suite of the parser to reflect the parse error.
Strangely, the test used to pass and started failing when inlining the `isNonstaticConstructor` method, without any changes.
In that test, `constructor` was a field, so in theory it should never have passed.
Would appreciate some feedback on this, as I'm not 100% sure if this is somehow related to Flow
* Update test262 whitelist
* Add comment and fix && operator
This commit is contained in:
committed by
Nicolò Ribaudo
parent
87dc201411
commit
9c1ad0a9f7
@@ -1498,13 +1498,18 @@ export default class StatementParser extends ExpressionParser {
|
||||
}
|
||||
|
||||
pushClassProperty(classBody: N.ClassBody, prop: N.ClassProperty) {
|
||||
// This only affects properties, not methods.
|
||||
if (this.isNonstaticConstructor(prop)) {
|
||||
if (
|
||||
!prop.computed &&
|
||||
(prop.key.name === "constructor" || prop.key.value === "constructor")
|
||||
) {
|
||||
// Non-computed field, which is either an identifier named "constructor"
|
||||
// or a string literal named "constructor"
|
||||
this.raise(
|
||||
prop.key.start,
|
||||
"Classes may not have a non-static field named 'constructor'",
|
||||
"Classes may not have a field named 'constructor'",
|
||||
);
|
||||
}
|
||||
|
||||
classBody.body.push(this.parseClassProperty(prop));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user