Archive @babel/helper-call-delegate (#13153)

This commit is contained in:
Nicolò Ribaudo 2021-04-14 23:54:46 +02:00 committed by GitHub
parent d6d942ddac
commit 5c7d2a7fa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 123 deletions

View File

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

View File

@ -1,19 +0,0 @@
# @babel/helper-call-delegate
> Helper function to call delegate
See our website [@babel/helper-call-delegate](https://babeljs.io/docs/en/babel-helper-call-delegate) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/helper-call-delegate
```
or using yarn:
```sh
yarn add @babel/helper-call-delegate --dev
```

View File

@ -1,23 +0,0 @@
{
"name": "@babel/helper-call-delegate",
"version": "7.12.13",
"description": "Helper function to call delegate",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-helper-call-delegate"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-call-delegate",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"dependencies": {
"@babel/helper-hoist-variables": "workspace:^7.12.13",
"@babel/types": "workspace:^7.12.13"
},
"devDependencies": {
"@babel/traverse": "workspace:*"
}
}

View File

@ -1,67 +0,0 @@
import hoistVariables from "@babel/helper-hoist-variables";
import type { NodePath } from "@babel/traverse";
import * as t from "@babel/types";
const visitor = {
enter(path, state) {
if (path.isThisExpression()) {
state.foundThis = true;
}
if (path.isReferencedIdentifier({ name: "arguments" })) {
state.foundArguments = true;
}
},
Function(path) {
path.skip();
},
};
export default function (
path: NodePath,
scope = path.scope,
shouldHoistVariables = true,
) {
const { node } = path;
const container = t.functionExpression(
null,
[],
node.body,
node.generator,
node.async,
);
let callee = container;
let args = [];
if (shouldHoistVariables) {
hoistVariables(path, id => scope.push({ id }));
}
const state = {
foundThis: false,
foundArguments: false,
};
path.traverse(visitor, state);
if (state.foundArguments || state.foundThis) {
callee = t.memberExpression(container, t.identifier("apply"));
args = [];
if (state.foundThis) {
args.push(t.thisExpression());
}
if (state.foundArguments) {
if (!state.foundThis) args.push(t.nullLiteral());
args.push(t.identifier("arguments"));
}
}
let call = t.callExpression(callee, args);
if (node.generator) call = t.yieldExpression(call, true);
return t.returnStatement(call);
}

View File

@ -389,16 +389,6 @@ __metadata:
languageName: unknown
linkType: soft
"@babel/helper-call-delegate@workspace:packages/babel-helper-call-delegate":
version: 0.0.0-use.local
resolution: "@babel/helper-call-delegate@workspace:packages/babel-helper-call-delegate"
dependencies:
"@babel/helper-hoist-variables": "workspace:^7.12.13"
"@babel/traverse": "workspace:*"
"@babel/types": "workspace:^7.12.13"
languageName: unknown
linkType: soft
"@babel/helper-compilation-targets@npm:^7.13.0":
version: 7.13.0
resolution: "@babel/helper-compilation-targets@npm:7.13.0"
@ -614,7 +604,7 @@ __metadata:
languageName: node
linkType: hard
"@babel/helper-hoist-variables@workspace:^7.12.13, @babel/helper-hoist-variables@workspace:^7.13.0, @babel/helper-hoist-variables@workspace:packages/babel-helper-hoist-variables":
"@babel/helper-hoist-variables@workspace:^7.13.0, @babel/helper-hoist-variables@workspace:packages/babel-helper-hoist-variables":
version: 0.0.0-use.local
resolution: "@babel/helper-hoist-variables@workspace:packages/babel-helper-hoist-variables"
dependencies: