Rename all proposal plugins to -proposal- from -transform- (#6570)

This commit is contained in:
Henry Zhu
2017-10-27 15:26:38 -04:00
committed by GitHub
parent a94aa54230
commit c41abd79a1
599 changed files with 372 additions and 372 deletions

View File

@@ -0,0 +1,3 @@
src
test
*.log

View File

@@ -0,0 +1,149 @@
# @babel/plugin-proposal-class-properties
> This plugin transforms class properties
## Example
Below is a class with four class properties which will be transformed.
```js
class Bork {
//Property initializer syntax
instanceProperty = "bork";
boundFunction = () => {
return this.instanceProperty;
};
//Static class properties
static staticProperty = "babelIsCool";
static staticFunction = function() {
return Bork.staticProperty;
};
}
let myBork = new Bork;
//Property initializers are not on the prototype.
console.log(myBork.__proto__.boundFunction); // > undefined
//Bound functions are bound to the class instance.
console.log(myBork.boundFunction.call(undefined)); // > "bork"
//Static function exists on the class.
console.log(Bork.staticFunction()); // > "babelIsCool"
```
## Installation
```sh
npm install --save-dev @babel/plugin-proposal-class-properties
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
Without options:
```json
{
"plugins": ["@babel/proposal-class-properties"]
}
```
With options:
```json
{
"plugins": [
["@babel/proposal-class-properties", { "loose": true }]
]
}
```
### Via CLI
```sh
babel --plugins @babel/proposal-class-properties script.js
```
### Via Node API
```javascript
require("@babel/core").transform("code", {
plugins: ["@babel/proposal-class-properties"]
});
```
## Options
### `loose`
`boolean`, defaults to `false`.
When `true`, class properties are compiled to use an assignment expression instead of `Object.defineProperty`.
#### Example
```js
class Bork {
static a = 'foo';
static b;
x = 'bar';
y;
}
```
Without `{ "loose": true }`, the above code will compile to the following, using `Object.definePropery`:
```js
var Bork = function Bork() {
babelHelpers.classCallCheck(this, Bork);
Object.defineProperty(this, "x", {
configurable: true,
enumerable: true,
writable: true,
value: 'bar'
});
Object.defineProperty(this, "y", {
configurable: true,
enumerable: true,
writable: true,
value: void 0
});
};
Object.defineProperty(Bork, "a", {
configurable: true,
enumerable: true,
writable: true,
value: 'foo'
});
Object.defineProperty(Bork, "b", {
configurable: true,
enumerable: true,
writable: true,
value: void 0
});
```
However, with `{ "loose": true }`, it will compile using assignment expressions:
```js
var Bork = function Bork() {
babelHelpers.classCallCheck(this, Bork);
this.x = 'bar';
this.y = void 0;
};
Bork.a = 'foo';
Bork.b = void 0;
```
## References
* [Proposal: ES Class Fields & Static Properties](https://github.com/jeffmo/es-class-static-properties-and-fields)

View File

@@ -0,0 +1,22 @@
{
"name": "@babel/plugin-proposal-class-properties",
"version": "7.0.0-beta.3",
"description": "This plugin transforms static class properties as well as properties declared with the property initializer syntax",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-class-properties",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/helper-function-name": "7.0.0-beta.3",
"@babel/plugin-syntax-class-properties": "7.0.0-beta.3",
"@babel/template": "7.0.0-beta.3"
},
"peerDependencies": {
"@babel/core": "7.0.0-beta.3"
},
"devDependencies": {
"@babel/helper-plugin-test-runner": "7.0.0-beta.3"
}
}

View File

@@ -0,0 +1,212 @@
import nameFunction from "@babel/helper-function-name";
import template from "@babel/template";
import syntaxClassProperties from "@babel/plugin-syntax-class-properties";
export default function({ types: t }, options) {
const { loose } = options;
const findBareSupers = {
Super(path) {
if (path.parentPath.isCallExpression({ callee: path.node })) {
this.push(path.parentPath);
}
},
};
const referenceVisitor = {
"TSTypeAnnotation|TypeAnnotation"(path) {
path.skip();
},
ReferencedIdentifier(path) {
if (this.scope.hasOwnBinding(path.node.name)) {
this.collision = true;
path.skip();
}
},
};
const buildClassPropertySpec = (ref, { key, value, computed }, scope) => {
return template.statement`
Object.defineProperty(REF, KEY, {
configurable: true,
enumerable: true,
writable: true,
value: VALUE
});
`({
REF: ref,
KEY: t.isIdentifier(key) && !computed ? t.stringLiteral(key.name) : key,
VALUE: value || scope.buildUndefinedNode(),
});
};
const buildClassPropertyLoose = (ref, { key, value, computed }, scope) => {
return template.statement`MEMBER = VALUE`({
MEMBER: t.memberExpression(ref, key, computed || t.isLiteral(key)),
VALUE: value || scope.buildUndefinedNode(),
});
};
const buildClassProperty = loose
? buildClassPropertyLoose
: buildClassPropertySpec;
return {
inherits: syntaxClassProperties,
visitor: {
Class(path) {
const isDerived = !!path.node.superClass;
let constructor;
const props = [];
const body = path.get("body");
for (const path of body.get("body")) {
if (path.isClassProperty()) {
props.push(path);
} else if (path.isClassMethod({ kind: "constructor" })) {
constructor = path;
}
}
if (!props.length) return;
const nodes = [];
let ref;
if (path.isClassExpression() || !path.node.id) {
nameFunction(path);
ref = path.scope.generateUidIdentifier("class");
} else {
// path.isClassDeclaration() && path.node.id
ref = path.node.id;
}
let instanceBody = [];
for (const prop of props) {
const propNode = prop.node;
if (propNode.decorators && propNode.decorators.length > 0) continue;
const isStatic = propNode.static;
if (isStatic) {
nodes.push(buildClassProperty(ref, propNode, path.scope));
} else {
// Make sure computed property names are only evaluated once (upon
// class definition).
if (propNode.computed) {
const ident = path.scope.generateUidIdentifierBasedOnNode(
propNode.key,
);
nodes.push(
t.variableDeclaration("var", [
t.variableDeclarator(ident, propNode.key),
]),
);
propNode.key = t.clone(ident);
}
instanceBody.push(
buildClassProperty(t.thisExpression(), propNode, path.scope),
);
}
}
if (instanceBody.length) {
if (!constructor) {
const newConstructor = t.classMethod(
"constructor",
t.identifier("constructor"),
[],
t.blockStatement([]),
);
if (isDerived) {
newConstructor.params = [t.restElement(t.identifier("args"))];
newConstructor.body.body.push(
t.returnStatement(
t.callExpression(t.super(), [
t.spreadElement(t.identifier("args")),
]),
),
);
}
[constructor] = body.unshiftContainer("body", newConstructor);
}
const collisionState = {
collision: false,
scope: constructor.scope,
};
for (const prop of props) {
prop.traverse(referenceVisitor, collisionState);
if (collisionState.collision) break;
}
if (collisionState.collision) {
const initialisePropsRef = path.scope.generateUidIdentifier(
"initialiseProps",
);
nodes.push(
t.variableDeclaration("var", [
t.variableDeclarator(
initialisePropsRef,
t.functionExpression(
null,
[],
t.blockStatement(instanceBody),
),
),
]),
);
instanceBody = [
t.expressionStatement(
t.callExpression(
t.memberExpression(initialisePropsRef, t.identifier("call")),
[t.thisExpression()],
),
),
];
}
//
if (isDerived) {
const bareSupers = [];
constructor.traverse(findBareSupers, bareSupers);
for (const bareSuper of bareSupers) {
bareSuper.insertAfter(instanceBody);
}
} else {
constructor.get("body").unshiftContainer("body", instanceBody);
}
}
for (const prop of props) {
prop.remove();
}
if (!nodes.length) return;
if (path.isClassExpression()) {
path.scope.push({ id: ref });
path.replaceWith(t.assignmentExpression("=", ref, path.node));
} else {
// path.isClassDeclaration()
if (!path.node.id) {
path.node.id = ref;
}
if (path.parentPath.isExportDeclaration()) {
path = path.parentPath;
}
}
path.insertAfter(nodes);
},
},
};
}

View File

@@ -0,0 +1,6 @@
class C {
// Output should not use `_initialiseProps`
x: T;
y = 0;
constructor(T) {}
}

View File

@@ -0,0 +1,8 @@
class C {
// Output should not use `_initialiseProps`
constructor(T) {
this.x = void 0;
this.y = 0;
}
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["transform-typescript", ["proposal-class-properties", {"loose": true }]]
}

View File

@@ -0,0 +1,6 @@
class C {
// Output should not use `_initialiseProps`
x: T;
y = 0;
constructor(T) {}
}

View File

@@ -0,0 +1,18 @@
class C {
// Output should not use `_initialiseProps`
constructor(T) {
Object.defineProperty(this, "x", {
configurable: true,
enumerable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "y", {
configurable: true,
enumerable: true,
writable: true,
value: 0
});
}
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["transform-typescript", "proposal-class-properties"]
}

View File

@@ -0,0 +1,3 @@
class Foo {
static fn = () => console.log(this);
}

View File

@@ -0,0 +1,7 @@
var _this = this;
class Foo {
static fn = function () {
return console.log(_this);
};
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-arrow-functions", "syntax-class-properties"]
}

View File

@@ -0,0 +1,3 @@
class Foo {
fn = () => console.log(this);
}

View File

@@ -0,0 +1,4 @@
{
"plugins": ["external-helpers", "transform-es2015-arrow-functions", "syntax-class-properties"],
"throws": "Unable to transform arrow inside class property"
}

View File

@@ -0,0 +1,9 @@
var foo = "bar";
class Foo {
bar = foo;
constructor() {
var foo = "foo";
}
}

View File

@@ -0,0 +1,18 @@
var foo = "bar";
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
_initialiseProps.call(this);
var foo = "foo";
};
var _initialiseProps = function () {
Object.defineProperty(this, "bar", {
configurable: true,
enumerable: true,
writable: true,
value: foo
});
};

View File

@@ -0,0 +1,3 @@
class Foo extends Bar {
bar = "foo";
}

View File

@@ -0,0 +1,19 @@
var Foo =
/*#__PURE__*/
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, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this, ...args)), Object.defineProperty(_this, "bar", {
configurable: true,
enumerable: true,
writable: true,
value: "foo"
}), _temp));
}
return Foo;
}(Bar);

View File

@@ -0,0 +1,9 @@
class Child extends Parent {
constructor() {
super();
}
scopedFunctionWithThis = () => {
this.name = {};
}
}

View File

@@ -0,0 +1,23 @@
var Child =
/*#__PURE__*/
function (_Parent) {
babelHelpers.inherits(Child, _Parent);
function Child() {
var _this;
babelHelpers.classCallCheck(this, Child);
_this = babelHelpers.possibleConstructorReturn(this, (Child.__proto__ || Object.getPrototypeOf(Child)).call(this));
Object.defineProperty(_this, "scopedFunctionWithThis", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
_this.name = {};
}
});
return _this;
}
return Child;
}(Parent);

View File

@@ -0,0 +1,4 @@
{
"plugins": ["external-helpers", "proposal-class-properties"],
"presets": ["stage-0", "es2015"]
}

View File

@@ -0,0 +1,13 @@
function test(x) {
class F {
[x] = 1;
constructor() {}
}
x = 'deadbeef';
assert.strictEqual(new F().foo, 1);
x = 'wrong';
assert.strictEqual(new F().foo, 1);
}
test('foo');

View File

@@ -0,0 +1,13 @@
function test(x) {
class F {
[x] = 1;
constructor() {}
}
x = 'deadbeef';
assert.strictEqual(new F().foo, 1);
x = 'wrong';
assert.strictEqual(new F().foo, 1);
}
test('foo');

View File

@@ -0,0 +1,19 @@
function test(x) {
var F = function F() {
babelHelpers.classCallCheck(this, F);
Object.defineProperty(this, _x, {
configurable: true,
enumerable: true,
writable: true,
value: 1
});
};
var _x = x;
x = 'deadbeef';
assert.strictEqual(new F().foo, 1);
x = 'wrong';
assert.strictEqual(new F().foo, 1);
}
test('foo');

View File

@@ -0,0 +1,3 @@
class Foo {
bar;
}

View File

@@ -0,0 +1,9 @@
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
Object.defineProperty(this, "bar", {
configurable: true,
enumerable: true,
writable: true,
value: void 0
});
};

View File

@@ -0,0 +1,3 @@
class Foo {
bar = "foo";
}

View File

@@ -0,0 +1,9 @@
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
Object.defineProperty(this, "bar", {
configurable: true,
enumerable: true,
writable: true,
value: "foo"
});
};

View File

@@ -0,0 +1,11 @@
export default param =>
class App {
static props = {
prop1: 'prop1',
prop2: 'prop2'
}
getParam() {
return param;
}
}

View File

@@ -0,0 +1,27 @@
export default (param => {
var _class, _temp;
return _temp = _class =
/*#__PURE__*/
function () {
function App() {
babelHelpers.classCallCheck(this, App);
}
babelHelpers.createClass(App, [{
key: "getParam",
value: function getParam() {
return param;
}
}]);
return App;
}(), Object.defineProperty(_class, "props", {
configurable: true,
enumerable: true,
writable: true,
value: {
prop1: 'prop1',
prop2: 'prop2'
}
}), _temp;
});

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "proposal-class-properties", "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
}

View File

@@ -0,0 +1,7 @@
call(class {
static test = true
});
export default class {
static test = true
};

View File

@@ -0,0 +1,23 @@
var _class, _temp;
call((_temp = _class = function _class() {
babelHelpers.classCallCheck(this, _class);
}, Object.defineProperty(_class, "test", {
configurable: true,
enumerable: true,
writable: true,
value: true
}), _temp));
var _class2 = function _class2() {
babelHelpers.classCallCheck(this, _class2);
};
Object.defineProperty(_class2, "test", {
configurable: true,
enumerable: true,
writable: true,
value: true
});
export { _class2 as default };
;

View 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,
}
),
};
};
}

View File

@@ -0,0 +1,27 @@
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), Object.defineProperty(_class, "propTypes", {
configurable: true,
enumerable: true,
writable: true,
value: {
context: PropTypes.shape({
addCss: PropTypes.func,
setTitle: PropTypes.func,
setMeta: PropTypes.func
})
}
}), _temp;
}

View 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);
}
}

View File

@@ -0,0 +1,65 @@
class MyClass {
constructor() {
var _this = this;
Object.defineProperty(this, "myAsyncMethod", {
configurable: true,
enumerable: true,
writable: true,
value: (() => {
var _ref = babelHelpers.asyncToGenerator(function* () {
console.log(_this);
});
return function value() {
return _ref.apply(this, arguments);
};
})()
});
}
}
(class MyClass2 {
constructor() {
var _this2 = this;
Object.defineProperty(this, "myAsyncMethod", {
configurable: true,
enumerable: true,
writable: true,
value: (() => {
var _ref2 = babelHelpers.asyncToGenerator(function* () {
console.log(_this2);
});
return function value() {
return _ref2.apply(this, arguments);
};
})()
});
}
});
export default class MyClass3 {
constructor() {
var _this3 = this;
Object.defineProperty(this, "myAsyncMethod", {
configurable: true,
enumerable: true,
writable: true,
value: (() => {
var _ref3 = babelHelpers.asyncToGenerator(function* () {
console.log(_this3);
});
return function value() {
return _ref3.apply(this, arguments);
};
})()
});
}
}

View File

@@ -0,0 +1,7 @@
{
"plugins": [
"external-helpers",
"transform-async-to-generator",
["proposal-class-properties"]
]
}

View File

@@ -0,0 +1,7 @@
export class MyClass {
static property = value;
}
export default class MyClass2 {
static property = value;
}

View File

@@ -0,0 +1,21 @@
export var MyClass = function MyClass() {
babelHelpers.classCallCheck(this, MyClass);
};
Object.defineProperty(MyClass, "property", {
configurable: true,
enumerable: true,
writable: true,
value: value
});
var MyClass2 = function MyClass2() {
babelHelpers.classCallCheck(this, MyClass2);
};
Object.defineProperty(MyClass2, "property", {
configurable: true,
enumerable: true,
writable: true,
value: value
});
export { MyClass2 as default };

View File

@@ -0,0 +1,3 @@
var Foo = class {
static num = 0;
}

View File

@@ -0,0 +1,7 @@
var Foo = class {
static num = 0;
}
assert.equal(Foo.num, 0);
assert.equal(Foo.num = 1, 1);
assert.equal(Foo.name, "Foo");

View File

@@ -0,0 +1,10 @@
var _class, _temp;
var Foo = (_temp = _class = function Foo() {
babelHelpers.classCallCheck(this, Foo);
}, Object.defineProperty(_class, "num", {
configurable: true,
enumerable: true,
writable: true,
value: 0
}), _temp);

View File

@@ -0,0 +1,3 @@
class Foo {
static bar;
}

View File

@@ -0,0 +1,6 @@
class Foo {
static num;
}
assert.equal("num" in Foo, true);
assert.equal(Foo.num, undefined);

View File

@@ -0,0 +1,10 @@
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
};
Object.defineProperty(Foo, "bar", {
configurable: true,
enumerable: true,
writable: true,
value: void 0
});

View File

@@ -0,0 +1,3 @@
class Foo {
static bar = "foo";
}

View 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");

View File

@@ -0,0 +1,10 @@
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
};
Object.defineProperty(Foo, "bar", {
configurable: true,
enumerable: true,
writable: true,
value: "foo"
});

View File

@@ -0,0 +1,9 @@
class A {
foo() {
return "bar";
}
}
class B extends A {
foo = super.foo();
}

View File

@@ -0,0 +1,35 @@
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)), Object.defineProperty(_this, "foo", {
configurable: true,
enumerable: true,
writable: true,
value: babelHelpers.get(B.prototype.__proto__ || Object.getPrototypeOf(B.prototype), "foo", _this).call(_this)
}), _temp));
}
return B;
}(A);

View File

@@ -0,0 +1,7 @@
class Foo extends Bar {
bar = "foo";
constructor() {
foo(super());
}
}

View File

@@ -0,0 +1,20 @@
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
var _temp, _this;
babelHelpers.classCallCheck(this, Foo);
foo((_temp = _this = babelHelpers.possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this)), Object.defineProperty(_this, "bar", {
configurable: true,
enumerable: true,
writable: true,
value: "foo"
}), _temp));
return _this;
}
return Foo;
}(Bar);

View File

@@ -0,0 +1,7 @@
class Foo extends Bar {
bar = "foo";
constructor() {
super();
}
}

View File

@@ -0,0 +1,21 @@
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
var _this;
babelHelpers.classCallCheck(this, Foo);
_this = babelHelpers.possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this));
Object.defineProperty(_this, "bar", {
configurable: true,
enumerable: true,
writable: true,
value: "foo"
});
return _this;
}
return Foo;
}(Bar);

View File

@@ -0,0 +1,9 @@
var foo = "bar";
class Foo {
bar = foo;
constructor() {
var foo = "foo";
}
}

View File

@@ -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;
};

View File

@@ -0,0 +1,3 @@
class Foo extends Bar {
bar = "foo";
}

View File

@@ -0,0 +1,14 @@
var Foo =
/*#__PURE__*/
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, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this, ...args)), _this.bar = "foo", _temp));
}
return Foo;
}(Bar);

View File

@@ -0,0 +1,9 @@
class Child extends Parent {
constructor() {
super();
}
scopedFunctionWithThis = () => {
this.name = {};
}
}

View File

@@ -0,0 +1,20 @@
var Child =
/*#__PURE__*/
function (_Parent) {
babelHelpers.inherits(Child, _Parent);
function Child() {
var _this;
babelHelpers.classCallCheck(this, Child);
_this = babelHelpers.possibleConstructorReturn(this, (Child.__proto__ || Object.getPrototypeOf(Child)).call(this));
_this.scopedFunctionWithThis = function () {
_this.name = {};
};
return _this;
}
return Child;
}(Parent);

View File

@@ -0,0 +1,4 @@
{
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}]],
"presets": ["es2015"]
}

View File

@@ -0,0 +1,13 @@
function test(x) {
class F {
[x] = 1;
constructor() {}
}
x = 'deadbeef';
assert.strictEqual(new F().foo, 1);
x = 'wrong';
assert.strictEqual(new F().foo, 1);
}
test('foo');

View File

@@ -0,0 +1,13 @@
function test(x) {
class F {
[x] = 1;
constructor() {}
}
x = 'deadbeef';
assert.strictEqual(new F().foo, 1);
x = 'wrong';
assert.strictEqual(new F().foo, 1);
}
test('foo');

View File

@@ -0,0 +1,14 @@
function test(x) {
var F = function F() {
babelHelpers.classCallCheck(this, F);
this[_x] = 1;
};
var _x = x;
x = 'deadbeef';
assert.strictEqual(new F().foo, 1);
x = 'wrong';
assert.strictEqual(new F().foo, 1);
}
test('foo');

View File

@@ -0,0 +1,3 @@
class Foo {
bar;
}

View File

@@ -0,0 +1,4 @@
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
this.bar = void 0;
};

View File

@@ -0,0 +1,3 @@
class Foo {
bar = "foo";
}

View File

@@ -0,0 +1,4 @@
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
this.bar = "foo";
};

View File

@@ -0,0 +1,11 @@
export default param =>
class App {
static props = {
prop1: 'prop1',
prop2: 'prop2'
}
getParam() {
return param;
}
}

View File

@@ -0,0 +1,22 @@
export default (param => {
var _class, _temp;
return _temp = _class =
/*#__PURE__*/
function () {
function App() {
babelHelpers.classCallCheck(this, App);
}
babelHelpers.createClass(App, [{
key: "getParam",
value: function getParam() {
return param;
}
}]);
return App;
}(), _class.props = {
prop1: 'prop1',
prop2: 'prop2'
}, _temp;
});

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}], "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
}

View File

@@ -0,0 +1,7 @@
export class MyClass {
static property = value;
}
export default class MyClass2 {
static property = value;
}

View File

@@ -0,0 +1,11 @@
export var MyClass = function MyClass() {
babelHelpers.classCallCheck(this, MyClass);
};
MyClass.property = value;
var MyClass2 = function MyClass2() {
babelHelpers.classCallCheck(this, MyClass2);
};
MyClass2.property = value;
export { MyClass2 as default };

View File

@@ -0,0 +1,3 @@
var Foo = class {
static num = 0;
}

View File

@@ -0,0 +1,7 @@
var Foo = class {
static num = 0;
}
assert.equal(Foo.num, 0);
assert.equal(Foo.num = 1, 1);
assert.equal(Foo.name, "Foo");

View File

@@ -0,0 +1,5 @@
var _class, _temp;
var Foo = (_temp = _class = function Foo() {
babelHelpers.classCallCheck(this, Foo);
}, _class.num = 0, _temp);

View File

@@ -0,0 +1,3 @@
class Foo {
static bar;
}

View File

@@ -0,0 +1,6 @@
class Foo {
static num;
}
assert.equal("num" in Foo, true);
assert.equal(Foo.num, undefined);

View File

@@ -0,0 +1,5 @@
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
};
Foo.bar = void 0;

View File

@@ -0,0 +1,3 @@
class Foo {
static bar = "foo";
}

View 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");

View File

@@ -0,0 +1,5 @@
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
};
Foo.bar = "foo";

View File

@@ -0,0 +1,7 @@
class Foo extends Bar {
bar = "foo";
constructor() {
foo(super());
}
}

View File

@@ -0,0 +1,15 @@
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
var _temp, _this;
babelHelpers.classCallCheck(this, Foo);
foo((_temp = _this = babelHelpers.possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this)), _this.bar = "foo", _temp));
return _this;
}
return Foo;
}(Bar);

View File

@@ -0,0 +1,7 @@
class Foo extends Bar {
bar = "foo";
constructor() {
super();
}
}

View File

@@ -0,0 +1,16 @@
var Foo =
/*#__PURE__*/
function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
var _this;
babelHelpers.classCallCheck(this, Foo);
_this = babelHelpers.possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this));
_this.bar = "foo";
return _this;
}
return Foo;
}(Bar);

View File

@@ -0,0 +1,28 @@
() => {
class Foo {
fn = () => console.log(this);
static fn = () => console.log(this);
}
};
() => class Bar {
fn = () => console.log(this);
static fn = () => console.log(this);
};
() => {
class Baz {
fn = () => console.log(this);
force = force
static fn = () => console.log(this);
constructor(force) {}
}
};
var qux = function() {
class Qux {
fn = () => console.log(this);
static fn = () => console.log(this);
}
}.bind(this)

View File

@@ -0,0 +1,121 @@
var _this = this;
(function () {
class Foo {
constructor() {
var _this2 = this;
Object.defineProperty(this, "fn", {
configurable: true,
enumerable: true,
writable: true,
value: function () {
return console.log(_this2);
}
});
}
}
Object.defineProperty(Foo, "fn", {
configurable: true,
enumerable: true,
writable: true,
value: function () {
return console.log(_this);
}
});
});
(function () {
var _class, _temp;
return _temp = _class = class Bar {
constructor() {
var _this3 = this;
Object.defineProperty(this, "fn", {
configurable: true,
enumerable: true,
writable: true,
value: function () {
return console.log(_this3);
}
});
}
}, Object.defineProperty(_class, "fn", {
configurable: true,
enumerable: true,
writable: true,
value: function () {
return console.log(_this);
}
}), _temp;
});
(function () {
class Baz {
constructor(force) {
_initialiseProps.call(this);
}
}
Object.defineProperty(Baz, "fn", {
configurable: true,
enumerable: true,
writable: true,
value: function () {
return console.log(_this);
}
});
var _initialiseProps = function () {
var _this4 = this;
Object.defineProperty(this, "fn", {
configurable: true,
enumerable: true,
writable: true,
value: function () {
return console.log(_this4);
}
});
Object.defineProperty(this, "force", {
configurable: true,
enumerable: true,
writable: true,
value: force
});
};
});
var qux = function () {
var _this6 = this;
class Qux {
constructor() {
var _this5 = this;
Object.defineProperty(this, "fn", {
configurable: true,
enumerable: true,
writable: true,
value: function () {
return console.log(_this5);
}
});
}
}
Object.defineProperty(Qux, "fn", {
configurable: true,
enumerable: true,
writable: true,
value: function () {
return console.log(_this6);
}
});
}.bind(this);

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "proposal-class-properties", "transform-es2015-arrow-functions"]
}

View File

@@ -0,0 +1,8 @@
class Test {
constructor() {
class Other extends Test {
a = () => super.test;
static a = () => super.test;
}
}
}

View File

@@ -0,0 +1,55 @@
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return _get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }
var Test = function Test() {
var _this2 = this;
_classCallCheck(this, Test);
var Other =
/*#__PURE__*/
function (_Test) {
_inherits(Other, _Test);
function Other() {
var _ref;
var _temp, _this;
_classCallCheck(this, Other);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _possibleConstructorReturn(_this, (_temp = _this = _possibleConstructorReturn(this, (_ref = Other.__proto__ || Object.getPrototypeOf(Other)).call.apply(_ref, [this].concat(args))), Object.defineProperty(_this, "a", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _get(Other.prototype.__proto__ || Object.getPrototypeOf(Other.prototype), "test", _this);
}
}), _temp));
}
return Other;
}(Test);
Object.defineProperty(Other, "a", {
configurable: true,
enumerable: true,
writable: true,
value: function value() {
return _get(Test.prototype.__proto__ || Object.getPrototypeOf(Test.prototype), "test", _this2);
}
});
};

View File

@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-2"]
}

View File

@@ -0,0 +1,7 @@
call(class {
static test = true
});
export default class {
static test = true
};

View File

@@ -0,0 +1,13 @@
var _class, _temp;
call((_temp = _class = function _class() {
babelHelpers.classCallCheck(this, _class);
}, _class.test = true, _temp));
var _class2 = function _class2() {
babelHelpers.classCallCheck(this, _class2);
};
_class2.test = true;
export { _class2 as default };
;

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}], "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
}

View 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,
}
),
};
};
}

View File

@@ -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;
}

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}], "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
}

Some files were not shown because too many files have changed in this diff Show More