parse/unparse php

node v10.24.1
version: 1.1.0
endpointsharetweet
const engine = require('php-parser'); const unparse = require('php-unparser'); const code = (` <?php require("./script.php")?> <html> <body> <h1>Body</h1> </body> </html> `); const scriptCode = `<? $name = "foo"; ?> `; var parser = new engine(); var codeAST = parser.parseCode(code); var scriptAST = parser.parseCode(scriptCode); var inlineIdx = codeAST.children.findIndex((e) => e.kind === 'include'); codeAST.children.splice(inlineIdx, 1, ...scriptAST.children); unparse(codeAST, {kind: 'program'});
Loading…

no comments

    sign in to comment