codecombat / esper.js

A javascript self-interpreter with a focus on sandboxed execution and runtime introspection.
MIT License
98 stars 19 forks source link

Support ES6 block scoping #18

Open ngocdaothanh opened 6 years ago

ngocdaothanh commented 6 years ago

(Related to #15 and #16)

Is it easy to add support for ES6 block scoping for let and const?

It's somewhat meaningless (and even confusing) to have let and const but no block scoping for them, because it's the main difference between them and var.

basicer commented 6 years ago

It's not so hard.

You would need to expand the Scope class to track both the block scope, and the function scope. This gets a little tricky when things like declaring a let inside a for loop deceleration is considered.

It's on my TODO list for sure.

basicer commented 6 years ago

I added some support for this in 268909e704034d8f5ed95095a17c8b80689d18cb, but it needs some testing. Let me know what you think.

ngocdaothanh commented 6 years ago

Thanks for working on this feature!

I've tried the code at #16 again, but it still doesn't work as expected.

To make it work as expected, I still need to change this line:

const char = string[i]

to:

let char = string[i]
ngocdaothanh commented 5 years ago

Hi, is PR #20 "Closure fixes" for fixing this issue?

basicer commented 5 years ago

It improves the situation but does not fix it entirely.