JSTQL-JS-Transform/src/transform/transform.ts

51 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-12-11 18:38:30 +00:00
import * as babelparser from "@babel/parser";
import traverse from "@babel/traverse";
import * as t from "@babel/types";
import { parseApplicableTo } from "../parser/parse";
export interface TransformRecipe{
applicableTo: string,
identifiers: string[],
consumeBlock: boolean,
transformTo: string,
}
export function transform(recipe: TransformRecipe, code:string){
let {commands, applicableTo} = parseApplicableTo(recipe.applicableTo);
//console.log(applicableTo);
let applicableToAST = babelparser.parse(applicableTo, {allowAwaitOutsideFunction: true});
console.log(applicableToAST);
let codeAST = babelparser.parse(code, {allowAwaitOutsideFunction: true});
console.log(codeAST);
traverse(applicableToAST, {
enter(path:any) {
traverse(codeAST, {
enter(codePath:any){
if (codePath.node.type === "Program"){
return;
}
if (codePath.node.type === path.node.type){
console.log("We found a match with");
console.log(codePath.node);
2023-12-11 18:40:19 +00:00
2023-12-11 18:38:30 +00:00
}
}
})
}
})
}