Skip to content

DCE wrong removing var assignment inside for-loop #720

@garyyeap

Description

@garyyeap

This issue is related to es2015 scoping issue and have been fixed on #713.
Now just open for referring in the test case and it should be closed after the PR#713 has been merged.

Input Code

function test () {
  var arr = ['a', 'b', 'c'];
  var len = arr.length;
  var result = null;

  for (let i = 0; i < len; i++) {
      result = arr[i];
  }

  return result || {};
}

Actual Output

'use strict';function test(){for(var a=['a','b','c'],b=a.length,d=0,;d<b;d++)a[d];return c||{}}

Expected Output

'use strict';function test(){for(var a=['a','b','c'],b=a.length,d=0,c=0;d<b;d++)c=a[d];return c||{}}

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