Rename all proposal plugins to -proposal- from -transform- (#6570)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
149
packages/babel-plugin-proposal-class-properties/README.md
Normal file
149
packages/babel-plugin-proposal-class-properties/README.md
Normal 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)
|
||||
22
packages/babel-plugin-proposal-class-properties/package.json
Normal file
22
packages/babel-plugin-proposal-class-properties/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
212
packages/babel-plugin-proposal-class-properties/src/index.js
Normal file
212
packages/babel-plugin-proposal-class-properties/src/index.js
Normal 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);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
// Output should not use `_initialiseProps`
|
||||
x: T;
|
||||
y = 0;
|
||||
constructor(T) {}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class C {
|
||||
// Output should not use `_initialiseProps`
|
||||
constructor(T) {
|
||||
this.x = void 0;
|
||||
this.y = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-typescript", ["proposal-class-properties", {"loose": true }]]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class C {
|
||||
// Output should not use `_initialiseProps`
|
||||
x: T;
|
||||
y = 0;
|
||||
constructor(T) {}
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-typescript", "proposal-class-properties"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
static fn = () => console.log(this);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
var _this = this;
|
||||
|
||||
class Foo {
|
||||
static fn = function () {
|
||||
return console.log(_this);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "transform-es2015-arrow-functions", "syntax-class-properties"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
fn = () => console.log(this);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "transform-es2015-arrow-functions", "syntax-class-properties"],
|
||||
"throws": "Unable to transform arrow inside class property"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
var foo = "bar";
|
||||
|
||||
class Foo {
|
||||
bar = foo;
|
||||
|
||||
constructor() {
|
||||
var foo = "foo";
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
};
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/general/derived/actual.js
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/general/derived/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo extends Bar {
|
||||
bar = "foo";
|
||||
}
|
||||
19
packages/babel-plugin-proposal-class-properties/test/fixtures/general/derived/expected.js
vendored
Normal file
19
packages/babel-plugin-proposal-class-properties/test/fixtures/general/derived/expected.js
vendored
Normal 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);
|
||||
9
packages/babel-plugin-proposal-class-properties/test/fixtures/general/foobar/actual.js
vendored
Normal file
9
packages/babel-plugin-proposal-class-properties/test/fixtures/general/foobar/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class Child extends Parent {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
scopedFunctionWithThis = () => {
|
||||
this.name = {};
|
||||
}
|
||||
}
|
||||
23
packages/babel-plugin-proposal-class-properties/test/fixtures/general/foobar/expected.js
vendored
Normal file
23
packages/babel-plugin-proposal-class-properties/test/fixtures/general/foobar/expected.js
vendored
Normal 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);
|
||||
4
packages/babel-plugin-proposal-class-properties/test/fixtures/general/foobar/options.json
vendored
Normal file
4
packages/babel-plugin-proposal-class-properties/test/fixtures/general/foobar/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "proposal-class-properties"],
|
||||
"presets": ["stage-0", "es2015"]
|
||||
}
|
||||
@@ -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');
|
||||
13
packages/babel-plugin-proposal-class-properties/test/fixtures/general/instance-computed/exec.js
vendored
Normal file
13
packages/babel-plugin-proposal-class-properties/test/fixtures/general/instance-computed/exec.js
vendored
Normal 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');
|
||||
@@ -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');
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
bar;
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
};
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/general/instance/actual.js
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/general/instance/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
bar = "foo";
|
||||
}
|
||||
9
packages/babel-plugin-proposal-class-properties/test/fixtures/general/instance/expected.js
vendored
Normal file
9
packages/babel-plugin-proposal-class-properties/test/fixtures/general/instance/expected.js
vendored
Normal 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"
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
export default param =>
|
||||
class App {
|
||||
static props = {
|
||||
prop1: 'prop1',
|
||||
prop2: 'prop2'
|
||||
}
|
||||
|
||||
getParam() {
|
||||
return param;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
});
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/general/options.json
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/general/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "proposal-class-properties", "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
call(class {
|
||||
static test = true
|
||||
});
|
||||
|
||||
export default class {
|
||||
static test = true
|
||||
};
|
||||
@@ -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 };
|
||||
;
|
||||
14
packages/babel-plugin-proposal-class-properties/test/fixtures/general/regression-T6719/actual.js
vendored
Normal file
14
packages/babel-plugin-proposal-class-properties/test/fixtures/general/regression-T6719/actual.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,
|
||||
}
|
||||
),
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
17
packages/babel-plugin-proposal-class-properties/test/fixtures/general/regression-T7364/actual.js
vendored
Normal file
17
packages/babel-plugin-proposal-class-properties/test/fixtures/general/regression-T7364/actual.js
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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
})()
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugins": [
|
||||
"external-helpers",
|
||||
"transform-async-to-generator",
|
||||
["proposal-class-properties"]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export class MyClass {
|
||||
static property = value;
|
||||
}
|
||||
|
||||
export default class MyClass2 {
|
||||
static property = value;
|
||||
}
|
||||
21
packages/babel-plugin-proposal-class-properties/test/fixtures/general/static-export/expected.js
vendored
Normal file
21
packages/babel-plugin-proposal-class-properties/test/fixtures/general/static-export/expected.js
vendored
Normal 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 };
|
||||
@@ -0,0 +1,3 @@
|
||||
var Foo = class {
|
||||
static num = 0;
|
||||
}
|
||||
@@ -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");
|
||||
@@ -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);
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
static bar;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
static num;
|
||||
}
|
||||
|
||||
assert.equal("num" in Foo, true);
|
||||
assert.equal(Foo.num, undefined);
|
||||
@@ -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
|
||||
});
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/general/static/actual.js
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/general/static/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
static bar = "foo";
|
||||
}
|
||||
9
packages/babel-plugin-proposal-class-properties/test/fixtures/general/static/exec.js
vendored
Normal file
9
packages/babel-plugin-proposal-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");
|
||||
10
packages/babel-plugin-proposal-class-properties/test/fixtures/general/static/expected.js
vendored
Normal file
10
packages/babel-plugin-proposal-class-properties/test/fixtures/general/static/expected.js
vendored
Normal 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"
|
||||
});
|
||||
9
packages/babel-plugin-proposal-class-properties/test/fixtures/general/super-call/actual.js
vendored
Normal file
9
packages/babel-plugin-proposal-class-properties/test/fixtures/general/super-call/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
foo() {
|
||||
return "bar";
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
foo = super.foo();
|
||||
}
|
||||
35
packages/babel-plugin-proposal-class-properties/test/fixtures/general/super-call/expected.js
vendored
Normal file
35
packages/babel-plugin-proposal-class-properties/test/fixtures/general/super-call/expected.js
vendored
Normal 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);
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo extends Bar {
|
||||
bar = "foo";
|
||||
|
||||
constructor() {
|
||||
foo(super());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo extends Bar {
|
||||
bar = "foo";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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-proposal-class-properties/test/fixtures/loose/derived/actual.js
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/derived/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo extends Bar {
|
||||
bar = "foo";
|
||||
}
|
||||
14
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/derived/expected.js
vendored
Normal file
14
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/derived/expected.js
vendored
Normal 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);
|
||||
9
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/foobar/actual.js
vendored
Normal file
9
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/foobar/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class Child extends Parent {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
scopedFunctionWithThis = () => {
|
||||
this.name = {};
|
||||
}
|
||||
}
|
||||
20
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/foobar/expected.js
vendored
Normal file
20
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/foobar/expected.js
vendored
Normal 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);
|
||||
4
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/foobar/options.json
vendored
Normal file
4
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/foobar/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}]],
|
||||
"presets": ["es2015"]
|
||||
}
|
||||
13
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/instance-computed/actual.js
vendored
Normal file
13
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/instance-computed/actual.js
vendored
Normal 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');
|
||||
13
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/instance-computed/exec.js
vendored
Normal file
13
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/instance-computed/exec.js
vendored
Normal 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');
|
||||
@@ -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');
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
bar;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
this.bar = void 0;
|
||||
};
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/instance/actual.js
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/instance/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
bar = "foo";
|
||||
}
|
||||
4
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/instance/expected.js
vendored
Normal file
4
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/instance/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
this.bar = "foo";
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
export default param =>
|
||||
class App {
|
||||
static props = {
|
||||
prop1: 'prop1',
|
||||
prop2: 'prop2'
|
||||
}
|
||||
|
||||
getParam() {
|
||||
return param;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
});
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/options.json
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}], "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
|
||||
}
|
||||
7
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static-export/actual.js
vendored
Normal file
7
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static-export/actual.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export class MyClass {
|
||||
static property = value;
|
||||
}
|
||||
|
||||
export default class MyClass2 {
|
||||
static property = value;
|
||||
}
|
||||
11
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static-export/expected.js
vendored
Normal file
11
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static-export/expected.js
vendored
Normal 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 };
|
||||
@@ -0,0 +1,3 @@
|
||||
var Foo = class {
|
||||
static num = 0;
|
||||
}
|
||||
@@ -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");
|
||||
@@ -0,0 +1,5 @@
|
||||
var _class, _temp;
|
||||
|
||||
var Foo = (_temp = _class = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
}, _class.num = 0, _temp);
|
||||
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
static bar;
|
||||
}
|
||||
6
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static-undefined/exec.js
vendored
Normal file
6
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static-undefined/exec.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
static num;
|
||||
}
|
||||
|
||||
assert.equal("num" in Foo, true);
|
||||
assert.equal(Foo.num, undefined);
|
||||
@@ -0,0 +1,5 @@
|
||||
var Foo = function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
};
|
||||
|
||||
Foo.bar = void 0;
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static/actual.js
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
static bar = "foo";
|
||||
}
|
||||
9
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/static/exec.js
vendored
Normal file
9
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/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-proposal-class-properties/test/fixtures/loose/static/expected.js
vendored
Normal file
5
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/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());
|
||||
}
|
||||
}
|
||||
15
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/super-expression/expected.js
vendored
Normal file
15
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/super-expression/expected.js
vendored
Normal 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);
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo extends Bar {
|
||||
bar = "foo";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
16
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/super-statement/expected.js
vendored
Normal file
16
packages/babel-plugin-proposal-class-properties/test/fixtures/loose/super-statement/expected.js
vendored
Normal 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);
|
||||
28
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/actual.js
vendored
Normal file
28
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/actual.js
vendored
Normal 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)
|
||||
121
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/expected.js
vendored
Normal file
121
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/expected.js
vendored
Normal 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);
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/options.json
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "proposal-class-properties", "transform-es2015-arrow-functions"]
|
||||
}
|
||||
8
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/actual.js
vendored
Normal file
8
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/actual.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
class Test {
|
||||
constructor() {
|
||||
class Other extends Test {
|
||||
a = () => super.test;
|
||||
static a = () => super.test;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/expected.js
vendored
Normal file
55
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/expected.js
vendored
Normal 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);
|
||||
}
|
||||
});
|
||||
};
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/options.json
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6154/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"presets": ["es2015", "stage-2"]
|
||||
}
|
||||
7
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/actual.js
vendored
Normal file
7
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/actual.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
call(class {
|
||||
static test = true
|
||||
});
|
||||
|
||||
export default class {
|
||||
static test = true
|
||||
};
|
||||
13
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/expected.js
vendored
Normal file
13
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/expected.js
vendored
Normal 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 };
|
||||
;
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/options.json
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers", ["proposal-class-properties", {"loose": true}], "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"]
|
||||
}
|
||||
14
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/actual.js
vendored
Normal file
14
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/actual.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,
|
||||
}
|
||||
),
|
||||
};
|
||||
};
|
||||
}
|
||||
22
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/expected.js
vendored
Normal file
22
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/expected.js
vendored
Normal 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;
|
||||
}
|
||||
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/options.json
vendored
Normal file
3
packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/options.json
vendored
Normal 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
Reference in New Issue
Block a user