diff --git a/Processor/File.js b/Processor/File.js index 371c523..a27ac6f 100644 --- a/Processor/File.js +++ b/Processor/File.js @@ -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(); diff --git a/Processor/Parse.js b/Processor/Parse.js index dddf075..2bf3e68 100644 --- a/Processor/Parse.js +++ b/Processor/Parse.js @@ -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(``)});\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; \ No newline at end of file diff --git a/source/abc.blade.php.cache b/source/abc.blade.php.cache index d191d40..2b1b19f 100644 Binary files a/source/abc.blade.php.cache and b/source/abc.blade.php.cache differ diff --git a/source/abc.blade.php.js b/source/abc.blade.php.js index 2480b78..986a8b3 100644 --- a/source/abc.blade.php.js +++ b/source/abc.blade.php.js @@ -1,5 +1,5 @@ output.push("\r\n\r\n\r\n \r\n \r\n \r\n \r\n "); output.push( "Merhaba" ); output.push("\r\n \r\n\r\n\r\n "); -output.push(""); +_external("merhaba"); output.push("\r\n\r\n"); diff --git a/target/abc.html b/target/abc.html index 71d6fc6..1dbfd93 100644 --- a/target/abc.html +++ b/target/abc.html @@ -9,6 +9,6 @@ - + \ No newline at end of file diff --git a/test.js b/test.js index 695f5a3..51c2360 100644 --- a/test.js +++ b/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 });