Microsoft/TypeScript

Compiler API: Expose More from typescript.d.ts

Open

#23,719 opened on 2018年4月26日

GitHub で見る
 (7 comments) (3 reactions) (0 assignees)TypeScript (48,455 stars) (6,726 forks)batch import
Domain: APIHelp WantedSuggestion

説明

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 for Node#locals & Symbol#parent
  • For Symbol#parent, the goal is: given the symbol for a method (e.g., methodSymbol for Number#toString) find where that method is defined (e.g., Number)... maybe program.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 of SignatureDeclaration | undefined instead of SignatureDeclaration

Related Issues: #15841

コントリビューターガイド

Compiler API: Expose More from typescript.d.ts · Microsoft/TypeScript#23719 | Good First Issue