Skip to content

Incorrect behaviour when it encounters a bodyless loop #8

Description

@BalintCsala

When I pass the while(1) console.log(Date.now()) loop, the output is

while(1) {
    if (window.CP.shouldStopExecution(1)) {
        break;
    }
    console.log(Date.now());
    window.CP.exitedLoop(1);
}

Which isn't correct, since window.CP.exitedLoop(1); should come after the closing bracket. If I however pass it the same function but with a body (aka. while(1) { console.log(Date.now()); }) I get

while(1) { 
    if (window.CP.shouldStopExecution(1)) { 
        break;
    } 
    console.log(Date.now()); 
}
window.CP.exitedLoop(1);

Possible solution

I'll get this out of the way first: I have absolutely no idea why this works, I stumbled upon it by accident.

Switching the last two lines in

patches.push({ pos: start, str: prolog });
patches.push({ pos: end, str: epilog });
patches.push({ pos: node.range[1], str: LOOP_EXIT.replace('%d', loopId) });

To get

patches.push({ pos: start, str: prolog });
patches.push({ pos: node.range[1], str: LOOP_EXIT.replace('%d', loopId) });
patches.push({ pos: end, str: epilog });

Solves this problem for me.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions