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

fix:added check for forXstatement pattern #11703

Merged
merged 6 commits into from Jun 12, 2020
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
Expand Up @@ -329,6 +329,8 @@ const handle = {
return;
}

// for (MEMBER of ARR)
// for (MEMBER in ARR)
// { KEY: MEMBER } = OBJ -> { KEY: _destructureSet(MEMBER) } = OBJ
// { KEY: MEMBER = _VALUE } = OBJ -> { KEY: _destructureSet(MEMBER) = _VALUE } = OBJ
// {...MEMBER} -> {..._destructureSet(MEMBER)}
Expand All @@ -337,6 +339,9 @@ const handle = {
// [MEMBER = _VALUE] = ARR -> [_destructureSet(MEMBER) = _VALUE] = ARR
// [...MEMBER] -> [..._destructureSet(MEMBER)]
if (
existentialism marked this conversation as resolved.
Show resolved Hide resolved
// for (MEMBER of ARR)
// for (MEMBER in ARR)
parentPath.isForXStatement({ left: node }) ||
// { KEY: MEMBER } = OBJ
(parentPath.isObjectProperty({ value: node }) &&
parentPath.parentPath.isObjectPattern()) ||
Expand Down
@@ -0,0 +1,27 @@
class D {
#arr;
f() {
for (const el of this.#arr);
Copy link
Member

Choose a reason for hiding this comment

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

These should be reversed.

Please also add a test for for-in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ooo, ok. So we need 2 new test cases (for-of and for-in) with it appearing in the left.

Copy link
Member

Choose a reason for hiding this comment

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

👍 can just do it in the next line, or leave a comment that it shouldn't be transformed

Copy link
Member

Choose a reason for hiding this comment

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

personally I think just doing them all in the same class is fine

for (const el of this.#arr);
for (this.#arr of [1, 2]);
for (this.#arr in [1,2,3]);

the empty arr seems to be the same case?

and I would rename 1-helpermemberexpressionfunction to something like for-of-member-expression or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for sure, will remember for next time!

}
}

class C {
#p;
m() {
for (this.#p of []);
}
}

class E {
#arr;
f() {
for (this.#arr of [1, 2]);
}
}

class F {
#ar;
g() {
for (this.#ar in [1,2,3]);
}
}
@@ -0,0 +1,99 @@
var _arr = new WeakMap();

var D = /*#__PURE__*/function () {
"use strict";

function D() {
babelHelpers.classCallCheck(this, D);

_arr.set(this, {
writable: true,
value: void 0
});
}

babelHelpers.createClass(D, [{
key: "f",
value: function f() {
for (var el of babelHelpers.classPrivateFieldGet(this, _arr)) {
;
}
}
}]);
return D;
}();

var _p = new WeakMap();

var C = /*#__PURE__*/function () {
"use strict";

function C() {
babelHelpers.classCallCheck(this, C);

_p.set(this, {
writable: true,
value: void 0
});
}

babelHelpers.createClass(C, [{
key: "m",
value: function m() {
for (babelHelpers.classPrivateFieldDestructureSet(this, _p).value of []) {
;
}
}
}]);
return C;
}();

var _arr2 = new WeakMap();

var E = /*#__PURE__*/function () {
"use strict";

function E() {
babelHelpers.classCallCheck(this, E);

_arr2.set(this, {
writable: true,
value: void 0
});
}

babelHelpers.createClass(E, [{
key: "f",
value: function f() {
for (babelHelpers.classPrivateFieldDestructureSet(this, _arr2).value of [1, 2]) {
;
}
}
}]);
return E;
}();

var _ar = new WeakMap();

var F = /*#__PURE__*/function () {
"use strict";

function F() {
babelHelpers.classCallCheck(this, F);

_ar.set(this, {
writable: true,
value: void 0
});
}

babelHelpers.createClass(F, [{
key: "g",
value: function g() {
for (babelHelpers.classPrivateFieldDestructureSet(this, _ar).value in [1, 2, 3]) {
;
}
}
}]);
return F;
}();