Skip to content

Commit

Permalink
Improve parsing static blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Aug 18, 2021
1 parent 019561b commit f09c7f6
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions packages/babel-parser/src/plugins/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2379,36 +2379,37 @@ export default (superClass: Class<Parser>): Class<Parser> =>
member: any,
state: N.ParseClassMemberState,
): void {
const invalidModifersForStaticBlocks = [
"declare",
"private",
"public",
"protected",
"override",
"abstract",
"readonly",
];
this.tsParseModifiers(
member,
invalidModifersForStaticBlocks.concat(["static"]),
);

const callParseClassMemberWithIsStatic = () => {
const isStatic = !!member.static;
if (isStatic && this.eat(tt.braceL)) {
delete member.static;
if (this.tsHasSomeModifiers(member, invalidModifersForStaticBlocks)) {
this.raise(this.state.pos, TSErrors.StaticBlockCannotHaveModifier);
}
this.parseClassStaticBlock(classBody, ((member: any): N.StaticBlock));
if (
this.isContextual("static") &&
this.lookaheadCharCode() === charCodes.leftCurlyBrace
) {
this.next(); // eat "static"
this.next(); // eat "{"
this.parseClassStaticBlock(classBody, ((member: any): N.StaticBlock));
} else {
this.tsParseModifiers(member, [
"declare",
"private",
"public",
"protected",
"override",
"abstract",
"readonly",
"static",
]);
const callParseClassMemberWithIsStatic = () => {
this.parseClassMemberWithIsStatic(
classBody,
member,
state,
!!member.static,
);
};
if (member.declare) {
this.tsInAmbientContext(callParseClassMemberWithIsStatic);
} else {
this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
callParseClassMemberWithIsStatic();
}
};
if (member.declare) {
this.tsInAmbientContext(callParseClassMemberWithIsStatic);
} else {
callParseClassMemberWithIsStatic();
}
}

Expand Down

0 comments on commit f09c7f6

Please sign in to comment.