Support multiple static blocks (#12738)
This commit is contained in:
@@ -49,7 +49,6 @@ export const ErrorMessages = Object.freeze({
|
||||
"`%0` has already been exported. Exported identifiers must be unique.",
|
||||
DuplicateProto: "Redefinition of __proto__ property",
|
||||
DuplicateRegExpFlags: "Duplicate regular expression flag",
|
||||
DuplicateStaticBlock: "Duplicate static block in the same class",
|
||||
ElementAfterRest: "Rest element must be last element",
|
||||
EscapedCharNotAnIdentifier: "Invalid Unicode escape",
|
||||
ExportBindingIsString:
|
||||
|
||||
@@ -1204,7 +1204,6 @@ export default class StatementParser extends ExpressionParser {
|
||||
const state: N.ParseClassMemberState = {
|
||||
constructorAllowsSuper,
|
||||
hadConstructor: false,
|
||||
hadStaticBlock: false,
|
||||
};
|
||||
let decorators: N.Decorator[] = [];
|
||||
const classBody: N.ClassBody = this.startNode();
|
||||
@@ -1313,11 +1312,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
return;
|
||||
}
|
||||
if (this.eat(tt.braceL)) {
|
||||
this.parseClassStaticBlock(
|
||||
classBody,
|
||||
((member: any): N.StaticBlock),
|
||||
state,
|
||||
);
|
||||
this.parseClassStaticBlock(classBody, ((member: any): N.StaticBlock));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1521,7 +1516,6 @@ export default class StatementParser extends ExpressionParser {
|
||||
parseClassStaticBlock(
|
||||
classBody: N.ClassBody,
|
||||
member: N.StaticBlock & { decorators?: Array<N.Decorator> },
|
||||
state: N.ParseClassMemberState,
|
||||
) {
|
||||
this.expectPlugin("classStaticBlock", member.start);
|
||||
// Start a new lexical scope
|
||||
@@ -1538,13 +1532,9 @@ export default class StatementParser extends ExpressionParser {
|
||||
this.scope.exit();
|
||||
this.state.labels = oldLabels;
|
||||
classBody.body.push(this.finishNode<N.StaticBlock>(member, "StaticBlock"));
|
||||
if (state.hadStaticBlock) {
|
||||
this.raise(member.start, Errors.DuplicateStaticBlock);
|
||||
}
|
||||
if (member.decorators?.length) {
|
||||
this.raise(member.start, Errors.DecoratorStaticBlock);
|
||||
}
|
||||
state.hadStaticBlock = true;
|
||||
}
|
||||
|
||||
pushClassProperty(classBody: N.ClassBody, prop: N.ClassProperty) {
|
||||
|
||||
@@ -1528,6 +1528,5 @@ export type ParseSubscriptState = {
|
||||
|
||||
export type ParseClassMemberState = {|
|
||||
hadConstructor: boolean,
|
||||
hadStaticBlock: boolean,
|
||||
constructorAllowsSuper: boolean,
|
||||
|};
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
"errors": [
|
||||
"SyntaxError: Duplicate static block in the same class (4:2)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}},
|
||||
Reference in New Issue
Block a user