Repository navigation
[api] AST utility APIs - #65586
[api] AST utility APIs#65586
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved bugs affect keyword recognition, modifier handling, type narrowing, and JSDoc variadic detection, while flag lookup can throw on detached binding elements.
6 open issues
Recognize JSDoc type aliases as modifier-bearing declarations · New Include JS imports in the modifier type guard · New Return stored modifiers for recovery nodes · New Addimmediateto the shared keyword table · New Skip qualified-name tags when finding the last JSDoc parameter · New Handle detached binding elements in root declaration lookup · New
What changed in this PR
Expands the TypeScript JavaScript API with AST inspection utilities and access to native formatting defaults.
Changes:
- Adds modifier/decorator guards, ancestor and flag helpers, rest-parameter detection, keyword lookup, and
Node.getModifiers(). - Exposes default formatting settings through the native protocol and async/sync clients.
- Improves private-symbol display names and adds coverage for the new APIs.
| File | Description |
|---|---|
tsc/internal/ls/lsutil/formatcodeoptions.go |
Serializes formatting settings with string-valued indentation styles. |
tsc/internal/api/session.go |
Handles formatting-default requests and supplies symbol display names. |
tsc/internal/api/proto.go |
Adds the formatting method and symbol display-name field. |
tools/scripts/tsc/generate-ts-ast.ts |
Generates factory-node getModifiers() methods. |
tools/scripts/tsc/generate-encoder.ts |
Generates remote-node getModifiers() methods. |
tools/gen-proto/main.go |
Maps native formatting settings to the client type. |
tools/gen-proto/main_test.go |
Checks generated formatting-method declarations. |
packages/typescript/test/sync/ast.test.ts |
Covers the new AST utilities and node method. |
packages/typescript/test/sync/api.test.ts |
Tests formatting defaults and private-symbol names. |
packages/typescript/test/sync/api-generators.test.ts |
Checks formatting-method generator parity. |
packages/typescript/test/scanner.test.ts |
Tests identifier-to-keyword lookup. |
packages/typescript/test/async/api.test.ts |
Covers async formatting defaults and private-symbol names. |
packages/typescript/src/ast/utils.ts |
Adds rest-parameter and combined-node-flag helpers. |
packages/typescript/src/ast/scanner.ts |
Exports identifier-to-keyword lookup. |
packages/typescript/src/ast/modifiers.ts |
Adds shared modifier extraction without decorators. |
packages/typescript/src/ast/is.ts |
Adds declaration guards and exports ancestor traversal. |
packages/typescript/src/ast/factory.generated.ts |
Implements getModifiers() on factory nodes. |
packages/typescript/src/ast/ast.ts |
Declares modifier/decorator unions and the node method. |
packages/typescript/src/api/sync/api.ts |
Exposes formatting defaults and consumes symbol display names. |
packages/typescript/src/api/proto.generated.ts |
Updates generated protocol types and batch-method lists. |
packages/typescript/src/api/node/node.generated.ts |
Implements getModifiers() on remote nodes. |
packages/typescript/src/api/async/api.ts |
Adds async formatting defaults and symbol display-name handling. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
f8f788e to
b423761
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the API expansion.
No open issues 🎉
6 resolved since last review
Handle detached binding elements in root declaration lookup Skip qualified-name tags when finding the last JSDoc parameter Addimmediateto the shared keyword table Return stored modifiers for recovery nodes Include JS imports in the modifier type guard Recognize JSDoc type aliases as modifier-bearing declarations
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> # Conflicts: # packages/typescript/src/api/node/node.generated.ts # packages/typescript/src/ast/ast.ts
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> # Conflicts: # packages/typescript/src/api/async/api.ts # packages/typescript/src/api/sync/api.ts
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> # Conflicts: # packages/typescript/src/ast/ast.ts # packages/typescript/src/ast/is.ts # packages/typescript/src/ast/utils.ts
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> # Conflicts: # packages/typescript/src/api/async/api.ts # packages/typescript/src/api/sync/api.ts # packages/typescript/test/sync/api-generators.test.ts
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
| "x-go-underlying": "int", | ||
| "x-accept-number": true, |
There was a problem hiding this comment.
Do we have any more of these left? I assume the rest are justifiable?
|
|
||
| export * from "./is.generated.ts"; | ||
|
|
||
| export function canHaveDecorators(node: Node): node is CanHaveDecorators { |
There was a problem hiding this comment.
Given this isn't generated, I do wonder what our strategy is for keeping these up to date long-term
There was a problem hiding this comment.
I did think about this—I was thinking about moving all mirrored/ported functions into files with some particular suffix. (Thought about a JSDoc marker but it would appear in public .d.ts files.) Then humans/agents/reviewers would at least be aware when something that has a cross-language counterpart is being modified.


canHaveDecoratorscanHaveModifiersfindAncestorgetCombinedNodeFlagsAPI.getDefaultFormatCodeSettingsNode.getModifiershasRestParameteridentifierToKeywordKind