Class Properties Tests (#7670)
* Round out class properties tests * Rename in preperation for private tests * Fix options
This commit is contained in:
parent
fa2c6c5164
commit
6f9b0546ef
63
packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/computed/output.js
vendored
Normal file
63
packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/computed/output.js
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
var foo = "foo";
|
||||||
|
|
||||||
|
var bar = () => {};
|
||||||
|
|
||||||
|
var four = 4;
|
||||||
|
|
||||||
|
var _one = one();
|
||||||
|
|
||||||
|
var _ref = 2 * four + seven;
|
||||||
|
|
||||||
|
var _undefined = undefined;
|
||||||
|
|
||||||
|
var _computed = computed();
|
||||||
|
|
||||||
|
var _computed2 = computed();
|
||||||
|
|
||||||
|
var _ref2 = "test" + one;
|
||||||
|
|
||||||
|
var _ref3 = /regex/;
|
||||||
|
var _bar = bar;
|
||||||
|
var _baz = baz;
|
||||||
|
var _ref4 = `template${expression}`;
|
||||||
|
|
||||||
|
var MyClass =
|
||||||
|
/*#__PURE__*/
|
||||||
|
function () {
|
||||||
|
function MyClass() {
|
||||||
|
babelHelpers.classCallCheck(this, MyClass);
|
||||||
|
this[null] = "null";
|
||||||
|
this[_undefined] = "undefined";
|
||||||
|
this[void 0] = "void 0";
|
||||||
|
this[_ref3] = "regex";
|
||||||
|
this[foo] = "foo";
|
||||||
|
this[_bar] = "bar";
|
||||||
|
this[_baz] = "baz";
|
||||||
|
this[`template`] = "template";
|
||||||
|
this[_ref4] = "template-with-expression";
|
||||||
|
}
|
||||||
|
|
||||||
|
babelHelpers.createClass(MyClass, [{
|
||||||
|
key: _ref2,
|
||||||
|
value: function () {}
|
||||||
|
}, {
|
||||||
|
key: "whatever",
|
||||||
|
get: function () {},
|
||||||
|
set: function (value) {}
|
||||||
|
}, {
|
||||||
|
key: _computed,
|
||||||
|
get: function () {}
|
||||||
|
}, {
|
||||||
|
key: _computed2,
|
||||||
|
set: function (value) {}
|
||||||
|
}], [{
|
||||||
|
key: 10,
|
||||||
|
value: function () {}
|
||||||
|
}]);
|
||||||
|
return MyClass;
|
||||||
|
}();
|
||||||
|
|
||||||
|
MyClass[_one] = "test";
|
||||||
|
MyClass[2 * 4 + 7] = "247";
|
||||||
|
MyClass[2 * four + 7] = "247";
|
||||||
|
MyClass[_ref] = "247";
|
||||||
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}]],
|
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}]],
|
||||||
"presets": ["es2015"]
|
"presets": ["stage-0", "es2015"]
|
||||||
}
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
var _class, _temp;
|
||||||
|
|
||||||
|
call((_temp = _class = function _class() {
|
||||||
|
babelHelpers.classCallCheck(this, _class);
|
||||||
|
}, _class.test = true, _temp));
|
||||||
|
|
||||||
|
var _default = function _default() {
|
||||||
|
babelHelpers.classCallCheck(this, _default);
|
||||||
|
};
|
||||||
|
|
||||||
|
_default.test = true;
|
||||||
|
export { _default as default };
|
||||||
|
;
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
function withContext(ComposedComponent) {
|
||||||
|
var _class, _temp;
|
||||||
|
|
||||||
|
return _temp = _class =
|
||||||
|
/*#__PURE__*/
|
||||||
|
function (_Component) {
|
||||||
|
babelHelpers.inherits(WithContext, _Component);
|
||||||
|
|
||||||
|
function WithContext() {
|
||||||
|
babelHelpers.classCallCheck(this, WithContext);
|
||||||
|
return babelHelpers.possibleConstructorReturn(this, (WithContext.__proto__ || Object.getPrototypeOf(WithContext)).apply(this, arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
return WithContext;
|
||||||
|
}(Component), _class.propTypes = {
|
||||||
|
context: PropTypes.shape({
|
||||||
|
addCss: PropTypes.func,
|
||||||
|
setTitle: PropTypes.func,
|
||||||
|
setMeta: PropTypes.func
|
||||||
|
})
|
||||||
|
}, _temp;
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"external-helpers",
|
||||||
|
"transform-async-to-generator",
|
||||||
|
["proposal-class-properties", {"loose": true}]
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
class MyClass {
|
||||||
|
constructor() {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
this.myAsyncMethod =
|
||||||
|
/*#__PURE__*/
|
||||||
|
babelHelpers.asyncToGenerator(function* () {
|
||||||
|
console.log(_this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
(class MyClass2 {
|
||||||
|
constructor() {
|
||||||
|
var _this2 = this;
|
||||||
|
|
||||||
|
this.myAsyncMethod =
|
||||||
|
/*#__PURE__*/
|
||||||
|
babelHelpers.asyncToGenerator(function* () {
|
||||||
|
console.log(_this2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default class MyClass3 {
|
||||||
|
constructor() {
|
||||||
|
var _this3 = this;
|
||||||
|
|
||||||
|
this.myAsyncMethod =
|
||||||
|
/*#__PURE__*/
|
||||||
|
babelHelpers.asyncToGenerator(function* () {
|
||||||
|
console.log(_this3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
30
packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/super-call/output.js
vendored
Normal file
30
packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/super-call/output.js
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
var A =
|
||||||
|
/*#__PURE__*/
|
||||||
|
function () {
|
||||||
|
function A() {
|
||||||
|
babelHelpers.classCallCheck(this, A);
|
||||||
|
}
|
||||||
|
|
||||||
|
babelHelpers.createClass(A, [{
|
||||||
|
key: "foo",
|
||||||
|
value: function foo() {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
return A;
|
||||||
|
}();
|
||||||
|
|
||||||
|
var B =
|
||||||
|
/*#__PURE__*/
|
||||||
|
function (_A) {
|
||||||
|
babelHelpers.inherits(B, _A);
|
||||||
|
|
||||||
|
function B(...args) {
|
||||||
|
var _temp, _this;
|
||||||
|
|
||||||
|
babelHelpers.classCallCheck(this, B);
|
||||||
|
return babelHelpers.possibleConstructorReturn(_this, (_temp = _this = babelHelpers.possibleConstructorReturn(this, (B.__proto__ || Object.getPrototypeOf(B)).call(this, ...args)), _this.foo = babelHelpers.get(B.prototype.__proto__ || Object.getPrototypeOf(B.prototype), "foo", babelHelpers.assertThisInitialized(_this)).call(_this), _temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
return B;
|
||||||
|
}(A);
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
var A = function A(_force) {
|
||||||
|
babelHelpers.classCallCheck(this, A);
|
||||||
|
this.force = force;
|
||||||
|
this.foo = babelHelpers.get(A.prototype.__proto__ || Object.getPrototypeOf(A.prototype), "method", babelHelpers.assertThisInitialized(this)).call(this);
|
||||||
|
};
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
class Foo {
|
||||||
|
static fn = () => console.log(this);
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["external-helpers", "transform-arrow-functions", "syntax-class-properties"]
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
var _this = this;
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
static fn = function () {
|
||||||
|
return console.log(_this);
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
class Foo {
|
||||||
|
fn = () => console.log(this);
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["external-helpers", "transform-arrow-functions", "syntax-class-properties"],
|
||||||
|
"throws": "Unable to transform arrow inside class property"
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
const actualOrder = [];
|
||||||
|
|
||||||
|
const track = i => {
|
||||||
|
actualOrder.push(i);
|
||||||
|
return i;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MyClass {
|
||||||
|
static [track(1)] = track(10);
|
||||||
|
[track(2)] = track(13);
|
||||||
|
get [track(3)]() {
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
set [track(4)](value) {
|
||||||
|
this.bar = value;
|
||||||
|
}
|
||||||
|
[track(5)] = track(14);
|
||||||
|
static [track(6)] = track(11);
|
||||||
|
static [track(7)] = track(12);
|
||||||
|
[track(8)]() {}
|
||||||
|
[track(9)] = track(15);
|
||||||
|
}
|
||||||
|
|
||||||
|
const inst = new MyClass();
|
||||||
|
|
||||||
|
const expectedOrder = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
||||||
|
expect(actualOrder).toEqual(expectedOrder);
|
||||||
|
|
||||||
|
expect(MyClass[1]).toBe(10);
|
||||||
|
expect(inst[2]).toBe(13);
|
||||||
|
expect(inst[3]).toBe("foo");
|
||||||
|
inst[4] = "baz";
|
||||||
|
expect(inst.bar).toBe("baz");
|
||||||
|
expect(inst[5]).toBe(14);
|
||||||
|
expect(MyClass[6]).toBe(11);
|
||||||
|
expect(MyClass[7]).toBe(12);
|
||||||
|
expect(typeof inst[8]).toBe("function");
|
||||||
|
expect(inst[9]).toBe(15);
|
||||||
25
packages/babel-plugin-proposal-class-properties/test/fixtures/public/computed/input.js
vendored
Normal file
25
packages/babel-plugin-proposal-class-properties/test/fixtures/public/computed/input.js
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const foo = "foo";
|
||||||
|
const bar = () => {};
|
||||||
|
const four = 4;
|
||||||
|
|
||||||
|
class MyClass {
|
||||||
|
static [one()] = "test";
|
||||||
|
static [2 * 4 + 7] = "247";
|
||||||
|
static [2 * four + 7] = "247";
|
||||||
|
static [2 * four + seven] = "247";
|
||||||
|
[null] = "null";
|
||||||
|
[undefined] = "undefined";
|
||||||
|
[void 0] = "void 0";
|
||||||
|
get ["whatever"]() {}
|
||||||
|
set ["whatever"](value) {}
|
||||||
|
get [computed()]() {}
|
||||||
|
set [computed()](value) {}
|
||||||
|
["test" + one]() {}
|
||||||
|
static [10]() {}
|
||||||
|
[/regex/] = "regex";
|
||||||
|
[foo] = "foo";
|
||||||
|
[bar] = "bar";
|
||||||
|
[baz] = "baz";
|
||||||
|
[`template`] = "template";
|
||||||
|
[`template${expression}`] = "template-with-expression";
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
call(class {
|
||||||
|
static test = true
|
||||||
|
});
|
||||||
|
|
||||||
|
export default class {
|
||||||
|
static test = true
|
||||||
|
};
|
||||||
14
packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T6719/input.js
vendored
Normal file
14
packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T6719/input.js
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
function withContext(ComposedComponent) {
|
||||||
|
return class WithContext extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
context: PropTypes.shape(
|
||||||
|
{
|
||||||
|
addCss: PropTypes.func,
|
||||||
|
setTitle: PropTypes.func,
|
||||||
|
setMeta: PropTypes.func,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
17
packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T7364/input.mjs
vendored
Normal file
17
packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T7364/input.mjs
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
class MyClass {
|
||||||
|
myAsyncMethod = async () => {
|
||||||
|
console.log(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(class MyClass2 {
|
||||||
|
myAsyncMethod = async () => {
|
||||||
|
console.log(this);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default class MyClass3 {
|
||||||
|
myAsyncMethod = async () => {
|
||||||
|
console.log(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
packages/babel-plugin-proposal-class-properties/test/fixtures/public/super-call/input.js
vendored
Normal file
9
packages/babel-plugin-proposal-class-properties/test/fixtures/public/super-call/input.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class A {
|
||||||
|
foo() {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends A {
|
||||||
|
foo = super.foo();
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user