Created
August 20, 2020 13:48
-
-
Save roytouw7/ab8678e2bdfe3ee19a832ad8a8914a57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fetch identifier for given node in AST if existing. | |
export const fetchIdentifier = (node: ts.Node): string | null => { | |
if (!ts.isPropertyDeclaration(node) && !ts.isVariableDeclaration(node) && !ts.isExpressionStatement(node)) { | |
return fetchIdentifier(node.parent); | |
} else if (ts.isPropertyDeclaration(node) || ts.isVariableDeclaration(node)) { | |
return node.name.getText(); | |
} else { | |
return null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment