Skip to content

Commit

Permalink
Handle undefined and use same output format as EvalJavascript.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jtolj committed Mar 24, 2021
1 parent 75760ea commit 79d1a49
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Scripts/jsToPhp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@
**/

function main(state) {
const js = state.text.replace(/\n\n\/\/ Result:[\s\S]*$/, '');
let output = '';
try {
const result = new Function(`return ${state.text}`)();
state.text = convert(result) + ';';
const result = new Function(`return ${js}`)();
output = convert(result) + ';';
} catch (error) {
state.postError(error.message);
}
state.text = js + "\n\n// Result:\n\n" + output;
}

const toPHP = function (value, indentation) {
switch (typeof value) {
case 'undefined':
value = null;
break;
case 'object':
if(value !== null) {
value = convert(value, indentation + 1);
Expand Down

0 comments on commit 79d1a49

Please sign in to comment.