This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 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-proposal-async-generator-functions
> Turn async generator functions into ES2015 generators
See our website [@babel/plugin-proposal-async-generator-functions](https://babeljs.io/docs/en/babel-plugin-proposal-async-generator-functions) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-proposal-async-generator-functions
```
or using yarn:
```sh
yarn add @babel/plugin-proposal-async-generator-functions --dev
```

View File

@ -0,0 +1,89 @@
"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_COMPLETION = true;
var ITERATOR_HAD_ERROR_KEY = false;
var ITERATOR_ERROR_KEY;
try {
for (
var ITERATOR_KEY = GET_ITERATOR(OBJECT), STEP_KEY, STEP_VALUE;
(
STEP_KEY = await ITERATOR_KEY.next(),
ITERATOR_COMPLETION = STEP_KEY.done,
STEP_VALUE = await STEP_KEY.value,
!ITERATOR_COMPLETION
);
ITERATOR_COMPLETION = true) {
}
} catch (err) {
ITERATOR_HAD_ERROR_KEY = true;
ITERATOR_ERROR_KEY = err;
} finally {
try {
if (!ITERATOR_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 = scope.generateUidIdentifier("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_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
GET_ITERATOR: getAsyncIterator,
OBJECT: node.right,
STEP_VALUE: _core.types.cloneNode(stepValue),
STEP_KEY: 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
};
}

View File

@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _helperRemapAsyncToGenerator = _interopRequireDefault(require("@babel/helper-remap-async-to-generator"));
var _pluginSyntaxAsyncGenerators = _interopRequireDefault(require("@babel/plugin-syntax-async-generators"));
var _core = require("@babel/core");
var _forAwait = _interopRequireDefault(require("./for-await"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion(7);
const yieldStarVisitor = {
Function(path) {
path.skip();
},
YieldExpression({
node
}, state) {
if (!node.delegate) return;
const callee = state.addHelper("asyncGeneratorDelegate");
node.argument = _core.types.callExpression(callee, [_core.types.callExpression(state.addHelper("asyncIterator"), [node.argument]), state.addHelper("awaitAsyncGenerator")]);
}
};
const forAwaitVisitor = {
Function(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);
}
block.body = block.body.concat(node.body.body);
_core.types.inherits(loop, node);
_core.types.inherits(loop.body, node.body);
if (build.replaceParent) {
path.parentPath.replaceWithMultiple(build.node);
} else {
path.replaceWithMultiple(build.node);
}
}
};
const visitor = {
Function(path, state) {
if (!path.node.async) return;
path.traverse(forAwaitVisitor, state);
if (!path.node.generator) return;
path.traverse(yieldStarVisitor, state);
(0, _helperRemapAsyncToGenerator.default)(path, {
wrapAsync: state.addHelper("wrapAsyncGenerator"),
wrapAwait: state.addHelper("awaitAsyncGenerator")
});
}
};
return {
name: "proposal-async-generator-functions",
inherits: _pluginSyntaxAsyncGenerators.default,
visitor: {
Program(path, state) {
path.traverse(visitor, state);
}
}
};
});
exports.default = _default;

View File

@ -0,0 +1,33 @@
{
"name": "@babel/plugin-proposal-async-generator-functions",
"version": "7.13.8",
"description": "Turn async generator functions into ES2015 generators",
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-plugin-proposal-async-generator-functions"
},
"homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-async-generator-functions",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/helper-plugin-utils": "^7.13.0",
"@babel/helper-remap-async-to-generator": "^7.13.0",
"@babel/plugin-syntax-async-generators": "^7.8.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "7.13.8",
"@babel/helper-plugin-test-runner": "7.12.13",
"babel-plugin-polyfill-corejs3": "^0.1.3",
"core-js-pure": "^3.8.1"
}
}