glayzzle/php-transpiler

No php code (other than the echo example) works!

projenix opened this issue · 1 comments

Hi there,

Nice initiative, but I don't seem to be able to run any sort of actual php code other than the echo example and a few close variations.

For example this code:
engine.parseCode('')

Returns the following errors:

/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser.js:189
throw err;
^

SyntaxError: Parse Error : syntax error, unexpected '"Hello ...' (T_CONSTANT_ENCAPSED_STRING), expecting ';' on line 1
at parser.raiseError (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser.js:183:15)
at parser.error (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser.js:223:15)
at parser.expectEndOfStatement (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser.js:252:10)
at parser.read_statement (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser/statement.js:344:14)
at parser.read_inner_statement (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser/statement.js:182:21)
at parser.read_inner_statements (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser/statement.js:86:28)
at parser.read_code_block (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser/statement.js:358:14)
at parser.read_statement (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser/statement.js:192:29)
at parser.read_for (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser/loops.js:95:19)
at parser.read_statement (/home/me/js-sandbox/php-transpile/node_modules/php-parser/src/parser/statement.js:198:47)

Am I missing something?

Thank you in advance,

I.A.

Hi @projenix,

The sample in the readme is outdated, I've just updated it. Try this instead :

// initialize the php parser factory class
var transpiler = require('php-transpiler');
var instance = new transpiler({
  browser: true // says if we generate code for browser or nodejs
});

var jsCode = instance.read('<?php $a = 1; echo $a + 2;');
console.log(jsCode);

Actually it handles syntax nodes like variables manipulation, functions, namespaces, for, if, includes, object instanciations ... but everything is not yet implemented (takes time) ....

But I think you are testing the bad library. This library is just generating JS strings, but you may use the runtime library or maybe the cli engine