-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Computed properties should keep original definition order (#15232)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Fixes #15140
- Loading branch information
1 parent
2bba4a5
commit e5e1369
Showing
22 changed files
with
188 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* @minVersion 7.20.6 */ | ||
|
||
export default function _defineAccessor(type, obj, key, fn) { | ||
var desc = { configurable: true, enumerable: true }; | ||
// type should be "get" or "set" | ||
desc[type] = fn; | ||
return Object.defineProperty(obj, key, desc); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
...rm-computed-properties/test/fixtures/assumption-setComputedProperties/accessors/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("get", _obj, foobar, function () { | ||
return "foobar"; | ||
}, _foobar2 = foobar, _mutatorMap[_foobar2] = _mutatorMap[_foobar2] || {}, _mutatorMap[_foobar2].set = function (x) { | ||
}), babelHelpers.defineAccessor("set", _obj, foobar, function (x) { | ||
console.log(x); | ||
}, _test = "test", _mutatorMap[_test] = _mutatorMap[_test] || {}, _mutatorMap[_test].get = function () { | ||
}), babelHelpers.defineAccessor("get", _obj, "test", function () { | ||
return "regular getter after computed property"; | ||
}, _test2 = "test", _mutatorMap[_test2] = _mutatorMap[_test2] || {}, _mutatorMap[_test2].set = function (x) { | ||
}), babelHelpers.defineAccessor("set", _obj, "test", function (x) { | ||
console.log(x); | ||
}, babelHelpers.defineEnumerableProperties(_obj, _mutatorMap), _obj); | ||
}), _obj); |
3 changes: 3 additions & 0 deletions
3
...mputed-properties/test/fixtures/assumption-setComputedProperties/single-accessor/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var obj = { | ||
get ["x" + foo]() { return "heh"; } | ||
}; |
3 changes: 3 additions & 0 deletions
3
...puted-properties/test/fixtures/assumption-setComputedProperties/single-accessor/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var obj = babelHelpers.defineAccessor("get", {}, "x" + foo, function () { | ||
return "heh"; | ||
}); |
6 changes: 3 additions & 3 deletions
6
...sform-computed-properties/test/fixtures/assumption-setComputedProperties/symbol/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("get", _foo, k, function () { | ||
return k; | ||
}, babelHelpers.defineEnumerableProperties(_foo, _mutatorMap), _foo); | ||
}), _foo); |
12 changes: 6 additions & 6 deletions
12
packages/babel-plugin-transform-computed-properties/test/fixtures/spec/accessors/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("get", _obj, foobar, function () { | ||
return "foobar"; | ||
}, _foobar2 = foobar, _mutatorMap[_foobar2] = _mutatorMap[_foobar2] || {}, _mutatorMap[_foobar2].set = function (x) { | ||
}), babelHelpers.defineAccessor("set", _obj, foobar, function (x) { | ||
console.log(x); | ||
}, _test = "test", _mutatorMap[_test] = _mutatorMap[_test] || {}, _mutatorMap[_test].get = function () { | ||
}), babelHelpers.defineAccessor("get", _obj, "test", function () { | ||
return "regular getter after computed property"; | ||
}, _test2 = "test", _mutatorMap[_test2] = _mutatorMap[_test2] || {}, _mutatorMap[_test2].set = function (x) { | ||
}), babelHelpers.defineAccessor("set", _obj, "test", function (x) { | ||
console.log(x); | ||
}, babelHelpers.defineEnumerableProperties(_obj, _mutatorMap), _obj); | ||
}), _obj); |
17 changes: 17 additions & 0 deletions
17
...es/babel-plugin-transform-computed-properties/test/fixtures/spec/definition-order/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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 = 1; | ||
var y = { x, get x() { return 0; }, x }; | ||
expect(y.x).toBe(1); | ||
y.x = 2; | ||
expect(y.x).toBe(2); |
13 changes: 13 additions & 0 deletions
13
...s/babel-plugin-transform-computed-properties/test/fixtures/spec/definition-order/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var a = { | ||
get ["x"]() { return 0; }, | ||
["y"]: 1, | ||
}; | ||
|
||
var b = { | ||
get ["x"]() { return 0; }, | ||
["x"]: 1, | ||
}; | ||
|
||
var x = 1; | ||
var y = { x, get x() { return 0; }, x }; | ||
y.x = 2; |
6 changes: 6 additions & 0 deletions
6
...bel-plugin-transform-computed-properties/test/fixtures/spec/definition-order/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"transform-duplicate-keys", | ||
"transform-computed-properties" | ||
] | ||
} |
14 changes: 14 additions & 0 deletions
14
.../babel-plugin-transform-computed-properties/test/fixtures/spec/definition-order/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var _a, _b, _y; | ||
var a = (_a = {}, babelHelpers.defineAccessor("get", _a, "x", function () { | ||
return 0; | ||
}), babelHelpers.defineProperty(_a, "y", 1), _a); | ||
var b = (_b = {}, babelHelpers.defineAccessor("get", _b, "x", function () { | ||
return 0; | ||
}), babelHelpers.defineProperty(_b, "x", 1), _b); | ||
var x = 1; | ||
var y = (_y = { | ||
x | ||
}, babelHelpers.defineAccessor("get", _y, "x", function () { | ||
return 0; | ||
}), babelHelpers.defineProperty(_y, "x", x), _y); | ||
y.x = 2; |
3 changes: 3 additions & 0 deletions
3
...es/babel-plugin-transform-computed-properties/test/fixtures/spec/single-accessor/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var obj = { | ||
get ["x" + foo]() { return "heh"; } | ||
}; |
3 changes: 3 additions & 0 deletions
3
...s/babel-plugin-transform-computed-properties/test/fixtures/spec/single-accessor/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var obj = babelHelpers.defineAccessor("get", {}, "x" + foo, function () { | ||
return "heh"; | ||
}); |
6 changes: 3 additions & 3 deletions
6
packages/babel-plugin-transform-computed-properties/test/fixtures/spec/symbol/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("get", _foo, k, function () { | ||
return k; | ||
}, babelHelpers.defineEnumerableProperties(_foo, _mutatorMap), _foo); | ||
}), _foo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.