Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function js(code: string): t.File {
return stripExtras(parse(code));
}
export function program(
template: string
): (replacements?: R) => t.File {
const ast = parse(template);
return (replacements = {} as R) => {
const unusedReplacements = new Set(Object.keys(replacements));
traverse(ast, {
Placeholder(path: NodePath): void {
const name = path.node.name.name;
const replacement = replacements[name];
if (!replacement) {
throw new Error(
`no replacement found for placeholder with name: ${name}`
);
}
if (Array.isArray(replacement)) {
static run(content: string): StageResult {
const log = logger(this.name);
log(content);
const editor = new MagicString(content);
const ast = parse(content, {
tokens: true
});
const { insertions, removals } = asi(content, ast);
insertions.forEach(({ index, content }) => editor.appendLeft(index, content));
removals.forEach(({ start, end }) => editor.remove(start, end));
return {
code: editor.toString(),
suggestions: []
};
}
}