mirror of
https://github.com/mdgriffith/elm-optimize-level-2.git
synced 2024-11-29 12:46:32 +03:00
Merge branch 'master' of https://github.com/mdgriffith/elm-optimize-level-2
This commit is contained in:
commit
2abb7d8781
@ -1,6 +1,6 @@
|
||||
|
||||
import ts, { isIdentifier } from 'typescript';
|
||||
import { ast } from './utils/create';
|
||||
import { ast, astNodes } from './utils/create';
|
||||
|
||||
export const replace = (
|
||||
replacements: { [name: string]: string }
|
||||
@ -13,6 +13,12 @@ export const replace = (
|
||||
const key = name.text as keyof typeof replacements;
|
||||
return ast(replacements[key]);
|
||||
}
|
||||
} else if (ts.isFunctionDeclaration(node)) {
|
||||
const name = node.name;
|
||||
if (isIdentifier(name) && name.text in replacements) {
|
||||
const key = name.text as keyof typeof replacements;
|
||||
return astNodes(replacements[key]);
|
||||
}
|
||||
}
|
||||
return ts.visitEachChild(node, visitor, context);
|
||||
};
|
||||
|
@ -6,6 +6,11 @@ export const ast = (sourceText: string): ts.Node => {
|
||||
return source.statements[0];
|
||||
};
|
||||
|
||||
export const astNodes = (sourceText: string): [ts.Node] => {
|
||||
const source = ts.createSourceFile('bla', sourceText, ts.ScriptTarget.ES2018);
|
||||
return source.statements;
|
||||
}
|
||||
|
||||
export function create(name: string, body: ts.Node): ts.Node {
|
||||
if (
|
||||
ts.isExpressionStatement(body) &&
|
||||
|
Loading…
Reference in New Issue
Block a user