also looking at this
perf(isolated): benchmark declaration generation paths
#3106
4 files
+215
-6
| @@ -723,6 +723,42 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme | ||
| 723 | 723 | pos = len |
| 724 | 724 | } |
| 725 | 725 | |
| 726 | /** | |
| 727 | * Skip an annotated variable initializer without capturing its text. | |
| 728 | * | |
| 729 | * Isolated declarations call it for every explicitly annotated value. Safe | |
| 730 | * single-line literals take the direct path; complex syntax falls back to | |
| 731 | * the general JSX-aware statement scanner. | |
| 732 | */ | |
| 733 | function skipAnnotatedVariableInitializer(): void { | |
| 734 | pos++ // skip = | |
| 735 | while (pos < len && (source.charCodeAt(pos) === CH_SPACE || source.charCodeAt(pos) === CH_TAB)) pos++ | |
| 736 | ||
| 737 | // Common isolated-declarations output is one explicitly annotated value | |
| 738 | // per line. A terminated single-line literal can jump directly to its | |
| 739 | // semicolon without inspecting the initializer's properties/elements. | |
| 740 | const lineEnd = source.indexOf('\n', pos) | |
| 741 | const physicalEnd = lineEnd === -1 ? len : lineEnd | |
| 742 | const terminator = source.indexOf(';', pos) | |
| 743 | if (terminator !== -1 && terminator < physicalEnd) { | |
| 744 | let valueEnd = terminator - 1 | |
| 745 | while (valueEnd >= pos && (source.charCodeAt(valueEnd) === CH_SPACE || source.charCodeAt(valueEnd) === CH_TAB)) valueEnd-- | |
| 746 | const first = source.charCodeAt(pos) | |
| 747 | const final = source.charCodeAt(valueEnd) | |
| 748 | const isClosedLiteral = (first === CH_LBRACE && final === CH_RBRACE) | |
| 749 | || (first === CH_LBRACKET && final === CH_RBRACKET) | |
| 750 | || (first === CH_SQUOTE && final === CH_SQUOTE) | |
| 751 | || (first === CH_DQUOTE && final === CH_DQUOTE) | |
| 752 | || (first === CH_BACKTICK && final === CH_BACKTICK) | |
| 753 | if (isClosedLiteral) { | |
| 754 | pos = terminator + 1 | |
| 755 | return | |
| 756 | } | |
| 757 | } | |
| 758 | ||
| 759 | skipToStatementEnd() | |
| 760 | } | |
| 761 | ||
| 726 | 762 | /** |
| 727 | 763 | * Skip an export re-export: { ... } [from '...'] [;] |
| 728 | 764 | * pos should be at the opening { |
| @@ -1983,7 +2019,7 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme | ||
| 1983 | 2019 | // Concrete annotations need no initializer work. Broad annotations retain |
| 1984 | 2020 | // the initializer only so the processor can emit useful @defaultValue docs. |
| 1985 | 2021 | if (isolatedDeclarations && typeAnnotation && (!keepComments || !isBroadAnnotation(typeAnnotation))) { |
| 1986 | skipToStatementEnd() | |
| 2022 | skipAnnotatedVariableInitializer() | |
| 1987 | 2023 | } |
| 1988 | 2024 | else { |
| 1989 | 2025 | pos++ // skip = |