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:
21
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/exec.js
vendored
Normal file
21
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/exec.js
vendored
Normal 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),
|
||||
}
|
||||
});
|
||||
5
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/input.js
vendored
Normal file
5
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/input.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
get [x]() {}
|
||||
[(x = 2, 3)]() {}
|
||||
set [x](_) {}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minNodeVersion": "8.0.0"
|
||||
}
|
||||
26
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/output.js
vendored
Normal file
26
packages/babel-plugin-transform-classes/test/fixtures/get-set/change-computed-key/output.js
vendored
Normal 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;
|
||||
}();
|
||||
12
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/exec.js
vendored
Normal file
12
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/exec.js
vendored
Normal 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),
|
||||
}
|
||||
});
|
||||
5
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/input.js
vendored
Normal file
5
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/input.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
get x() {}
|
||||
x() {}
|
||||
set x(_) {}
|
||||
}
|
||||
3
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/options.json
vendored
Normal file
3
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minNodeVersion": "8.0.0"
|
||||
}
|
||||
20
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/output.js
vendored
Normal file
20
packages/babel-plugin-transform-classes/test/fixtures/get-set/method-conflict/output.js
vendored
Normal 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;
|
||||
}();
|
||||
17
packages/babel-plugin-transform-classes/test/fixtures/get-set/numeric-keys/input.js
vendored
Normal file
17
packages/babel-plugin-transform-classes/test/fixtures/get-set/numeric-keys/input.js
vendored
Normal 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"(_) {}
|
||||
}
|
||||
40
packages/babel-plugin-transform-classes/test/fixtures/get-set/numeric-keys/output.js
vendored
Normal file
40
packages/babel-plugin-transform-classes/test/fixtures/get-set/numeric-keys/output.js
vendored
Normal 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;
|
||||
}();
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Foo {
|
||||
foo() {}
|
||||
"foo"() {}
|
||||
"foo"() { "second" }
|
||||
[bar]() {}
|
||||
[bar + "foo"]() {}
|
||||
}
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
Reference in New Issue
Block a user