blade
This commit is contained in:
parent
de9567a36a
commit
79d1af0c5f
|
@ -30,13 +30,14 @@ File.prototype.isRequiredRebuild = function(content){
|
|||
};
|
||||
File.prototype.execute = function(memoriable){
|
||||
let output = [];
|
||||
let t = new vm.Script(this.parsedContent,{
|
||||
let t = new vm.Script(this.parsedContent.ast,{
|
||||
cachedData: this.cachedData,
|
||||
});
|
||||
let content = vm.createContext({
|
||||
...memoriable,
|
||||
output,
|
||||
echo:(...args) => output.push(...args)
|
||||
echo:(...args) => output.push(...args),
|
||||
_external: e => {}
|
||||
});
|
||||
t.runInContext(content);
|
||||
this.cachedData = t.createCachedData();
|
||||
|
|
|
@ -7,6 +7,7 @@ function ParseEngine(file)
|
|||
{
|
||||
let content = [];
|
||||
let buffer = [];
|
||||
let requiredImports = [];
|
||||
let hmx = new Hemex();
|
||||
hmx.setText(file.content);
|
||||
function flushBuffer()
|
||||
|
@ -319,7 +320,8 @@ function ParseEngine(file)
|
|||
break;
|
||||
}
|
||||
case "import":{
|
||||
jsContent.push(`output.push(${JSON.stringify(`<!-- imported ${value}--->`)});\n`);
|
||||
requiredImports.push(value);
|
||||
jsContent.push(`_external(${value});\n`);
|
||||
break;
|
||||
}
|
||||
case "js-if-block":{
|
||||
|
@ -341,7 +343,10 @@ function ParseEngine(file)
|
|||
}
|
||||
return jsContent.join('');
|
||||
}
|
||||
return useAST(content);
|
||||
return {
|
||||
ast:useAST(content),
|
||||
requiredImports
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = ParseEngine;
|
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
output.push("<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <title>\r\n ");
|
||||
output.push( "Merhaba" );
|
||||
output.push("\r\n </title>\r\n</head>\r\n<body>\r\n ");
|
||||
output.push("<!-- imported \"merhaba\"--->");
|
||||
_external("merhaba");
|
||||
output.push("\r\n</body>\r\n</html>");
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- imported "merhaba"--->
|
||||
<button></button>
|
||||
</body>
|
||||
</html>
|
2
test.js
2
test.js
|
@ -4,7 +4,7 @@ let {writeFile} = require("node:fs/promises");
|
|||
async function main()
|
||||
{
|
||||
let node = await parser.processFile("./source/abc.blade.php");
|
||||
await writeFile("./source/abc.blade.php.js", node.parsedContent, "utf8");
|
||||
await writeFile("./source/abc.blade.php.js", node.parsedContent.ast, "utf8");
|
||||
let result = node.execute({
|
||||
ebilet: 25
|
||||
});
|
||||
|
|
Reference in New Issue