Repository navigation
JS: TypeScript extractor cleanup - #22860
Conversation
The package typings and enclosing-package helpers have no callers. Remove these helpers, their package.json reader, and the associated State caches. Single-file parsing does not use this package-resolution machinery, so this does not change which files are parsed or how imports are handled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
`LoadCommand` is not part of the command union or command dispatch, and `loadTsConfig` has no callers. Remove the unreachable tsconfig loader, including its node_modules redirection and virtual-source-root mapping. `VirtualSourceRoot` is only used by that loader, so remove the helper too. The active parser continues to parse each requested file independently. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
`checkMemoryUsage` can only reclaim compiler state by calling `state.project.reload()`, but `state.project` is initialized to `null` and is never assigned. The reload branch therefore cannot run, even when the configured memory threshold is exceeded. Remove the check, its threshold bookkeeping, and the now-unused environment reader. This removes no effective memory protection from single-file parsing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
No code constructs a `Project` or assigns `State.project`. With the ineffective memory reload checks removed, the remaining project state has no readers. Delete the unused `Project` class and its state field. The AST augmenter also never uses its `Project` argument, and its caller always passes `null`. Remove that argument and update the parsing comment to describe the single-file path that is actually used. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
`checkCycle` is a debugging helper with no callers, explicitly excluded from production use and suppressed as an unused variable. Remove it and its lint suppression. The AST property whitelist and JSON serialization path are unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
The AST augmenter builds a filtered numeric-to-name `SyntaxKind` lookup at module initialization, but never reads it. Remove the lookup construction and the `hasOwnProperty` helper that is only used there. Node and token kinds still use `ts.SyntaxKind` directly, and the metadata response continues to expose that enum unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
`tryGetTypeOfNode` has no callers. The AST augmenter does not query the type checker, so its exception recovery and warning cannot run. Remove the helper without changing the syntactic AST augmentation path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
The TypeScript 5.9.2 dependency does not use `experimentalAsyncFunctions`. Async functions are parsed without this option, so passing it to `createProgram` has no effect. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
The TypeScript 5.9 parser already marks declaration lists with `NodeFlags.Let` and `NodeFlags.Const`, which the existing fallback checks use. The optional `isLet`/`isConst` probes are therefore unnecessary compatibility code for older compiler APIs. Use the flags directly and remove the untyped API alias. The emitted $declarationKind values remain var, let, or const as before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20e67a1f-bf8e-4e8f-947a-37804de79e08
There was a problem hiding this comment.
🟢 Approval recommended
No blocking issues remain; the cleanup preserves the active parsing path.
No open issues 🎉
What changed in this PR
Simplifies the JavaScript extractor’s TypeScript parser by removing obsolete type-extraction infrastructure.
Changes:
- Removes unused project, configuration, virtual-root, and memory-reload code.
- Prunes unused AST helpers and simplifies declaration-kind checks.
| File | Description |
|---|---|
| javascript/extractor/lib/typescript/src/virtual_source_root.ts | Deletes unused virtual-root mapping. |
| javascript/extractor/lib/typescript/src/main.ts | Removes obsolete state and helpers; updates parsing documentation. |
| javascript/extractor/lib/typescript/src/common.ts | Deletes the unused project wrapper. |
| javascript/extractor/lib/typescript/src/ast_extractor.ts | Removes unused helpers and simplifies AST augmentation. |
Review effort: Max
asgerf
left a comment
There was a problem hiding this comment.
Thanks for cleaning this up. The checkCycle function ought to be kept until the migration though, as it has historically saved a lot of time when debugging issues with cycles in the AST.
| * If cycles are found, the whitelist in `astProperties` is too permissive. | ||
| */ | ||
| // tslint:disable-next-line:no-unused-variable | ||
| function checkCycle(root: any) { |
There was a problem hiding this comment.
This one is genuinely useful. Rather than removing it it would be better to insert a comment describing when to use it.
There was a problem hiding this comment.
Good to know, I wasn't sure about that one. I've reverted that commit so it's now re-instated.
There was a problem hiding this comment.
Let's ignore it for now, but I think it would be useful to have a // ... checkCycle(..) somewhere such that one can see one is supposed to make use of it.
This reverts commit 17c8e4a. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e1081f1d-de10-4a26-b042-0f6692b3b558
When updating the TypeScript part of the JavaScript extractor to 7.1, Copilot picked up on a bunch of unused or otherwise unneeded code. I think this mostly leftover stuff from when we removed extraction of types. Those changes are independent of the 7.1 update, so I've moved them out into a separate PR.
Each change has its own commit with an explanation. This should make reviewing easier.