Skip to content

Some for loops cause incorrect output #430

@cpetrov

Description

@cpetrov

Using let in the initialization part of the for loop used in the function foo() leads to incorrect output.

Input:

function foo() {
  let len = 0;
  for (let i = 0; i < 2; i++) {}
  return len;
}

Output:

"use strict";function foo(){for(var b=0;2>b;b++);return a}

The returned variable a is not defined. The function foo() must always return 0.

Demo: https://babeljs.io/repl/#?babili=true&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&browsers=&builtIns=false&code=function foo() { let len %3D 0%3B for (let i %3D 0%3B i < 2%3B i%2B%2B) {} return len%3B}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bugwith es2015The bug is caused when used with es2015-block-scoping plugin

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions