Skip to content

Commit

Permalink
Avoid state cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
fedeci committed Feb 9, 2021
1 parent c5bcc1f commit 874e203
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/babel-parser/src/parser/util.js
Expand Up @@ -96,6 +96,12 @@ export default class UtilParser extends Tokenizer {
);
}

hasFollowingLineBreak(): boolean {
return lineBreak.test(
this.input.slice(this.state.end, this.nextTokenStart()),
);
}

// TODO

isLineTerminator(): boolean {
Expand Down
16 changes: 9 additions & 7 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -1530,9 +1530,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (value === "global") {
return this.tsParseAmbientExternalModuleDeclaration(nany);
} else {
return this.tsTryParse(() =>
this.tsParseDeclaration(nany, value, /* next */ true),
);
return this.tsParseDeclaration(nany, value, /* next */ true);
}
}
}
Expand Down Expand Up @@ -1619,8 +1617,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
break;

case "module":
if (next) this.next();
if (!this.isLineTerminator()) {
if (!this.hasFollowingLineBreak() && !this.isLineTerminator()) {
if (next) this.next();
if (this.match(tt.string)) {
return this.tsParseAmbientExternalModuleDeclaration(node);
} else if (this.match(tt.name)) {
Expand All @@ -1630,8 +1628,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
break;

case "namespace":
if (next) this.next();
if (!this.isLineTerminator() && this.match(tt.name)) {
if (
!this.hasFollowingLineBreak() &&
!this.isLineTerminator() &&
this.match(tt.name)
) {
if (next) this.next();
return this.tsParseModuleOrNamespaceDeclaration(node);
}
break;
Expand Down

0 comments on commit 874e203

Please sign in to comment.