mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 20:25:48 -06:00
Store already known not parenthesized arrow expression positions for faster exit in case of deep parsing
Fixes #31987
This commit is contained in:
parent
dbe9e3d237
commit
1d18b4941e
@ -605,6 +605,8 @@ namespace ts {
|
||||
|
||||
let parsingContext: ParsingContext;
|
||||
|
||||
let notParenthesizedArrow: Map<true> | undefined;
|
||||
|
||||
// Flags that dictate what parsing context we're in. For example:
|
||||
// Whether or not we are in strict parsing mode. All that changes in strict parsing mode is
|
||||
// that some tokens that would be considered identifiers may be considered keywords.
|
||||
@ -826,6 +828,7 @@ namespace ts {
|
||||
identifiers = undefined!;
|
||||
syntaxCursor = undefined;
|
||||
sourceText = undefined!;
|
||||
notParenthesizedArrow = undefined!;
|
||||
}
|
||||
|
||||
function parseSourceFileWorker(fileName: string, languageVersion: ScriptTarget, setParentNodes: boolean, scriptKind: ScriptKind): SourceFile {
|
||||
@ -3676,7 +3679,17 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parsePossibleParenthesizedArrowFunctionExpressionHead(): ArrowFunction | undefined {
|
||||
return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false);
|
||||
const tokenPos = scanner.getTokenPos();
|
||||
if (notParenthesizedArrow && notParenthesizedArrow.has(tokenPos.toString())) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const result = parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false);
|
||||
if (!result) {
|
||||
(notParenthesizedArrow || (notParenthesizedArrow = createMap())).set(tokenPos.toString(), true);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction | undefined {
|
||||
|
||||
File diff suppressed because one or more lines are too long
3933
tests/baselines/reference/parsingDeepParenthensizedExpression.types
Normal file
3933
tests/baselines/reference/parsingDeepParenthensizedExpression.types
Normal file
File diff suppressed because one or more lines are too long
20
tests/cases/compiler/parsingDeepParenthensizedExpression.ts
Normal file
20
tests/cases/compiler/parsingDeepParenthensizedExpression.ts
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user