Transform class static block (#12143)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Brian Ng <bng412@gmail.com>
This commit is contained in:
parent
3ccca88178
commit
f697e7995d
8
Makefile
8
Makefile
@ -220,6 +220,14 @@ prepublish:
|
|||||||
|
|
||||||
# --exclude-dependents support is added by .yarn-patches/@lerna/version
|
# --exclude-dependents support is added by .yarn-patches/@lerna/version
|
||||||
new-version:
|
new-version:
|
||||||
|
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
@echo "!!!!!! !!!!!!"
|
||||||
|
@echo "!!!!!! Enable the check in proposal-class-static-block !!!!!!"
|
||||||
|
@echo "!!!!!! !!!!!!"
|
||||||
|
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
|
@exit 1
|
||||||
git pull --rebase
|
git pull --rebase
|
||||||
$(YARN) lerna version --exclude-dependents --force-publish=$(FORCE_PUBLISH)
|
$(YARN) lerna version --exclude-dependents --force-publish=$(FORCE_PUBLISH)
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,16 @@ const pluginNameMap = {
|
|||||||
url: "https://git.io/JvpRG",
|
url: "https://git.io/JvpRG",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
classStaticBlock: {
|
||||||
|
syntax: {
|
||||||
|
name: "@babel/plugin-syntax-class-static-block",
|
||||||
|
url: "https://git.io/JTLB6",
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
name: "@babel/plugin-proposal-class-static-block",
|
||||||
|
url: "https://git.io/JTLBP",
|
||||||
|
},
|
||||||
|
},
|
||||||
decimal: {
|
decimal: {
|
||||||
syntax: {
|
syntax: {
|
||||||
name: "@babel/plugin-syntax-decimal",
|
name: "@babel/plugin-syntax-decimal",
|
||||||
|
|||||||
@ -120,6 +120,18 @@ export function createClassFeaturePlugin({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isDecorated) isDecorated = hasOwnDecorators(path.node);
|
if (!isDecorated) isDecorated = hasOwnDecorators(path.node);
|
||||||
|
|
||||||
|
if (path.isStaticBlock?.()) {
|
||||||
|
throw path.buildCodeFrameError(`Incorrect plugin order, \`@babel/plugin-proposal-class-static-block\` should be placed before class features plugins
|
||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"@babel/plugin-proposal-class-static-block",
|
||||||
|
"@babel/plugin-proposal-private-property-in-object",
|
||||||
|
"@babel/plugin-proposal-private-methods",
|
||||||
|
"@babel/plugin-proposal-class-properties",
|
||||||
|
]
|
||||||
|
}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!props.length && !isDecorated) return;
|
if (!props.length && !isDecorated) return;
|
||||||
@ -188,7 +200,12 @@ export function createClassFeaturePlugin({
|
|||||||
},
|
},
|
||||||
|
|
||||||
PrivateName(path) {
|
PrivateName(path) {
|
||||||
if (this.file.get(versionKey) !== version) return;
|
if (
|
||||||
|
this.file.get(versionKey) !== version ||
|
||||||
|
path.parentPath.isPrivate({ key: path.node })
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
throw path.buildCodeFrameError(`Unknown PrivateName "${path}"`);
|
throw path.buildCodeFrameError(`Unknown PrivateName "${path}"`);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
"@babel/helper-split-export-declaration": "workspace:^7.11.0",
|
"@babel/helper-split-export-declaration": "workspace:^7.11.0",
|
||||||
"@babel/helper-validator-identifier": "workspace:^7.10.4",
|
"@babel/helper-validator-identifier": "workspace:^7.10.4",
|
||||||
"@babel/template": "workspace:^7.10.4",
|
"@babel/template": "workspace:^7.10.4",
|
||||||
|
"@babel/traverse": "workspace:^7.11.5",
|
||||||
"@babel/types": "workspace:^7.11.0",
|
"@babel/types": "workspace:^7.11.0",
|
||||||
"lodash": "^4.17.19"
|
"lodash": "^4.17.19"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,21 @@
|
|||||||
import { skipAllButComputedKey } from "@babel/helper-replace-supers";
|
import { environmentVisitor } from "@babel/helper-replace-supers";
|
||||||
|
import traverse from "@babel/traverse";
|
||||||
|
import * as t from "@babel/types";
|
||||||
|
|
||||||
export default function rewriteThis(programPath: NodePath) {
|
export default function rewriteThis(programPath: NodePath) {
|
||||||
// Rewrite "this" to be "undefined".
|
// Rewrite "this" to be "undefined".
|
||||||
programPath.traverse(rewriteThisVisitor);
|
traverse(programPath.node, { ...rewriteThisVisitor, noScope: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A visitor to walk the tree, rewriting all `this` references in the top-level scope to be
|
* A visitor to walk the tree, rewriting all `this` references in the top-level scope to be
|
||||||
* `undefined`.
|
* `void 0` (undefined).
|
||||||
*/
|
*/
|
||||||
const rewriteThisVisitor = {
|
const rewriteThisVisitor = traverse.visitors.merge([
|
||||||
|
environmentVisitor,
|
||||||
|
{
|
||||||
ThisExpression(path) {
|
ThisExpression(path) {
|
||||||
path.replaceWith(path.scope.buildUndefinedNode());
|
path.replaceWith(t.unaryExpression("void", t.numericLiteral(0), true));
|
||||||
},
|
},
|
||||||
Function(path) {
|
|
||||||
if (path.isMethod()) skipAllButComputedKey(path);
|
|
||||||
else if (!path.isArrowFunctionExpression()) path.skip();
|
|
||||||
},
|
},
|
||||||
ClassProperty(path) {
|
]);
|
||||||
skipAllButComputedKey(path);
|
|
||||||
},
|
|
||||||
ClassPrivateProperty(path) {
|
|
||||||
path.skip();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@ -42,8 +42,13 @@ export function skipAllButComputedKey(path: NodePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// environmentVisitor should be used when traversing the whole class and not for specific class elements/methods.
|
// environmentVisitor should be used when traversing the whole class and not for specific class elements/methods.
|
||||||
|
// For perf reasons, the environmentVisitor will be traversed with `{ noScope: true }`, which means `path.scope` is undefined.
|
||||||
|
// Avoid using `path.scope` here
|
||||||
export const environmentVisitor = {
|
export const environmentVisitor = {
|
||||||
TypeAnnotation(path: NodePath) {
|
// todo (Babel 8): remove StaticBlock brand checks
|
||||||
|
[`${t.StaticBlock ? "StaticBlock|" : ""}ClassPrivateProperty|TypeAnnotation`](
|
||||||
|
path: NodePath,
|
||||||
|
) {
|
||||||
path.skip();
|
path.skip();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -55,7 +60,7 @@ export const environmentVisitor = {
|
|||||||
path.skip();
|
path.skip();
|
||||||
},
|
},
|
||||||
|
|
||||||
"Method|ClassProperty|ClassPrivateProperty"(path: NodePath) {
|
"Method|ClassProperty"(path: NodePath) {
|
||||||
skipAllButComputedKey(path);
|
skipAllButComputedKey(path);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
src
|
||||||
|
test
|
||||||
|
*.log
|
||||||
19
packages/babel-plugin-proposal-class-static-block/README.md
Normal file
19
packages/babel-plugin-proposal-class-static-block/README.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# @babel/plugin-proposal-class-static-block
|
||||||
|
|
||||||
|
> Allow transforming of class static blocks
|
||||||
|
|
||||||
|
See our website [@babel/plugin-proposal-class-static-block](https://babeljs.io/docs/en/next/babel-plugin-proposal-class-static-block.html) for more information.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Using npm:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save-dev @babel/plugin-proposal-class-static-block
|
||||||
|
```
|
||||||
|
|
||||||
|
or using yarn:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn add @babel/plugin-proposal-class-static-block --dev
|
||||||
|
```
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"name": "@babel/plugin-proposal-class-static-block",
|
||||||
|
"version": "7.11.0",
|
||||||
|
"description": "Allow parsing of class static blocks",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/babel/babel.git",
|
||||||
|
"directory": "packages/babel-plugin-proposal-class-static-block"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"main": "./lib/index.js",
|
||||||
|
"exports": {
|
||||||
|
".": "./lib/index.js"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"babel-plugin"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/helper-plugin-utils": "workspace:^7.10.1",
|
||||||
|
"@babel/plugin-syntax-class-static-block": "workspace:^7.11.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@babel/core": "^7.12.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "workspace:^7.11.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
import { declare } from "@babel/helper-plugin-utils";
|
||||||
|
import syntaxClassStaticBlock from "@babel/plugin-syntax-class-static-block";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a uid that is not in `denyList`
|
||||||
|
*
|
||||||
|
* @param {*} scope
|
||||||
|
* @param {Set<string>} a deny list that the generated uid should avoid
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function generateUid(scope, denyList: Set<string>) {
|
||||||
|
const name = "";
|
||||||
|
let uid;
|
||||||
|
let i = 1;
|
||||||
|
do {
|
||||||
|
uid = scope._generateUid(name, i);
|
||||||
|
i++;
|
||||||
|
} while (denyList.has(uid));
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default declare(({ types: t, template, assertVersion }) => {
|
||||||
|
// todo: change to ^7.12.0 when it is published
|
||||||
|
assertVersion("^7.11.6");
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: "proposal-class-static-block",
|
||||||
|
inherits: syntaxClassStaticBlock,
|
||||||
|
visitor: {
|
||||||
|
Class(path: NodePath<Class>) {
|
||||||
|
const { scope } = path;
|
||||||
|
const classBody = path.get("body");
|
||||||
|
const privateNames = new Set();
|
||||||
|
let staticBlockPath;
|
||||||
|
for (const path of classBody.get("body")) {
|
||||||
|
if (path.isPrivate()) {
|
||||||
|
privateNames.add(path.get("key.id").node.name);
|
||||||
|
} else if (path.isStaticBlock()) {
|
||||||
|
staticBlockPath = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!staticBlockPath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const staticBlockRef = t.privateName(
|
||||||
|
t.identifier(generateUid(scope, privateNames)),
|
||||||
|
);
|
||||||
|
classBody.pushContainer(
|
||||||
|
"body",
|
||||||
|
t.classPrivateProperty(
|
||||||
|
staticBlockRef,
|
||||||
|
template.expression.ast`(() => { ${staticBlockPath.node.body} })()`,
|
||||||
|
[],
|
||||||
|
/* static */ true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
staticBlockPath.remove();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = Foo.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static bar = 42;
|
||||||
|
static #_ = (() => {
|
||||||
|
this.foo = this.bar;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
class Foo extends class extends class Base {
|
||||||
|
static {
|
||||||
|
this.qux = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.bar = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar + this.qux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
class Foo extends class extends class Base {
|
||||||
|
static {
|
||||||
|
this.qux = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.bar = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar + this.qux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
class Foo extends class extends class Base {
|
||||||
|
static #_ = (() => {
|
||||||
|
this.qux = 21;
|
||||||
|
})();
|
||||||
|
} {
|
||||||
|
static #_ = (() => {
|
||||||
|
this.bar = 21;
|
||||||
|
})();
|
||||||
|
} {
|
||||||
|
static #_ = (() => {
|
||||||
|
this.foo = this.bar + this.qux;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = this.#bar + this.qux;
|
||||||
|
}
|
||||||
|
static qux = 21;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #_ = 42;
|
||||||
|
// static block can not be tranformed as `#_` here
|
||||||
|
static {
|
||||||
|
this.foo = this.#_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #_ = 42;
|
||||||
|
// static block can not be tranformed as `#_` here
|
||||||
|
static {
|
||||||
|
this.foo = this.#_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class Foo {
|
||||||
|
static #_ = 42; // static block can not be tranformed as `#_` here
|
||||||
|
|
||||||
|
static #_2 = (() => {
|
||||||
|
this.foo = this.#_;
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(undefined);
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["proposal-class-static-block", "syntax-class-properties"],
|
||||||
|
"minNodeVersion": "12.0.0"
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
let getFoo;
|
||||||
|
class Foo {
|
||||||
|
static #foo = 42;
|
||||||
|
static {
|
||||||
|
getFoo = () => this.#foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(getFoo()).toBe(42);
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class Foo extends class {
|
||||||
|
static bar = 42;
|
||||||
|
} {
|
||||||
|
static bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = super.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
class Foo extends class {
|
||||||
|
static {
|
||||||
|
this.bar = 42;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = super.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = Foo.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = Foo.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
var _ = babelHelpers.classPrivateFieldLooseKey("_");
|
||||||
|
|
||||||
|
class Foo {}
|
||||||
|
|
||||||
|
Foo.bar = 42;
|
||||||
|
Object.defineProperty(Foo, _, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
Foo.foo = Foo.bar;
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
var _ = babelHelpers.classPrivateFieldLooseKey("_");
|
||||||
|
|
||||||
|
class Foo {}
|
||||||
|
|
||||||
|
Foo.bar = 42;
|
||||||
|
Object.defineProperty(Foo, _, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
Foo.foo = Foo.bar;
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
class Foo extends class extends class Base {
|
||||||
|
static {
|
||||||
|
this.qux = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.bar = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar + this.qux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
class Foo extends class extends class Base {
|
||||||
|
static {
|
||||||
|
this.qux = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.bar = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar + this.qux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
var _class, _2, _temp, _class2, _3, _temp2;
|
||||||
|
|
||||||
|
var _ = babelHelpers.classPrivateFieldLooseKey("_");
|
||||||
|
|
||||||
|
class Foo extends (_temp = (_2 = babelHelpers.classPrivateFieldLooseKey("_"), _class = class extends (_temp2 = (_3 = babelHelpers.classPrivateFieldLooseKey("_"), _class2 = class Base {}), Object.defineProperty(_class2, _3, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
_class2.qux = 21;
|
||||||
|
})()
|
||||||
|
}), _temp2) {}), Object.defineProperty(_class, _2, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
_class.bar = 21;
|
||||||
|
})()
|
||||||
|
}), _temp) {}
|
||||||
|
|
||||||
|
Object.defineProperty(Foo, _, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
Foo.foo = Foo.bar + Foo.qux;
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = this.#bar + this.qux;
|
||||||
|
}
|
||||||
|
static qux = 21;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #_ = 42;
|
||||||
|
// static block can not be tranformed as `#_` here
|
||||||
|
static {
|
||||||
|
this.foo = this.#_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #_ = 42;
|
||||||
|
// static block can not be tranformed as `#_` here
|
||||||
|
static {
|
||||||
|
this.foo = this.#_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
var _ = babelHelpers.classPrivateFieldLooseKey("_");
|
||||||
|
|
||||||
|
var _2 = babelHelpers.classPrivateFieldLooseKey("_2");
|
||||||
|
|
||||||
|
class Foo {}
|
||||||
|
|
||||||
|
Object.defineProperty(Foo, _, {
|
||||||
|
writable: true,
|
||||||
|
value: 42
|
||||||
|
});
|
||||||
|
Object.defineProperty(Foo, _2, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
Foo.foo = babelHelpers.classPrivateFieldLooseBase(Foo, _)[_];
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(undefined);
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"proposal-class-static-block",
|
||||||
|
["proposal-private-property-in-object", { "loose": true }],
|
||||||
|
["proposal-private-methods", { "loose": true }],
|
||||||
|
["proposal-class-properties", { "loose": true }],
|
||||||
|
"external-helpers"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
let getFoo;
|
||||||
|
class Foo {
|
||||||
|
static #foo = 42;
|
||||||
|
static {
|
||||||
|
getFoo = () => this.#foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(getFoo()).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static #bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = #bar in this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(true);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
let getFoo;
|
||||||
|
class Foo {
|
||||||
|
static #foo() { return 42 };
|
||||||
|
static {
|
||||||
|
getFoo = () => this.#foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(getFoo()).toBe(42);
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class Foo extends class {
|
||||||
|
static bar = 42;
|
||||||
|
} {
|
||||||
|
static bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = super.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
class Foo extends class {
|
||||||
|
static {
|
||||||
|
this.bar = 42;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = super.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
class Foo extends class {
|
||||||
|
static {
|
||||||
|
this.bar = 42;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = super.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
var _class, _2, _temp;
|
||||||
|
|
||||||
|
var _ = babelHelpers.classPrivateFieldLooseKey("_");
|
||||||
|
|
||||||
|
class Foo extends (_temp = (_2 = babelHelpers.classPrivateFieldLooseKey("_"), _class = class {}), Object.defineProperty(_class, _2, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
_class.bar = 42;
|
||||||
|
})()
|
||||||
|
}), _temp) {}
|
||||||
|
|
||||||
|
Foo.bar = 21;
|
||||||
|
Object.defineProperty(Foo, _, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
var _class2, _3, _temp2;
|
||||||
|
|
||||||
|
Foo.foo = (_temp2 = (_3 = babelHelpers.classPrivateFieldLooseKey("_"), _class2 = class {}), Object.defineProperty(_class2, _3, {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
_class2.bar = 42;
|
||||||
|
})()
|
||||||
|
}), _temp2).bar;
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = Foo.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = Foo.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
class Foo {}
|
||||||
|
|
||||||
|
babelHelpers.defineProperty(Foo, "bar", 42);
|
||||||
|
var _ = {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
Foo.foo = Foo.bar;
|
||||||
|
})()
|
||||||
|
};
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
class Foo {}
|
||||||
|
|
||||||
|
babelHelpers.defineProperty(Foo, "bar", 42);
|
||||||
|
var _ = {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
Foo.foo = Foo.bar;
|
||||||
|
})()
|
||||||
|
};
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
class Foo extends class extends class Base {
|
||||||
|
static {
|
||||||
|
this.qux = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.bar = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar + this.qux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
class Foo extends class extends class Base {
|
||||||
|
static {
|
||||||
|
this.qux = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.bar = 21;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static {
|
||||||
|
this.foo = this.bar + this.qux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
var _class, _temp, _2, _class2, _temp2, _3;
|
||||||
|
|
||||||
|
class Foo extends (_temp = _class = class extends (_temp2 = _class2 = class Base {}, _3 = {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
_class2.qux = 21;
|
||||||
|
})()
|
||||||
|
}, _temp2) {}, _2 = {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
_class.bar = 21;
|
||||||
|
})()
|
||||||
|
}, _temp) {}
|
||||||
|
|
||||||
|
var _ = {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
Foo.foo = Foo.bar + Foo.qux;
|
||||||
|
})()
|
||||||
|
};
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = this.#bar + this.qux;
|
||||||
|
}
|
||||||
|
static qux = 21;
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #_ = 42;
|
||||||
|
// static block can not be tranformed as `#_` here
|
||||||
|
static {
|
||||||
|
this.foo = this.#_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class Foo {
|
||||||
|
static #_ = 42;
|
||||||
|
// static block can not be tranformed as `#_` here
|
||||||
|
static {
|
||||||
|
this.foo = this.#_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
||||||
|
|
||||||
|
class Foo {}
|
||||||
|
|
||||||
|
var _ = {
|
||||||
|
writable: true,
|
||||||
|
value: 42
|
||||||
|
};
|
||||||
|
var _2 = {
|
||||||
|
writable: true,
|
||||||
|
value: (() => {
|
||||||
|
Foo.foo = _classStaticPrivateFieldSpecGet(Foo, Foo, _);
|
||||||
|
})()
|
||||||
|
};
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = this.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(undefined);
|
||||||
9
packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/options.json
vendored
Normal file
9
packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/options.json
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"proposal-class-static-block",
|
||||||
|
"proposal-private-property-in-object",
|
||||||
|
"proposal-private-methods",
|
||||||
|
"proposal-class-properties",
|
||||||
|
"external-helpers"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
let getFoo;
|
||||||
|
class Foo {
|
||||||
|
static #foo = 42;
|
||||||
|
static {
|
||||||
|
getFoo = () => this.#foo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(getFoo()).toBe(42);
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
class Foo {
|
||||||
|
static #bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = #bar in this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(true);
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
let getFoo;
|
||||||
|
class Foo {
|
||||||
|
static #foo() { return 42 };
|
||||||
|
static {
|
||||||
|
getFoo = () => this.#foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(getFoo()).toBe(42);
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class Foo extends class {
|
||||||
|
static bar = 42;
|
||||||
|
} {
|
||||||
|
static bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = super.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
class Foo extends class {
|
||||||
|
static {
|
||||||
|
this.bar = 42;
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
static bar = 21;
|
||||||
|
static {
|
||||||
|
this.foo = super.bar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Foo.foo).toBe(42);
|
||||||
3
packages/babel-plugin-proposal-class-static-block/test/fixtures/options.json
vendored
Normal file
3
packages/babel-plugin-proposal-class-static-block/test/fixtures/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["proposal-class-static-block"]
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
|
runner(__dirname);
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
import * as babel from "@babel/core";
|
||||||
|
import proposalClassStaticBlock from "../lib/index.js";
|
||||||
|
|
||||||
|
describe("plugin ordering", () => {
|
||||||
|
it("should throw when @babel/plugin-proposal-class-static-block is after class features plugin", () => {
|
||||||
|
const source = `class Foo {
|
||||||
|
static {
|
||||||
|
this.foo = Foo.bar;
|
||||||
|
}
|
||||||
|
static bar = 42;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
expect(() => {
|
||||||
|
babel.transform(source, {
|
||||||
|
filename: "example.js",
|
||||||
|
highlightCode: false,
|
||||||
|
configFile: false,
|
||||||
|
babelrc: false,
|
||||||
|
plugins: [
|
||||||
|
"@babel/plugin-proposal-class-properties",
|
||||||
|
proposalClassStaticBlock,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.toThrow(`Incorrect plugin order, \`@babel/plugin-proposal-class-static-block\` should be placed before class features plugins
|
||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"@babel/plugin-proposal-class-static-block",
|
||||||
|
"@babel/plugin-proposal-private-property-in-object",
|
||||||
|
"@babel/plugin-proposal-private-methods",
|
||||||
|
"@babel/plugin-proposal-class-properties",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
1 | class Foo {
|
||||||
|
> 2 | static {
|
||||||
|
| ^
|
||||||
|
3 | this.foo = Foo.bar;
|
||||||
|
4 | }
|
||||||
|
5 | static bar = 42;`);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
class foo {
|
||||||
|
static {
|
||||||
|
this // should not be replaced by undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-modules-commonjs", "syntax-class-static-block"]
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
class foo {
|
||||||
|
static {
|
||||||
|
this; // should not be replaced by undefined
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,6 +13,7 @@
|
|||||||
"@babel/plugin-external-helpers": "workspace:^7.10.4",
|
"@babel/plugin-external-helpers": "workspace:^7.10.4",
|
||||||
"@babel/plugin-proposal-async-generator-functions": "workspace:^7.10.5",
|
"@babel/plugin-proposal-async-generator-functions": "workspace:^7.10.5",
|
||||||
"@babel/plugin-proposal-class-properties": "workspace:^7.10.4",
|
"@babel/plugin-proposal-class-properties": "workspace:^7.10.4",
|
||||||
|
"@babel/plugin-proposal-class-static-block": "workspace:^7.11.0",
|
||||||
"@babel/plugin-proposal-decorators": "workspace:^7.10.5",
|
"@babel/plugin-proposal-decorators": "workspace:^7.10.5",
|
||||||
"@babel/plugin-proposal-do-expressions": "workspace:^7.10.4",
|
"@babel/plugin-proposal-do-expressions": "workspace:^7.10.4",
|
||||||
"@babel/plugin-proposal-dynamic-import": "workspace:^7.10.4",
|
"@babel/plugin-proposal-dynamic-import": "workspace:^7.10.4",
|
||||||
@ -34,6 +35,7 @@
|
|||||||
"@babel/plugin-proposal-unicode-property-regex": "workspace:^7.10.4",
|
"@babel/plugin-proposal-unicode-property-regex": "workspace:^7.10.4",
|
||||||
"@babel/plugin-syntax-async-generators": "^7.8.0",
|
"@babel/plugin-syntax-async-generators": "^7.8.0",
|
||||||
"@babel/plugin-syntax-class-properties": "workspace:^7.10.4",
|
"@babel/plugin-syntax-class-properties": "workspace:^7.10.4",
|
||||||
|
"@babel/plugin-syntax-class-static-block": "workspace:^7.11.0",
|
||||||
"@babel/plugin-syntax-decimal": "workspace:^7.11.0",
|
"@babel/plugin-syntax-decimal": "workspace:^7.11.0",
|
||||||
"@babel/plugin-syntax-decorators": "workspace:^7.10.4",
|
"@babel/plugin-syntax-decorators": "workspace:^7.10.4",
|
||||||
"@babel/plugin-syntax-do-expressions": "workspace:^7.10.4",
|
"@babel/plugin-syntax-do-expressions": "workspace:^7.10.4",
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
"external-helpers",
|
"external-helpers",
|
||||||
"syntax-async-generators",
|
"syntax-async-generators",
|
||||||
"syntax-class-properties",
|
"syntax-class-properties",
|
||||||
|
"syntax-class-static-block",
|
||||||
"syntax-decimal",
|
"syntax-decimal",
|
||||||
"syntax-decorators",
|
"syntax-decorators",
|
||||||
"syntax-do-expressions",
|
"syntax-do-expressions",
|
||||||
@ -20,6 +21,7 @@
|
|||||||
"syntax-typescript",
|
"syntax-typescript",
|
||||||
"proposal-async-generator-functions",
|
"proposal-async-generator-functions",
|
||||||
"proposal-class-properties",
|
"proposal-class-properties",
|
||||||
|
"proposal-class-static-block",
|
||||||
"proposal-decorators",
|
"proposal-decorators",
|
||||||
"proposal-do-expressions",
|
"proposal-do-expressions",
|
||||||
"proposal-dynamic-import",
|
"proposal-dynamic-import",
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
import externalHelpers from "@babel/plugin-external-helpers";
|
import externalHelpers from "@babel/plugin-external-helpers";
|
||||||
import syntaxAsyncGenerators from "@babel/plugin-syntax-async-generators";
|
import syntaxAsyncGenerators from "@babel/plugin-syntax-async-generators";
|
||||||
import syntaxClassProperties from "@babel/plugin-syntax-class-properties";
|
import syntaxClassProperties from "@babel/plugin-syntax-class-properties";
|
||||||
|
import syntaxClassStaticBlock from "@babel/plugin-syntax-class-static-block";
|
||||||
import syntaxDecimal from "@babel/plugin-syntax-decimal";
|
import syntaxDecimal from "@babel/plugin-syntax-decimal";
|
||||||
import syntaxDecorators from "@babel/plugin-syntax-decorators";
|
import syntaxDecorators from "@babel/plugin-syntax-decorators";
|
||||||
import syntaxDoExpressions from "@babel/plugin-syntax-do-expressions";
|
import syntaxDoExpressions from "@babel/plugin-syntax-do-expressions";
|
||||||
@ -23,6 +24,7 @@ import syntaxTopLevelAwait from "@babel/plugin-syntax-top-level-await";
|
|||||||
import syntaxTypescript from "@babel/plugin-syntax-typescript";
|
import syntaxTypescript from "@babel/plugin-syntax-typescript";
|
||||||
import proposalAsyncGeneratorFunctions from "@babel/plugin-proposal-async-generator-functions";
|
import proposalAsyncGeneratorFunctions from "@babel/plugin-proposal-async-generator-functions";
|
||||||
import proposalClassProperties from "@babel/plugin-proposal-class-properties";
|
import proposalClassProperties from "@babel/plugin-proposal-class-properties";
|
||||||
|
import proposalClassStaticBlock from "@babel/plugin-proposal-class-static-block";
|
||||||
import proposalDecorators from "@babel/plugin-proposal-decorators";
|
import proposalDecorators from "@babel/plugin-proposal-decorators";
|
||||||
import proposalDoExpressions from "@babel/plugin-proposal-do-expressions";
|
import proposalDoExpressions from "@babel/plugin-proposal-do-expressions";
|
||||||
import proposalDynamicImport from "@babel/plugin-proposal-dynamic-import";
|
import proposalDynamicImport from "@babel/plugin-proposal-dynamic-import";
|
||||||
@ -98,6 +100,7 @@ export {
|
|||||||
externalHelpers,
|
externalHelpers,
|
||||||
syntaxAsyncGenerators,
|
syntaxAsyncGenerators,
|
||||||
syntaxClassProperties,
|
syntaxClassProperties,
|
||||||
|
syntaxClassStaticBlock,
|
||||||
syntaxDecimal,
|
syntaxDecimal,
|
||||||
syntaxDecorators,
|
syntaxDecorators,
|
||||||
syntaxDoExpressions,
|
syntaxDoExpressions,
|
||||||
@ -116,6 +119,7 @@ export {
|
|||||||
syntaxTypescript,
|
syntaxTypescript,
|
||||||
proposalAsyncGeneratorFunctions,
|
proposalAsyncGeneratorFunctions,
|
||||||
proposalClassProperties,
|
proposalClassProperties,
|
||||||
|
proposalClassStaticBlock,
|
||||||
proposalDecorators,
|
proposalDecorators,
|
||||||
proposalDoExpressions,
|
proposalDoExpressions,
|
||||||
proposalDynamicImport,
|
proposalDynamicImport,
|
||||||
@ -192,6 +196,7 @@ export const all = {
|
|||||||
"external-helpers": externalHelpers,
|
"external-helpers": externalHelpers,
|
||||||
"syntax-async-generators": syntaxAsyncGenerators,
|
"syntax-async-generators": syntaxAsyncGenerators,
|
||||||
"syntax-class-properties": syntaxClassProperties,
|
"syntax-class-properties": syntaxClassProperties,
|
||||||
|
"syntax-class-static-block": syntaxClassStaticBlock,
|
||||||
"syntax-decimal": syntaxDecimal,
|
"syntax-decimal": syntaxDecimal,
|
||||||
"syntax-decorators": syntaxDecorators,
|
"syntax-decorators": syntaxDecorators,
|
||||||
"syntax-do-expressions": syntaxDoExpressions,
|
"syntax-do-expressions": syntaxDoExpressions,
|
||||||
@ -210,6 +215,7 @@ export const all = {
|
|||||||
"syntax-typescript": syntaxTypescript,
|
"syntax-typescript": syntaxTypescript,
|
||||||
"proposal-async-generator-functions": proposalAsyncGeneratorFunctions,
|
"proposal-async-generator-functions": proposalAsyncGeneratorFunctions,
|
||||||
"proposal-class-properties": proposalClassProperties,
|
"proposal-class-properties": proposalClassProperties,
|
||||||
|
"proposal-class-static-block": proposalClassStaticBlock,
|
||||||
"proposal-decorators": proposalDecorators,
|
"proposal-decorators": proposalDecorators,
|
||||||
"proposal-do-expressions": proposalDoExpressions,
|
"proposal-do-expressions": proposalDoExpressions,
|
||||||
"proposal-dynamic-import": proposalDynamicImport,
|
"proposal-dynamic-import": proposalDynamicImport,
|
||||||
|
|||||||
@ -29,7 +29,6 @@ export default (_: any, opts: Object = {}) => {
|
|||||||
[babelPlugins.syntaxRecordAndTuple, { syntaxType: recordAndTupleSyntax }],
|
[babelPlugins.syntaxRecordAndTuple, { syntaxType: recordAndTupleSyntax }],
|
||||||
babelPlugins.proposalExportDefaultFrom,
|
babelPlugins.proposalExportDefaultFrom,
|
||||||
[babelPlugins.proposalPipelineOperator, { proposal: pipelineProposal }],
|
[babelPlugins.proposalPipelineOperator, { proposal: pipelineProposal }],
|
||||||
babelPlugins.proposalPrivatePropertyInObject,
|
|
||||||
babelPlugins.proposalDoExpressions,
|
babelPlugins.proposalDoExpressions,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,11 +13,13 @@ export default (_: any, opts: Object = {}) => {
|
|||||||
return {
|
return {
|
||||||
presets: [[presetStage3, { loose, useBuiltIns }]],
|
presets: [[presetStage3, { loose, useBuiltIns }]],
|
||||||
plugins: [
|
plugins: [
|
||||||
|
babelPlugins.proposalClassStaticBlock,
|
||||||
[
|
[
|
||||||
babelPlugins.proposalDecorators,
|
babelPlugins.proposalDecorators,
|
||||||
{ legacy: decoratorsLegacy, decoratorsBeforeExport },
|
{ legacy: decoratorsLegacy, decoratorsBeforeExport },
|
||||||
],
|
],
|
||||||
babelPlugins.proposalFunctionSent,
|
babelPlugins.proposalFunctionSent,
|
||||||
|
babelPlugins.proposalPrivatePropertyInObject,
|
||||||
babelPlugins.proposalThrowExpressions,
|
babelPlugins.proposalThrowExpressions,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -367,7 +367,7 @@ export default class Scope {
|
|||||||
.replace(/[0-9]+$/g, "");
|
.replace(/[0-9]+$/g, "");
|
||||||
|
|
||||||
let uid;
|
let uid;
|
||||||
let i = 0;
|
let i = 1;
|
||||||
do {
|
do {
|
||||||
uid = this._generateUid(name, i);
|
uid = this._generateUid(name, i);
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@ -108,7 +108,7 @@ defineType("PipelinePrimaryTopicReference", {
|
|||||||
|
|
||||||
defineType("ClassPrivateProperty", {
|
defineType("ClassPrivateProperty", {
|
||||||
visitor: ["key", "value", "decorators"],
|
visitor: ["key", "value", "decorators"],
|
||||||
builder: ["key", "value", "decorators"],
|
builder: ["key", "value", "decorators", "static"],
|
||||||
aliases: ["Property", "Private"],
|
aliases: ["Property", "Private"],
|
||||||
fields: {
|
fields: {
|
||||||
key: {
|
key: {
|
||||||
|
|||||||
17
yarn.lock
17
yarn.lock
@ -595,6 +595,7 @@ __metadata:
|
|||||||
"@babel/helper-split-export-declaration": "workspace:^7.11.0"
|
"@babel/helper-split-export-declaration": "workspace:^7.11.0"
|
||||||
"@babel/helper-validator-identifier": "workspace:^7.10.4"
|
"@babel/helper-validator-identifier": "workspace:^7.10.4"
|
||||||
"@babel/template": "workspace:^7.10.4"
|
"@babel/template": "workspace:^7.10.4"
|
||||||
|
"@babel/traverse": "workspace:^7.11.5"
|
||||||
"@babel/types": "workspace:^7.11.0"
|
"@babel/types": "workspace:^7.11.0"
|
||||||
lodash: ^4.17.19
|
lodash: ^4.17.19
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
@ -998,6 +999,18 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
"@babel/plugin-proposal-class-static-block@workspace:^7.11.0, @babel/plugin-proposal-class-static-block@workspace:packages/babel-plugin-proposal-class-static-block":
|
||||||
|
version: 0.0.0-use.local
|
||||||
|
resolution: "@babel/plugin-proposal-class-static-block@workspace:packages/babel-plugin-proposal-class-static-block"
|
||||||
|
dependencies:
|
||||||
|
"@babel/core": "workspace:^7.11.6"
|
||||||
|
"@babel/helper-plugin-utils": "workspace:^7.10.1"
|
||||||
|
"@babel/plugin-syntax-class-static-block": "workspace:^7.11.0"
|
||||||
|
peerDependencies:
|
||||||
|
"@babel/core": ^7.12.0
|
||||||
|
languageName: unknown
|
||||||
|
linkType: soft
|
||||||
|
|
||||||
"@babel/plugin-proposal-decorators@workspace:^7.10.4, @babel/plugin-proposal-decorators@workspace:^7.10.5, @babel/plugin-proposal-decorators@workspace:packages/babel-plugin-proposal-decorators":
|
"@babel/plugin-proposal-decorators@workspace:^7.10.4, @babel/plugin-proposal-decorators@workspace:^7.10.5, @babel/plugin-proposal-decorators@workspace:packages/babel-plugin-proposal-decorators":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@babel/plugin-proposal-decorators@workspace:packages/babel-plugin-proposal-decorators"
|
resolution: "@babel/plugin-proposal-decorators@workspace:packages/babel-plugin-proposal-decorators"
|
||||||
@ -1432,7 +1445,7 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@babel/plugin-syntax-class-static-block@workspace:packages/babel-plugin-syntax-class-static-block":
|
"@babel/plugin-syntax-class-static-block@workspace:^7.11.0, @babel/plugin-syntax-class-static-block@workspace:packages/babel-plugin-syntax-class-static-block":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@babel/plugin-syntax-class-static-block@workspace:packages/babel-plugin-syntax-class-static-block"
|
resolution: "@babel/plugin-syntax-class-static-block@workspace:packages/babel-plugin-syntax-class-static-block"
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -3176,6 +3189,7 @@ __metadata:
|
|||||||
"@babel/plugin-external-helpers": "workspace:^7.10.4"
|
"@babel/plugin-external-helpers": "workspace:^7.10.4"
|
||||||
"@babel/plugin-proposal-async-generator-functions": "workspace:^7.10.5"
|
"@babel/plugin-proposal-async-generator-functions": "workspace:^7.10.5"
|
||||||
"@babel/plugin-proposal-class-properties": "workspace:^7.10.4"
|
"@babel/plugin-proposal-class-properties": "workspace:^7.10.4"
|
||||||
|
"@babel/plugin-proposal-class-static-block": "workspace:^7.11.0"
|
||||||
"@babel/plugin-proposal-decorators": "workspace:^7.10.5"
|
"@babel/plugin-proposal-decorators": "workspace:^7.10.5"
|
||||||
"@babel/plugin-proposal-do-expressions": "workspace:^7.10.4"
|
"@babel/plugin-proposal-do-expressions": "workspace:^7.10.4"
|
||||||
"@babel/plugin-proposal-dynamic-import": "workspace:^7.10.4"
|
"@babel/plugin-proposal-dynamic-import": "workspace:^7.10.4"
|
||||||
@ -3197,6 +3211,7 @@ __metadata:
|
|||||||
"@babel/plugin-proposal-unicode-property-regex": "workspace:^7.10.4"
|
"@babel/plugin-proposal-unicode-property-regex": "workspace:^7.10.4"
|
||||||
"@babel/plugin-syntax-async-generators": ^7.8.0
|
"@babel/plugin-syntax-async-generators": ^7.8.0
|
||||||
"@babel/plugin-syntax-class-properties": "workspace:^7.10.4"
|
"@babel/plugin-syntax-class-properties": "workspace:^7.10.4"
|
||||||
|
"@babel/plugin-syntax-class-static-block": "workspace:^7.11.0"
|
||||||
"@babel/plugin-syntax-decimal": "workspace:^7.11.0"
|
"@babel/plugin-syntax-decimal": "workspace:^7.11.0"
|
||||||
"@babel/plugin-syntax-decorators": "workspace:^7.10.4"
|
"@babel/plugin-syntax-decorators": "workspace:^7.10.4"
|
||||||
"@babel/plugin-syntax-do-expressions": "workspace:^7.10.4"
|
"@babel/plugin-syntax-do-expressions": "workspace:^7.10.4"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user