-
Notifications
You must be signed in to change notification settings - Fork 12.8k
How to get sourceFile with parentNode set? #14808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Call |
@ajafff It worked! Wondering why the lack of parent property would cause property |
you could avoid that by passing the sourceFile to node.getText(sourceFile); // works even if parent is not set |
Oh I see -- but TypeChecker seems pretty useful too. |
TypeScript Version: 2.2.1
I'm looking at the Compiler API and trying to figure out a way to parse a object literal like so:
When I try to do it this way:
literal.getChildren()
orliteral.getText()
throws exception:However, if I'm creating the sourceFile this way:
The same code works fine.
However, with
setParentNodes
as false, it throws same exceptionCannot read property 'text'
.Full Code: https://github.com/octref/vueinfo/blob/master/index.ts#L13-L25
So my two questions are:
sourceFile
, and why am I gettingCannot read property 'text'
in one of them?program.getSourceFile
withsetParentNodes
, so I can access the AST behind it?The text was updated successfully, but these errors were encountered: