Skip to content

[duplicate] 'let' causing variables to disappear in for-loop #485

@michaelathatch

Description

@michaelathatch

This only occurs in conjunction with the es2015 plugin.
The following code

function getSum(data) {
  let total = 0;
  for (let i = 0; i < data.length; i++) {
    total += data[i];
  }
  return total;
}

gets transpiled to

"use strict";function getSum(a){for(var c=0;c<a.length;c++)a[c];return b}

which returns the undefined variable b. Seemingly total has been removed.

The same code using var i instead of let i produces the expected result

"use strict";function getSum(a){for(var c=0,b=0;b<a.length;b++)c+=a[b];return c}

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions