Skip to content

Instantly share code, notes, and snippets.

@roytouw7
Created August 20, 2020 13:48
Show Gist options
  • Save roytouw7/ab8678e2bdfe3ee19a832ad8a8914a57 to your computer and use it in GitHub Desktop.
Save roytouw7/ab8678e2bdfe3ee19a832ad8a8914a57 to your computer and use it in GitHub Desktop.
// 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