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: Computed properties should keep original definition order #15232

Merged
merged 12 commits into from
Dec 5, 2022
Prev Previous commit
Next Next commit
Change parameter order of defineAccessor
  • Loading branch information
SuperSodaSea committed Nov 29, 2022
commit 1fd56a3c4e900159ae31202c5aae8e90c88042c6
2 changes: 1 addition & 1 deletion packages/babel-helpers/src/helpers-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default Object.freeze({
),
defineAccessor: helper(
"7.20.6",
"export default function _defineAccessor(obj,key,type,fn){var desc={configurable:!0,enumerable:!0};return desc[type]=fn,Object.defineProperty(obj,key,desc)}",
"export default function _defineAccessor(type,obj,key,fn){var desc={configurable:!0,enumerable:!0};return desc[type]=fn,Object.defineProperty(obj,key,desc)}",
),
iterableToArrayLimit: helper(
"7.0.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helpers/src/helpers/defineAccessor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @minVersion 7.20.6 */
Copy link
Contributor Author

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...

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 16758f3.


export default function _defineAccessor(obj, key, type, fn) {
export default function _defineAccessor(type, obj, key, fn) {
var desc = { configurable: true, enumerable: true };
// type should be "get" or "set"
desc[type] = fn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ export default declare((api, options: Options) => {

if (computedProps.length === 1) {
return t.callExpression(state.addHelper("defineAccessor"), [
t.stringLiteral(prop.kind),
initPropExpression,
key,
t.stringLiteral(prop.kind),
getValue(prop),
]);
} else {
body.push(
t.expressionStatement(
t.callExpression(state.addHelper("defineAccessor"), [
t.stringLiteral(prop.kind),
t.cloneNode(objId),
key,
t.stringLiteral(prop.kind),
getValue(prop),
]),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var _obj;
var obj = (_obj = {}, babelHelpers.defineAccessor(_obj, foobar, "get", function () {
var obj = (_obj = {}, babelHelpers.defineAccessor("get", _obj, foobar, function () {
return "foobar";
}), babelHelpers.defineAccessor(_obj, foobar, "set", function (x) {
}), babelHelpers.defineAccessor("set", _obj, foobar, function (x) {
console.log(x);
}), babelHelpers.defineAccessor(_obj, "test", "get", function () {
}), babelHelpers.defineAccessor("get", _obj, "test", function () {
return "regular getter after computed property";
}), babelHelpers.defineAccessor(_obj, "test", "set", function (x) {
}), babelHelpers.defineAccessor("set", _obj, "test", function (x) {
console.log(x);
}), _obj);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var obj = babelHelpers.defineAccessor({}, "x" + foo, "get", function () {
var obj = babelHelpers.defineAccessor("get", {}, "x" + foo, function () {
return "heh";
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var _foo;
var k = Symbol();
var foo = (_foo = {}, _foo[Symbol.iterator] = "foobar", babelHelpers.defineAccessor(_foo, k, "get", function () {
var foo = (_foo = {}, _foo[Symbol.iterator] = "foobar", babelHelpers.defineAccessor("get", _foo, k, function () {
return k;
}), _foo);
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var _obj;
var obj = (_obj = {}, babelHelpers.defineAccessor(_obj, foobar, "get", function () {
var obj = (_obj = {}, babelHelpers.defineAccessor("get", _obj, foobar, function () {
return "foobar";
}), babelHelpers.defineAccessor(_obj, foobar, "set", function (x) {
}), babelHelpers.defineAccessor("set", _obj, foobar, function (x) {
console.log(x);
}), babelHelpers.defineAccessor(_obj, "test", "get", function () {
}), babelHelpers.defineAccessor("get", _obj, "test", function () {
return "regular getter after computed property";
}), babelHelpers.defineAccessor(_obj, "test", "set", function (x) {
}), babelHelpers.defineAccessor("set", _obj, "test", function (x) {
console.log(x);
}), _obj);
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var _a, _b, _x;
var a = (_a = {}, babelHelpers.defineAccessor(_a, "x", "get", function () {
var a = (_a = {}, babelHelpers.defineAccessor("get", _a, "x", function () {
return 0;
}), babelHelpers.defineProperty(_a, "y", 1), _a);
var b = (_b = {}, babelHelpers.defineAccessor(_b, "x", "get", function () {
var b = (_b = {}, babelHelpers.defineAccessor("get", _b, "x", function () {
return 0;
}), babelHelpers.defineProperty(_b, "x", 1), _b);
var x = (_x = {
x
}, babelHelpers.defineAccessor(_x, "x", "get", function () {
}, babelHelpers.defineAccessor("get", _x, "x", function () {
return 0;
}), babelHelpers.defineProperty(_x, "x", x), _x);
x.x = 1;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var obj = babelHelpers.defineAccessor({}, "x" + foo, "get", function () {
var obj = babelHelpers.defineAccessor("get", {}, "x" + foo, function () {
return "heh";
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var _foo;
var k = Symbol();
var foo = (_foo = {}, babelHelpers.defineProperty(_foo, Symbol.iterator, "foobar"), babelHelpers.defineAccessor(_foo, k, "get", function () {
var foo = (_foo = {}, babelHelpers.defineProperty(_foo, Symbol.iterator, "foobar"), babelHelpers.defineAccessor("get", _foo, k, function () {
return k;
}), _foo);