jow- / ucode

JavaScript-like language with optional templating
ISC License
87 stars 24 forks source link

compiler: close upvalues on loop control statements #187

Closed nbd168 closed 4 months ago

nbd168 commented 5 months ago

When removing locals from all scopes, upvalues need to be considered, like in uc_compiler_leave_scope. Otherwise, the following testcase returns the wrong value:

let dest;
for (let i in [ 1 ]) {
    let foo = i;
    dest = () => {
        warn(`value: ${foo}\n`);
    };
    continue;
}
dest();
// returns value: null instead of value: 1