Fix compile errors in replacement code.

This commit is contained in:
Robin Heggelund Hansen 2021-07-14 12:02:39 +02:00
parent f3a03a651e
commit 266885899e
2 changed files with 3 additions and 3 deletions

View File

@ -15,7 +15,7 @@ export const replace = (
}
} else if (ts.isFunctionDeclaration(node)) {
const name = node.name;
if (isIdentifier(name) && name.text in replacements) {
if (name && isIdentifier(name) && name.text in replacements) {
const key = name.text as keyof typeof replacements;
return astNodes(replacements[key]);
}

View File

@ -6,9 +6,9 @@ export const ast = (sourceText: string): ts.Node => {
return source.statements[0];
};
export const astNodes = (sourceText: string): [ts.Node] => {
export const astNodes = (sourceText: string): ts.Node[] => {
const source = ts.createSourceFile('bla', sourceText, ts.ScriptTarget.ES2018);
return source.statements;
return Array.from(source.statements);
}
export function create(name: string, body: ts.Node): ts.Node {