first commit

This commit is contained in:
monjack
2025-06-20 18:01:48 +08:00
commit 6daa6d65c1
24611 changed files with 2512443 additions and 0 deletions

View File

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,19 @@
# @babel/plugin-transform-async-generator-functions
> Turn async generator functions into ES2015 generators
See our website [@babel/plugin-transform-async-generator-functions](https://babeljs.io/docs/babel-plugin-transform-async-generator-functions) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-transform-async-generator-functions
```
or using yarn:
```sh
yarn add @babel/plugin-transform-async-generator-functions --dev
```

View File

@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _core = require("@babel/core");
const buildForAwait = (0, _core.template)(`
async function wrapper() {
var ITERATOR_ABRUPT_COMPLETION = false;
var ITERATOR_HAD_ERROR_KEY = false;
var ITERATOR_ERROR_KEY;
try {
for (
var ITERATOR_KEY = GET_ITERATOR(OBJECT), STEP_KEY;
ITERATOR_ABRUPT_COMPLETION = !(STEP_KEY = await ITERATOR_KEY.next()).done;
ITERATOR_ABRUPT_COMPLETION = false
) {
}
} catch (err) {
ITERATOR_HAD_ERROR_KEY = true;
ITERATOR_ERROR_KEY = err;
} finally {
try {
if (ITERATOR_ABRUPT_COMPLETION && ITERATOR_KEY.return != null) {
await ITERATOR_KEY.return();
}
} finally {
if (ITERATOR_HAD_ERROR_KEY) {
throw ITERATOR_ERROR_KEY;
}
}
}
}
`);
function _default(path, {
getAsyncIterator
}) {
const {
node,
scope,
parent
} = path;
const stepKey = scope.generateUidIdentifier("step");
const stepValue = _core.types.memberExpression(stepKey, _core.types.identifier("value"));
const left = node.left;
let declar;
if (_core.types.isIdentifier(left) || _core.types.isPattern(left) || _core.types.isMemberExpression(left)) {
declar = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, stepValue));
} else if (_core.types.isVariableDeclaration(left)) {
declar = _core.types.variableDeclaration(left.kind, [_core.types.variableDeclarator(left.declarations[0].id, stepValue)]);
}
let template = buildForAwait({
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
ITERATOR_ABRUPT_COMPLETION: scope.generateUidIdentifier("iteratorAbruptCompletion"),
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
GET_ITERATOR: getAsyncIterator,
OBJECT: node.right,
STEP_KEY: _core.types.cloneNode(stepKey)
});
template = template.body.body;
const isLabeledParent = _core.types.isLabeledStatement(parent);
const tryBody = template[3].block.body;
const loop = tryBody[0];
if (isLabeledParent) {
tryBody[0] = _core.types.labeledStatement(parent.label, loop);
}
return {
replaceParent: isLabeledParent,
node: template,
declar,
loop
};
}
//# sourceMappingURL=for-await.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperRemapAsyncToGenerator = require("@babel/helper-remap-async-to-generator");
var _core = require("@babel/core");
var _traverse = require("@babel/traverse");
var _forAwait = require("./for-await.js");
var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion("^7.0.0-0 || >8.0.0-alpha <8.0.0-beta");
const yieldStarVisitor = _traverse.visitors.environmentVisitor({
ArrowFunctionExpression(path) {
path.skip();
},
YieldExpression({
node
}, state) {
if (!node.delegate) return;
const asyncIter = _core.types.callExpression(state.addHelper("asyncIterator"), [node.argument]);
node.argument = _core.types.callExpression(state.addHelper("asyncGeneratorDelegate"), [asyncIter, state.addHelper("awaitAsyncGenerator")]);
}
});
const forAwaitVisitor = _traverse.visitors.environmentVisitor({
ArrowFunctionExpression(path) {
path.skip();
},
ForOfStatement(path, {
file
}) {
const {
node
} = path;
if (!node.await) return;
const build = (0, _forAwait.default)(path, {
getAsyncIterator: file.addHelper("asyncIterator")
});
const {
declar,
loop
} = build;
const block = loop.body;
path.ensureBlock();
if (declar) {
block.body.push(declar);
if (path.node.body.body.length) {
block.body.push(_core.types.blockStatement(path.node.body.body));
}
} else {
block.body.push(...path.node.body.body);
}
_core.types.inherits(loop, node);
_core.types.inherits(loop.body, node.body);
const p = build.replaceParent ? path.parentPath : path;
p.replaceWithMultiple(build.node);
p.scope.parent.crawl();
}
});
const visitor = {
Function(path, state) {
if (!path.node.async) return;
path.traverse(forAwaitVisitor, state);
if (!path.node.generator) return;
path.traverse(yieldStarVisitor, state);
path.setData("@babel/plugin-transform-async-generator-functions/async_generator_function", true);
(0, _helperRemapAsyncToGenerator.default)(path, {
wrapAsync: state.addHelper("wrapAsyncGenerator"),
wrapAwait: state.addHelper("awaitAsyncGenerator")
});
}
};
return {
name: "transform-async-generator-functions",
manipulateOptions: (_, parser) => parser.plugins.push("asyncGenerators"),
visitor: {
Program(path, state) {
path.traverse(visitor, state);
}
}
};
});
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,38 @@
{
"name": "@babel/plugin-transform-async-generator-functions",
"version": "7.27.1",
"description": "Turn async generator functions into ES2015 generators",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-plugin-transform-async-generator-functions"
},
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-async-generator-functions",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/helper-plugin-utils": "^7.27.1",
"@babel/helper-remap-async-to-generator": "^7.27.1",
"@babel/traverse": "^7.27.1"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.27.1",
"@babel/helper-plugin-test-runner": "^7.27.1",
"babel-plugin-polyfill-corejs3": "^0.11.0",
"core-js-pure": "^3.30.2"
},
"engines": {
"node": ">=6.9.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
}