Skip to content

JS: TypeScript extractor cleanup - #22860

Merged
paldepind merged 10 commits into
mainfrom
js/typescript-cleanup
Oct 21, 2026
Merged

paldepind merged 10 commits into
mainfrom
js/typescript-cleanup

Conversation

@paldepind

Copy link
Copy Markdown
Contributor

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.

paldepind and others added 9 commits October 21, 2026 10:04
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
@github-actions github-actions Bot added the JS label Oct 21, 2026
@paldepind
paldepind marked this pull request as ready for review October 21, 2026 08:31
@paldepind
paldepind requested review from a team as code owners October 21, 2026 08:31
Copilot AI max review requested due to automatic review settings October 21, 2026 08:31
@paldepind paldepind changed the title JS: TypeScript cleanup JS: TypeScript extractor cleanup Oct 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 asgerf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is genuinely useful. Rather than removing it it would be better to insert a comment describing when to use it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, I wasn't sure about that one. I've reverted that commit so it's now re-instated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@paldepind
paldepind merged commit fb0ba8c into main Oct 21, 2026
17 checks passed
@paldepind
paldepind deleted the js/typescript-cleanup branch October 21, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants