Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for fixed block scoping issue #13304

Merged
merged 1 commit into from May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,15 @@
"use strict";

const results = [0, 1, 2];
const fns = [];

for (let result of results) {
result = result * 2;
fns.push(() => {
return result;
});
}

expect(fns[0]()).toBe(0);
expect(fns[1]()).toBe(2);
expect(fns[2]()).toBe(4);
@@ -0,0 +1,6 @@
for (let result of results) {
result = otherValue;
fn(() => {
result;
});
}
@@ -0,0 +1,6 @@
{
"plugins": [
["transform-block-scoping", { "loose": true }],
"transform-for-of"
]
}
@@ -0,0 +1,22 @@
var _loop = function (_result) {
_result = otherValue;
fn(() => {
_result;
});
result = _result;
};

var _iterator = babelHelpers.createForOfIteratorHelper(results),
_step;

try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var result = _step.value;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugin ordering changed the output, but that's unavoidable since both apply different transformations to the same thing.


_loop(result);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
@@ -0,0 +1,15 @@
"use strict";

const results = [0, 1, 2];
const fns = [];

for (let result of results) {
result = result * 2;
fns.push(() => {
return result;
});
}

expect(fns[0]()).toBe(0);
expect(fns[1]()).toBe(2);
expect(fns[2]()).toBe(4);
@@ -0,0 +1,6 @@
for (let result of results) {
result = otherValue;
fn(() => {
result;
});
}
@@ -0,0 +1,6 @@
{
"plugins": [
"transform-for-of",
["transform-block-scoping", { "loose": true }]
]
}
@@ -0,0 +1,20 @@
var _iterator = babelHelpers.createForOfIteratorHelper(results),
_step;

try {
var _loop = function () {
var result = _step.value;
result = otherValue;
fn(() => {
result;
});
};

for (_iterator.s(); !(_step = _iterator.n()).done;) {
_loop();
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
@@ -0,0 +1,15 @@
"use strict";

const results = [0, 1, 2];
const fns = [];

for (let result of results) {
result = result * 2;
fns.push(() => {
return result;
});
}

expect(fns[0]()).toBe(0);
expect(fns[1]()).toBe(2);
expect(fns[2]()).toBe(4);
@@ -0,0 +1,6 @@
for (let result of results) {
result = otherValue;
fn(() => {
result;
});
}
@@ -0,0 +1,6 @@
{
"plugins": [
["transform-block-scoping", { "loose": true }],
["transform-for-of", { "loose": true }]
]
}
@@ -0,0 +1,13 @@
var _loop = function (_result) {
_result = otherValue;
fn(() => {
_result;
});
result = _result;
};

for (var _iterator = babelHelpers.createForOfIteratorHelperLoose(results), _step; !(_step = _iterator()).done;) {
var result = _step.value;

_loop(result);
}
@@ -0,0 +1,15 @@
"use strict";

const results = [0, 1, 2];
const fns = [];

for (let result of results) {
result = result * 2;
fns.push(() => {
return result;
});
}

expect(fns[0]()).toBe(0);
expect(fns[1]()).toBe(2);
expect(fns[2]()).toBe(4);
@@ -0,0 +1,6 @@
for (let result of results) {
result = otherValue;
fn(() => {
result;
});
}
@@ -0,0 +1,6 @@
{
"plugins": [
["transform-for-of", { "loose": true }],
["transform-block-scoping", { "loose": true }]
]
}
@@ -0,0 +1,11 @@
var _loop = function () {
var result = _step.value;
result = otherValue;
fn(() => {
result;
});
};

for (var _iterator = babelHelpers.createForOfIteratorHelperLoose(results), _step; !(_step = _iterator()).done;) {
_loop();
}