ReviewOS

also looking at this

stacks/dtsx

perf(isolated): benchmark declaration generation paths

#3106
Merged chris wants to merge codex/isolated-mode-benchmarks into main
4 files +215 -6
packages/dtsx/src/extractor/scanner.tsmodified+37-1
Changes to packages/dtsx/src/extractor/scanner.ts
@@ -723,6 +723,42 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme
723723 pos = len
724724 }
725725
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
726762 /**
727763 * Skip an export re-export: { ... } [from '...'] [;]
728764 * pos should be at the opening {
@@ -1983,7 +2019,7 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme
19832019 // Concrete annotations need no initializer work. Broad annotations retain
19842020 // the initializer only so the processor can emit useful @defaultValue docs.
19852021 if (isolatedDeclarations && typeAnnotation && (!keepComments || !isBroadAnnotation(typeAnnotation))) {
1986 skipToStatementEnd()
2022 skipAnnotatedVariableInitializer()
19872023 }
19882024 else {
19892025 pos++ // skip =