Archive helper-explode-class and helper-bindify-decorators (#13160)
This commit is contained in:
parent
ed4ccd6482
commit
cbfcee59c7
@ -1,3 +0,0 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
@ -1,19 +0,0 @@
|
||||
# @babel/helper-bindify-decorators
|
||||
|
||||
> Helper function to bindify decorators
|
||||
|
||||
See our website [@babel/helper-bindify-decorators](https://babeljs.io/docs/en/babel-helper-bindify-decorators) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helper-bindify-decorators
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-bindify-decorators --dev
|
||||
```
|
||||
@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "@babel/helper-bindify-decorators",
|
||||
"version": "7.12.13",
|
||||
"description": "Helper function to bindify decorators",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-bindify-decorators"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-bindify-decorators",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/types": "workspace:^7.12.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/traverse": "workspace:*"
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
import type { NodePath } from "@babel/traverse";
|
||||
import * as t from "@babel/types";
|
||||
|
||||
export default function bindifyDecorators(
|
||||
decorators: ReadonlyArray<NodePath<t.Decorator>>,
|
||||
): void {
|
||||
for (const decoratorPath of decorators) {
|
||||
const decorator = decoratorPath.node;
|
||||
const expression = decorator.expression;
|
||||
if (!t.isMemberExpression(expression)) continue;
|
||||
|
||||
const temp = decoratorPath.scope.maybeGenerateMemoised(expression.object);
|
||||
let ref;
|
||||
|
||||
const nodes = [];
|
||||
|
||||
if (temp) {
|
||||
ref = temp;
|
||||
nodes.push(t.assignmentExpression("=", temp, expression.object));
|
||||
} else {
|
||||
ref = expression.object;
|
||||
}
|
||||
|
||||
nodes.push(
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.memberExpression(ref, expression.property, expression.computed),
|
||||
t.identifier("bind"),
|
||||
),
|
||||
[ref],
|
||||
),
|
||||
);
|
||||
|
||||
if (nodes.length === 1) {
|
||||
decorator.expression = nodes[0];
|
||||
} else {
|
||||
decorator.expression = t.sequenceExpression(nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
src
|
||||
test
|
||||
*.log
|
||||
@ -1,19 +0,0 @@
|
||||
# @babel/helper-explode-class
|
||||
|
||||
> Helper function to explode class
|
||||
|
||||
See our website [@babel/helper-explode-class](https://babeljs.io/docs/en/babel-helper-explode-class) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helper-explode-class
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-explode-class --dev
|
||||
```
|
||||
@ -1,23 +0,0 @@
|
||||
{
|
||||
"name": "@babel/helper-explode-class",
|
||||
"version": "7.12.13",
|
||||
"description": "Helper function to explode class",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-explode-class"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-explode-class",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-bindify-decorators": "workspace:^7.12.13",
|
||||
"@babel/types": "workspace:^7.12.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/traverse": "workspace:*"
|
||||
}
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
import bindifyDecorators from "@babel/helper-bindify-decorators";
|
||||
import type { NodePath } from "@babel/traverse";
|
||||
import * as t from "@babel/types";
|
||||
|
||||
export default function (classPath) {
|
||||
classPath.assertClass();
|
||||
|
||||
const memoisedExpressions = [];
|
||||
|
||||
function maybeMemoise(path) {
|
||||
if (!path.node || path.isPure()) return;
|
||||
|
||||
const uid = classPath.scope.generateDeclaredUidIdentifier();
|
||||
memoisedExpressions.push(t.assignmentExpression("=", uid, path.node));
|
||||
path.replaceWith(uid);
|
||||
}
|
||||
|
||||
function memoiseDecorators(paths: Array<NodePath>) {
|
||||
if (!Array.isArray(paths) || !paths.length) return;
|
||||
|
||||
// ensure correct evaluation order of decorators
|
||||
paths = paths.reverse();
|
||||
|
||||
// bind decorators if they're member expressions
|
||||
bindifyDecorators(paths);
|
||||
|
||||
for (const path of paths) {
|
||||
maybeMemoise(path);
|
||||
}
|
||||
}
|
||||
|
||||
maybeMemoise(classPath.get("superClass"));
|
||||
memoiseDecorators(classPath.get("decorators"), true);
|
||||
|
||||
const methods: Array<NodePath> = classPath.get("body.body");
|
||||
for (const methodPath of methods) {
|
||||
if (methodPath.is("computed")) {
|
||||
maybeMemoise(methodPath.get("key"));
|
||||
}
|
||||
|
||||
if (methodPath.has("decorators")) {
|
||||
memoiseDecorators(classPath.get("decorators"));
|
||||
}
|
||||
}
|
||||
|
||||
if (memoisedExpressions) {
|
||||
classPath.insertBefore(
|
||||
memoisedExpressions.map(expr => t.expressionStatement(expr)),
|
||||
);
|
||||
}
|
||||
}
|
||||
19
yarn.lock
19
yarn.lock
@ -352,15 +352,6 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-bindify-decorators@workspace:^7.12.13, @babel/helper-bindify-decorators@workspace:packages/babel-helper-bindify-decorators":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/helper-bindify-decorators@workspace:packages/babel-helper-bindify-decorators"
|
||||
dependencies:
|
||||
"@babel/traverse": "workspace:*"
|
||||
"@babel/types": "workspace:^7.12.13"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-builder-binary-assignment-operator-visitor@npm:^7.12.13":
|
||||
version: 7.12.13
|
||||
resolution: "@babel/helper-builder-binary-assignment-operator-visitor@npm:7.12.13"
|
||||
@ -537,16 +528,6 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-explode-class@workspace:packages/babel-helper-explode-class":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/helper-explode-class@workspace:packages/babel-helper-explode-class"
|
||||
dependencies:
|
||||
"@babel/helper-bindify-decorators": "workspace:^7.12.13"
|
||||
"@babel/traverse": "workspace:*"
|
||||
"@babel/types": "workspace:^7.12.13"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@babel/helper-fixtures@workspace:*, @babel/helper-fixtures@workspace:^7.13.13, @babel/helper-fixtures@workspace:packages/babel-helper-fixtures":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@babel/helper-fixtures@workspace:packages/babel-helper-fixtures"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user