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