-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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: Computed properties should keep original definition order #15232
Changes from 3 commits
4061dae
ed1f8c3
86acf87
16758f3
1fd56a3
c735135
71a045c
b8acd2e
8a6ccb4
666e7de
dac736c
b16daaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* @minVersion 7.20.6 */ | ||
|
||
export default function _defineAccessor(obj, key, type, fn) { | ||
var desc = { configurable: true, enumerable: true }; | ||
// type should be "get" or "set" | ||
desc[type] = fn; | ||
return Object.defineProperty(obj, key, desc); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
var _foobar, _foobar2, _test, _test2, _obj, _mutatorMap; | ||
var obj = (_obj = {}, _foobar = foobar, _mutatorMap = {}, _mutatorMap[_foobar] = _mutatorMap[_foobar] || {}, _mutatorMap[_foobar].get = function () { | ||
var _obj; | ||
var obj = (_obj = {}, babelHelpers.defineAccessor(_obj, foobar, "get", function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very nitpicky, the PR is very good as it is. However, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 1fd56a3. |
||
return "foobar"; | ||
}, _foobar2 = foobar, _mutatorMap[_foobar2] = _mutatorMap[_foobar2] || {}, _mutatorMap[_foobar2].set = function (x) { | ||
}), babelHelpers.defineAccessor(_obj, foobar, "set", function (x) { | ||
console.log(x); | ||
}, _test = "test", _mutatorMap[_test] = _mutatorMap[_test] || {}, _mutatorMap[_test].get = function () { | ||
}), babelHelpers.defineAccessor(_obj, "test", "get", function () { | ||
return "regular getter after computed property"; | ||
}, _test2 = "test", _mutatorMap[_test2] = _mutatorMap[_test2] || {}, _mutatorMap[_test2].set = function (x) { | ||
}), babelHelpers.defineAccessor(_obj, "test", "set", function (x) { | ||
console.log(x); | ||
}, babelHelpers.defineEnumerableProperties(_obj, _mutatorMap), _obj); | ||
}), _obj); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var obj = { | ||
get ["x" + foo]() { return "heh"; } | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var obj = babelHelpers.defineAccessor({}, "x" + foo, "get", function () { | ||
return "heh"; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
var _foo, _mutatorMap; | ||
var _foo; | ||
var k = Symbol(); | ||
var foo = (_foo = {}, _foo[Symbol.iterator] = "foobar", _mutatorMap = {}, _mutatorMap[k] = _mutatorMap[k] || {}, _mutatorMap[k].get = function () { | ||
var foo = (_foo = {}, _foo[Symbol.iterator] = "foobar", babelHelpers.defineAccessor(_foo, k, "get", function () { | ||
return k; | ||
}, babelHelpers.defineEnumerableProperties(_foo, _mutatorMap), _foo); | ||
}), _foo); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
var _foobar, _foobar2, _test, _test2, _obj, _mutatorMap; | ||
var obj = (_obj = {}, _foobar = foobar, _mutatorMap = {}, _mutatorMap[_foobar] = _mutatorMap[_foobar] || {}, _mutatorMap[_foobar].get = function () { | ||
var _obj; | ||
var obj = (_obj = {}, babelHelpers.defineAccessor(_obj, foobar, "get", function () { | ||
return "foobar"; | ||
}, _foobar2 = foobar, _mutatorMap[_foobar2] = _mutatorMap[_foobar2] || {}, _mutatorMap[_foobar2].set = function (x) { | ||
}), babelHelpers.defineAccessor(_obj, foobar, "set", function (x) { | ||
console.log(x); | ||
}, _test = "test", _mutatorMap[_test] = _mutatorMap[_test] || {}, _mutatorMap[_test].get = function () { | ||
}), babelHelpers.defineAccessor(_obj, "test", "get", function () { | ||
return "regular getter after computed property"; | ||
}, _test2 = "test", _mutatorMap[_test2] = _mutatorMap[_test2] || {}, _mutatorMap[_test2].set = function (x) { | ||
}), babelHelpers.defineAccessor(_obj, "test", "set", function (x) { | ||
console.log(x); | ||
}, babelHelpers.defineEnumerableProperties(_obj, _mutatorMap), _obj); | ||
}), _obj); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var a = { | ||
get ["x"]() { return 0; }, | ||
["y"]: 1, | ||
}; | ||
expect(Object.keys(a)).toStrictEqual(["x", "y"]); | ||
|
||
var b = { | ||
get ["x"]() { return 0; }, | ||
["x"]: 1, | ||
}; | ||
expect(b.x).toBe(1); | ||
|
||
var x = { x, get x() { return 0; }, x }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, can you use two different variables? var y = { x, get x() { return 0; }, x }; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in c735135. |
||
expect(x.x).toBe(undefined); | ||
x.x = 1; | ||
expect(x.x).toBe(1); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var a = { | ||
get ["x"]() { return 0; }, | ||
["y"]: 1, | ||
}; | ||
|
||
var b = { | ||
get ["x"]() { return 0; }, | ||
["x"]: 1, | ||
}; | ||
|
||
var x = { x, get x() { return 0; }, x }; | ||
x.x = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"transform-duplicate-keys", | ||
"transform-computed-properties" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var _a, _b, _x; | ||
var a = (_a = {}, babelHelpers.defineAccessor(_a, "x", "get", function () { | ||
return 0; | ||
}), babelHelpers.defineProperty(_a, "y", 1), _a); | ||
var b = (_b = {}, babelHelpers.defineAccessor(_b, "x", "get", function () { | ||
return 0; | ||
}), babelHelpers.defineProperty(_b, "x", 1), _b); | ||
var x = (_x = { | ||
x | ||
}, babelHelpers.defineAccessor(_x, "x", "get", function () { | ||
return 0; | ||
}), babelHelpers.defineProperty(_x, "x", x), _x); | ||
x.x = 1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var obj = { | ||
get ["x" + foo]() { return "heh"; } | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var obj = babelHelpers.defineAccessor({}, "x" + foo, "get", function () { | ||
return "heh"; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
var _foo, _mutatorMap; | ||
var _foo; | ||
var k = Symbol(); | ||
var foo = (_foo = {}, babelHelpers.defineProperty(_foo, Symbol.iterator, "foobar"), _mutatorMap = {}, _mutatorMap[k] = _mutatorMap[k] || {}, _mutatorMap[k].get = function () { | ||
var foo = (_foo = {}, babelHelpers.defineProperty(_foo, Symbol.iterator, "foobar"), babelHelpers.defineAccessor(_foo, k, "get", function () { | ||
return k; | ||
}, babelHelpers.defineEnumerableProperties(_foo, _mutatorMap), _foo); | ||
}), _foo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the correct
minVersion
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to update it when releasing, could you update the Makefile like I did in 80c6889?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 16758f3.