Siubaak / sval

A javascript interpreter written in javascript
https://jsbin.com/kehahiqono/edit?js,console
MIT License
379 stars 50 forks source link

Can't access variable inside function #63

Closed gda-gp closed 4 years ago

gda-gp commented 4 years ago

Demo:

console.log('Sval Version: ' + Sval.version)

const interpreter = new Sval()

interpreter.run(`
const tryValue = (x) => {
console.log(\`value of ${x}\`);
}
tryValue('xxxx');
`)

console.log('End: ' + interpreter.exports.end)

x has no value inside function

ngocdaothanh commented 4 years ago

The code runs as expected if we change the code to:

interpreter.run(`
const tryValue = (x) => {
console.log('value of ' + x);
}
tryValue('xxxx');`)

So, the bug is at the string interpolation:

`value of ${x}`
Siubaak commented 4 years ago

You should escape character $, like value of \${x}