fix exported classes with static class properties - fixes #2868
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
var foo = "bar";
|
||||
|
||||
class Foo {
|
||||
bar = foo;
|
||||
|
||||
constructor() {
|
||||
var foo = "foo";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
var foo = "bar";
|
||||
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
|
||||
_initialiseProps.call(this);
|
||||
|
||||
var foo = "foo";
|
||||
};
|
||||
|
||||
var _initialiseProps = function () {
|
||||
this.bar = foo;
|
||||
};
|
||||
3
packages/babel-plugin-transform-class-properties/test/fixtures/general/derived/actual.js
vendored
Normal file
3
packages/babel-plugin-transform-class-properties/test/fixtures/general/derived/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo extends Bar {
|
||||
bar = "foo";
|
||||
}
|
||||
12
packages/babel-plugin-transform-class-properties/test/fixtures/general/derived/expected.js
vendored
Normal file
12
packages/babel-plugin-transform-class-properties/test/fixtures/general/derived/expected.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
var Foo = (function (_Bar) {
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
|
||||
function Foo(...args) {
|
||||
var _temp, _this;
|
||||
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
return babelHelpers.possibleConstructorReturn(_this, (_temp = (_this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this, ...args)), _this), _this.bar = "foo", _temp));
|
||||
}
|
||||
|
||||
return Foo;
|
||||
})(Bar);
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
bar;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
};
|
||||
3
packages/babel-plugin-transform-class-properties/test/fixtures/general/instance/actual.js
vendored
Normal file
3
packages/babel-plugin-transform-class-properties/test/fixtures/general/instance/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
bar = "foo";
|
||||
}
|
||||
4
packages/babel-plugin-transform-class-properties/test/fixtures/general/instance/expected.js
vendored
Normal file
4
packages/babel-plugin-transform-class-properties/test/fixtures/general/instance/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
this.bar = "foo";
|
||||
};
|
||||
3
packages/babel-plugin-transform-class-properties/test/fixtures/general/options.json
vendored
Normal file
3
packages/babel-plugin-transform-class-properties/test/fixtures/general/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers-2", "transform-class-properties", "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export class MyClass {
|
||||
static property = value;
|
||||
}
|
||||
|
||||
export default class MyClass2 {
|
||||
static property = value;
|
||||
}
|
||||
12
packages/babel-plugin-transform-class-properties/test/fixtures/general/static-export/expected.js
vendored
Normal file
12
packages/babel-plugin-transform-class-properties/test/fixtures/general/static-export/expected.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
export var MyClass = function MyClass() {
|
||||
babelHelpers.classCallCheck(this, MyClass);
|
||||
};
|
||||
|
||||
MyClass.property = value;
|
||||
|
||||
var MyClass2 = function MyClass2() {
|
||||
babelHelpers.classCallCheck(this, MyClass2);
|
||||
};
|
||||
|
||||
export default MyClass2;
|
||||
MyClass2.property = value;
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
static bar;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
static num;
|
||||
}
|
||||
|
||||
assert.equal("num" in Foo, false);
|
||||
assert.equal(Foo.num, undefined);
|
||||
@@ -0,0 +1,3 @@
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
};
|
||||
3
packages/babel-plugin-transform-class-properties/test/fixtures/general/static/actual.js
vendored
Normal file
3
packages/babel-plugin-transform-class-properties/test/fixtures/general/static/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
static bar = "foo";
|
||||
}
|
||||
9
packages/babel-plugin-transform-class-properties/test/fixtures/general/static/exec.js
vendored
Normal file
9
packages/babel-plugin-transform-class-properties/test/fixtures/general/static/exec.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
static num = 0;
|
||||
static str = "foo";
|
||||
}
|
||||
|
||||
assert.equal(Foo.num, 0);
|
||||
assert.equal(Foo.num = 1, 1);
|
||||
assert.equal(Foo.str, "foo");
|
||||
assert.equal(Foo.str = "bar", "bar");
|
||||
5
packages/babel-plugin-transform-class-properties/test/fixtures/general/static/expected.js
vendored
Normal file
5
packages/babel-plugin-transform-class-properties/test/fixtures/general/static/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
};
|
||||
|
||||
Foo.bar = "foo";
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo extends Bar {
|
||||
bar = "foo";
|
||||
|
||||
constructor() {
|
||||
foo(super());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
var Foo = (function (_Bar) {
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
|
||||
function Foo() {
|
||||
var _temp, _this;
|
||||
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
|
||||
foo((_temp = (_this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this)), _this), _this.bar = "foo", _temp));
|
||||
return _this;
|
||||
}
|
||||
|
||||
return Foo;
|
||||
})(Bar);
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo extends Bar {
|
||||
bar = "foo";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
var Foo = (function (_Bar) {
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
|
||||
var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this));
|
||||
|
||||
_this.bar = "foo";
|
||||
return _this;
|
||||
}
|
||||
|
||||
return Foo;
|
||||
})(Bar);
|
||||
Reference in New Issue
Block a user