Open
Description
TypeScript Version: 2.9.0-dev.20180426
While Traversing the TypeScript AST of a source file, there have been a number of helpful things I've found by extending ts.*
from typescript.d.ts
and I would like it if these could be exposed (or not marked /* @internal */
).
Search Terms:
typescript.d.ts
Node.locals
Symbol.parent
getContainingFunction
isAssignmentTarget
Code
declare namespace ts {
interface Node {
/* @internal */ readonly locals?: SymbolTable; // Locals associated with node (initialized by binding)
}
interface Symbol {
/* @internal */ readonly parent?: Symbol; // Parent symbol
}
function getContainingFunction(node: Node): SignatureDeclaration | undefined;
function isAssignmentTarget(node: Node): boolean;
}
Note:
- Added
readonly
forNode#locals
&Symbol#parent
- For
Symbol#parent
, the goal is: given the symbol for a method (e.g.,methodSymbol
forNumber#toString
) find where that method is defined (e.g.,Number
)... maybeprogram.getTypeChecker().getSymbolAtLocation(methodSymbol.valueDeclaration.parent)
is what is "supposed" to be used instead? - For
ts.getContainingFunction()
it seems more appropriate to have a return type ofSignatureDeclaration | undefined
instead ofSignatureDeclaration
Related Issues:
#15841
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ajafff commentedon Apr 26, 2018
There's a package that provides declarations even for the internal stuff: https://www.npmjs.com/package/byots
Regarding
isAssignmentTarget
: you might want to useisReassignmentTarget
of my librarytsutils
.mhegazy commentedon Apr 26, 2018
I do not think we want to expose
symbol.parent
, norlocals
. these are internal implementation details that we can change with no prior notice.getContainingFunction
andisAssignmentTarget
are fine though. we would take a PR to expose them.SlurpTheo commentedon Apr 27, 2018
@mhegazy So instead of
symbol.parent
is my second note along the right plan of action (get symbol's valueDeclaration, get its parent, get its symbol)?I'll have to dig more into why I needed
node.locals
sometime soon.mhegazy commentedon Apr 27, 2018
correct.
granmoe commentedon Mar 6, 2019
Is there any reliable way to find all symbols available in module scope without using
node.locals
? This is what I desperately wish to do.jirutka commentedon Oct 11, 2019
@granmoe, take a look at
TypeChecker#getSymbolsInScope
(you can get its instance from theprogram
).Zemnmez commentedon Feb 8, 2020
I second
symbol.parent
! It's very hard to operate on symbol trees without it.