Skip to content

Fix getChildren() dropping opening '<' token when immediately followed by '<' (#64168) - #64214

Open
Vaibhav Srivastava (vaibhavsrv) wants to merge 1 commit into
microsoft:mainfrom
vaibhavsrv:fix/get-children-contiguous-less-than-token
Open

Fix getChildren() dropping opening '<' token when immediately followed by '<' (#64168)#64214
Vaibhav Srivastava (vaibhavsrv) wants to merge 1 commit into
microsoft:mainfrom
vaibhavsrv:fix/get-children-contiguous-less-than-token

Conversation

@vaibhavsrv

Copy link
Copy Markdown

Fixes #64168

Summary

  • What changed: In addSyntheticNodes (packages/typescript/src/ast/astnav.ts), when a scanned token exceeds the gap end (tokenEnd > end) and is a LessThanLessThanToken (<<), scanner.reScanLessThanToken() is invoked to split << into < (LessThanToken).
  • Why it changed: Previously, when getChildren() was called on type argument lists immediately following another < (such as ReturnType<<T>(x: T) => number>), addSyntheticNodes scanned << at pos = 21 yielding tokenEnd = 23. Because 23 <= 22 evaluated to false, the < token was silently dropped, creating a gap between AST children.

Tests

  • Executed:
    • ./bin/tsc -b packages/typescript
    • go test ./internal/parser ./internal/ls/...
    • AST invariant test corpus entry with type Bar = ReturnType<<T>(x: T) => number>;
  • Results: Build succeeded cleanly (exit code 0) and all tests passed (exit code 0).

Copilot AI balanced review requested due to automatic review settings September 9, 2026 16:34
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 9, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug labels Sep 9, 2026
…d by '<' (microsoft#64168)

In addSyntheticNodes (packages/typescript/src/ast/astnav.ts), re-scan LessThanLessThanToken when tokenEnd exceeds the gap end. This splits '<<' into '<' (LessThanToken) so getChildren() preserves opening angle brackets on type argument lists immediately following '<'.
@vaibhavsrv
Vaibhav Srivastava (vaibhavsrv) force-pushed the fix/get-children-contiguous-less-than-token branch from 8abb5b5 to 9acd475 Compare September 9, 2026 16:36

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.

🔵 Needs a closer look

The unrelated deferred-import feature and generated changes should be moved to a separate PR.

Pull request overview

Fixes missing < tokens from getChildren(), but also includes unrelated import.defer?.() compiler changes.

Changes:

  • Re-scans << when synthesizing a single <.
  • Adds AST invariant coverage.
  • Adds unrelated optional-chain diagnostics and tests.
File summaries
File Description
packages/typescript/src/ast/astnav.ts Splits an overrunning << token.
packages/typescript/test/sync/ast.test.ts Adds regression coverage.
tsc/internal/parser/parser.go Flags optional deferred imports.
tsc/internal/checker/grammarchecks.go Rejects optional import calls.
tsc/internal/diagnostics/extraDiagnosticMessages.json Defines the new diagnostic.
tsc/internal/diagnostics/diagnostics_generated.go Adds generated diagnostic data.
tsc/internal/diagnostics/loc_generated.go Contains incidental import churn.
tsc/testdata/tests/cases/conformance/importDefer/importDeferOptionalChain.ts Tests optional deferred imports.
tsc/testdata/baselines/reference/conformance/importDeferOptionalChain.errors.txt Captures expected diagnostics.
tsc/testdata/baselines/reference/conformance/importDeferOptionalChain.js Captures emitted JavaScript.
tsc/testdata/baselines/reference/conformance/importDeferOptionalChain.symbols Captures symbol output.
tsc/testdata/baselines/reference/conformance/importDeferOptionalChain.types Captures type output.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@vaibhavsrv

Copy link
Copy Markdown
Author

Updated! Rebased the branch onto clean upstream/main to remove the deferred import commits. This PR now strictly contains only the getChildren() fix for #64168 and its AST invariant regression test (2 changed files).

while (pos < end) {
const token = scanner.getToken();
const tokenEnd = scanner.getTokenEnd();
let token = scanner.getToken();

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.

there is already an existing PR opened with almost exactly the same fix: #64169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

getChildren() drops the < token of a type argument list when immediately followed by another <

3 participants