Define class elements in the correct order (#12723)

* Define class elements in the correct order

* Object.gOPDescriptors is not available on Node.js 6

* Handle numeric keys

* Update test

* Update fixtures
This commit is contained in:
Nicolò Ribaudo
2021-02-02 02:22:16 +01:00
committed by GitHub
parent 20664a430e
commit 60ef190d05
21 changed files with 273 additions and 104 deletions

View File

@@ -0,0 +1,21 @@
let x = 1;
class A {
get [x]() {}
[(x = 3, 2)]() {}
set [x](_) {}
}
expect(Object.getOwnPropertyDescriptors(A.prototype)).toMatchObject({
1: {
get: expect.any(Function),
set: undefined,
},
2: {
value: expect.any(Function),
},
3: {
get: undefined,
set: expect.any(Function),
}
});

View File

@@ -0,0 +1,5 @@
class A {
get [x]() {}
[(x = 2, 3)]() {}
set [x](_) {}
}

View File

@@ -0,0 +1,3 @@
{
"minNodeVersion": "8.0.0"
}

View File

@@ -0,0 +1,26 @@
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
let A = /*#__PURE__*/function () {
"use strict";
function A() {
_classCallCheck(this, A);
}
_createClass(A, [{
key: x,
get: function () {}
}, {
key: (x = 2, 3),
value: function () {}
}, {
key: x,
set: function (_) {}
}]);
return A;
}();

View File

@@ -0,0 +1,12 @@
class A {
get x() {}
x() {}
set x(_) {}
}
expect(Object.getOwnPropertyDescriptors(A.prototype)).toMatchObject({
x: {
get: undefined,
set: expect.any(Function),
}
});

View File

@@ -0,0 +1,5 @@
class A {
get x() {}
x() {}
set x(_) {}
}

View File

@@ -0,0 +1,3 @@
{
"minNodeVersion": "8.0.0"
}

View File

@@ -0,0 +1,20 @@
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
let A = /*#__PURE__*/function () {
"use strict";
function A() {
_classCallCheck(this, A);
}
_createClass(A, [{
key: "x",
set: function (_) {}
}]);
return A;
}();

View File

@@ -0,0 +1,17 @@
class A {
get 1() {}
set [1](_) {}
get 2() {}
set "2"(_) {}
get 3n() {}
set 3(_) {}
get [4n]() {}
set "4"(_) {}
// Different keys
get 5n() {}
set "5n"(_) {}
}

View File

@@ -0,0 +1,40 @@
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
let A = /*#__PURE__*/function () {
"use strict";
function A() {
_classCallCheck(this, A);
}
_createClass(A, [{
key: "1",
get: function () {},
set: function (_) {}
}, {
key: "2",
get: function () {},
set: function (_) {}
}, {
key: "3",
get: function () {},
set: function (_) {}
}, {
key: "4",
get: function () {},
set: function (_) {} // Different keys
}, {
key: "5",
get: function () {}
}, {
key: "5n",
set: function (_) {}
}]);
return A;
}();

View File

@@ -44,13 +44,13 @@ let Obj = /*#__PURE__*/function (_Base) {
}
_createClass(Obj, [{
key: "test",
get: function () {}
}, {
key: "set",
value: function set() {
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
}
}, {
key: "test",
get: function () {}
}]);
return Obj;

View File

@@ -46,16 +46,16 @@ let Obj = /*#__PURE__*/function (_Base) {
}
_createClass(Obj, [{
key: "set",
value: function set() {
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
}
}, {
key: "test",
set: function (v) {
expect(this).toBe(obj);
value = v;
}
}, {
key: "set",
value: function set() {
return _set(_getPrototypeOf(Obj.prototype), "test", 3, this, true);
}
}]);
return Obj;

View File

@@ -1,6 +1,6 @@
class Foo {
foo() {}
"foo"() {}
"foo"() { "second" }
[bar]() {}
[bar + "foo"]() {}
}

View File

@@ -7,10 +7,9 @@ var Foo = /*#__PURE__*/function () {
babelHelpers.createClass(Foo, [{
key: "foo",
value: function foo() {}
}, {
key: "foo",
value: function foo() {}
value: function foo() {
"second";
}
}, {
key: bar,
value: function value() {}