Skip to content

Commit 1d18b49

Browse files
committed
Store already known not parenthesized arrow expression positions for faster exit in case of deep parsing
Fixes microsoft#31987
1 parent dbe9e3d commit 1d18b49

File tree

4 files changed

+4722
-1
lines changed

4 files changed

+4722
-1
lines changed

src/compiler/parser.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ namespace ts {
605605

606606
let parsingContext: ParsingContext;
607607

608+
let notParenthesizedArrow: Map<true> | undefined;
609+
608610
// Flags that dictate what parsing context we're in. For example:
609611
// Whether or not we are in strict parsing mode. All that changes in strict parsing mode is
610612
// that some tokens that would be considered identifiers may be considered keywords.
@@ -826,6 +828,7 @@ namespace ts {
826828
identifiers = undefined!;
827829
syntaxCursor = undefined;
828830
sourceText = undefined!;
831+
notParenthesizedArrow = undefined!;
829832
}
830833

831834
function parseSourceFileWorker(fileName: string, languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind): SourceFile {
@@ -3676,7 +3679,17 @@ namespace ts {
36763679
}
36773680

36783681
function parsePossibleParenthesizedArrowFunctionExpressionHead(): ArrowFunction | undefined {
3679-
return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false);
3682+
const tokenPos = scanner.getTokenPos();
3683+
if (notParenthesizedArrow && notParenthesizedArrow.has(tokenPos.toString())) {
3684+
return undefined;
3685+
}
3686+
3687+
const result = parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false);
3688+
if (!result) {
3689+
(notParenthesizedArrow || (notParenthesizedArrow = createMap())).set(tokenPos.toString(), true);
3690+
}
3691+
3692+
return result;
36803693
}
36813694

36823695
function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction | undefined {

0 commit comments

Comments
 (0)