Skip to content

Add AST helpers used by api-extractor - #64439

Merged
Andrew Branch (andrewbranch) merged 1 commit into
microsoft:mainfrom
andrewbranch:ast-helpers
Sep 25, 2026
Merged

Andrew Branch (andrewbranch) merged 1 commit into
microsoft:mainfrom
andrewbranch:ast-helpers

Conversation

@andrewbranch

Copy link
Copy Markdown
Member
  • isExternalModule(sourceFile)
  • getCombinedModifierFlags(declaration)
  • getNameOfDeclaration(declaration)

Copilot AI balanced review requested due to automatic review settings September 24, 2026 22:54
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 24, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 24, 2026
Comment on lines +115 to +116
export function isExternalModule(file: SourceFile): boolean {
return file.externalModuleIndicator !== undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're never going to be able to rid ourselves of that property are we

return flags;
}

function skipParentheses(node: Expression): Expression {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have instructions or any sort of way to remember / validate that we ported these right into the future?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you mean if we change the implementation in Go?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, right (I chose a random place to comment, sorry)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We should probably add something in the general Copilot instructions, honestly. That will probably help turn a lot of stuff up during automated reviews. The API is so broad that I don't know if there's a good way to get more specific.

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.

Copilot review overview

🟡 Changes recommended

getNameOfDeclaration incorrectly returns undefined for supported identifier and element-access expressions.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds AST compatibility helpers required by API Extractor.

Changes:

  • Adds module, modifier, and declaration-name helpers.
  • Exposes supporting AST types and generated enum data.
  • Adds synchronous API tests.
File Description
tsc/​internal/​ast/​ast_generated.go Extends declaration names.
tsc/​internal/​api/​enum_values_generated.go Exposes JS declaration enum values.
tools/​scripts/​tsc/​generate-enums.ts Supports custom enum filenames.
tools/​scripts/​tsc/​ast.json Updates the AST schema.
packages/​typescript/​test/​sync/​ast.test.ts Tests the new helpers.
packages/​typescript/​src/​enums/​jsDeclarationKind.ts Adds the runtime enum.
packages/​typescript/​src/​enums/​jsDeclarationKind.enum.ts Adds the enum type.
packages/​typescript/​src/​ast/​utils.ts Implements the AST helpers.
packages/​typescript/​src/​ast/​modifiers.ts Centralizes modifier conversion.
packages/​typescript/​src/​ast/​is.generated.ts Updates the declaration-name guard.
packages/​typescript/​src/​ast/​ast.generated.ts Updates the declaration-name union.
packages/​typescript/​src/​api/​node/​node.infrastructure.ts Reuses modifier conversion.
Files not reviewed (2)
  • tsc/internal/api/enum_values_generated.go: Generated file
  • tsc/internal/ast/ast_generated.go: Generated file

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

Comment on lines +293 to +297
if (declaration.kind === SyntaxKind.ExportAssignment) {
const expression = (declaration as ExportAssignment).expression;
return isIdentifier(expression) ? expression : undefined;
}
return getDeclaredName(declaration);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The new behavior is accurate to Go's ast.GetNameOfDeclaration.

@jakebailey Jake Bailey (jakebailey) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Anyway, I'll mark this LGTM if it works for you, and we can figure out parity later

@andrewbranch
Andrew Branch (andrewbranch) added this pull request to the merge queue Sep 25, 2026
Merged via the queue into microsoft:main with commit 87f2e8c Sep 25, 2026
29 checks passed
return flags;
}

export function getCombinedModifierFlags(node: Declaration): ModifierFlags {

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.

Was excited to use this, but it should be callable for ClassElements too. (From what I can tell all ClassElementBase are also Declaration but the two are not related.

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

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants