Skip to content

Commit ee543e0

Browse files
Export getNodeForTarget in ast exports (#8652)
1 parent 48e5c6c commit ee543e0

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: feature
4+
packages:
5+
- "@typespec/compiler"
6+
---
7+
8+
[API] Export `getNodeForTarget` in `@typespec/compiler/ast` exports

packages/compiler/src/ast/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
export { NodeFlags, SyntaxKind } from "../core/types.js";
1313

14+
export { getNodeForTarget } from "../core/diagnostics.js";
1415
export { printTypeSpecNode } from "../core/formatter.js";
1516
export {
1617
exprIsBareIdentifier,

packages/compiler/src/core/diagnostics.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,18 @@ export function getRelatedLocations(diagnostic: Diagnostic): RelatedSourceLocati
4444
}
4545

4646
/**
47-
* Find the syntax node for a typespec diagnostic target.
48-
* Returns undefined if target is a type or symbol without a node.
47+
* Find the syntax node for a TypeSpec diagnostic target.
48+
*
49+
* This function extracts the AST node from various types of diagnostic targets:
50+
* - For template instance targets: returns the node of the template declaration
51+
* - For symbols: returns the first declaration node (or symbol source for using symbols)
52+
* - For AST nodes: returns the node itself
53+
* - For types: returns the node associated with the type
54+
*
55+
* @param target The diagnostic target to extract a node from. Can be a template instance,
56+
* symbol, AST node, or type.
57+
* @returns The AST node associated with the target, or undefined if the target is a type
58+
* or symbol that doesn't have an associated node.
4959
*/
5060
export function getNodeForTarget(target: TypeSpecDiagnosticTarget): Node | undefined {
5161
if (!("kind" in target) && !("entityKind" in target)) {

0 commit comments

Comments
 (0)