Changing front

This commit is contained in:
ewandor committed 2023-01-16 17:49:38 +01:00
1 parent 0b8a93b256
commit 4fe4be7730
48586 files changed
+4725790 -17464

No files matched your search

@@ -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.
@@ -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
```
@@ -0,0 +1,78 @@
"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
@@ -0,0 +1 @@
{"version":3,"names":["buildForAwait","template","path","getAsyncIterator","node","scope","parent","stepKey","generateUidIdentifier","stepValue","t","memberExpression","identifier","left","declar","isIdentifier","isPattern","isMemberExpression","expressionStatement","assignmentExpression","isVariableDeclaration","variableDeclaration","kind","variableDeclarator","declarations","id","ITERATOR_HAD_ERROR_KEY","ITERATOR_ABRUPT_COMPLETION","ITERATOR_ERROR_KEY","ITERATOR_KEY","GET_ITERATOR","OBJECT","right","STEP_KEY","cloneNode","body","isLabeledParent","isLabeledStatement","tryBody","block","loop","labeledStatement","label","replaceParent"],"sources":["../src/for-await.ts"],"sourcesContent":["import { types as t, template } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\n\nconst buildForAwait = template(`\n async function wrapper() {\n var ITERATOR_ABRUPT_COMPLETION = false;\n var ITERATOR_HAD_ERROR_KEY = false;\n var ITERATOR_ERROR_KEY;\n try {\n for (\n var ITERATOR_KEY = GET_ITERATOR(OBJECT), STEP_KEY;\n ITERATOR_ABRUPT_COMPLETION = !(STEP_KEY = await ITERATOR_KEY.next()).done;\n ITERATOR_ABRUPT_COMPLETION = false\n ) {\n }\n } catch (err) {\n ITERATOR_HAD_ERROR_KEY = true;\n ITERATOR_ERROR_KEY = err;\n } finally {\n try {\n if (ITERATOR_ABRUPT_COMPLETION && ITERATOR_KEY.return != null) {\n await ITERATOR_KEY.return();\n }\n } finally {\n if (ITERATOR_HAD_ERROR_KEY) {\n throw ITERATOR_ERROR_KEY;\n }\n }\n }\n }\n`);\n\nexport default function (\n path: NodePath<t.ForOfStatement>,\n { getAsyncIterator }: { getAsyncIterator: t.Identifier },\n) {\n const { node, scope, parent } = path;\n\n const stepKey = scope.generateUidIdentifier(\"step\");\n const stepValue = t.memberExpression(stepKey, t.identifier(\"value\"));\n const left = node.left;\n let declar;\n\n if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {\n // for await (i of test), for await ({ i } of test)\n declar = t.expressionStatement(\n t.assignmentExpression(\"=\", left, stepValue),\n );\n } else if (t.isVariableDeclaration(left)) {\n // for await (let i of test)\n declar = t.variableDeclaration(left.kind, [\n t.variableDeclarator(left.declarations[0].id, stepValue),\n ]);\n }\n let template = buildForAwait({\n ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier(\"didIteratorError\"),\n ITERATOR_ABRUPT_COMPLETION: scope.generateUidIdentifier(\n \"iteratorAbruptCompletion\",\n ),\n ITERATOR_ERROR_KEY: scope.generateUidIdentifier(\"iteratorError\"),\n ITERATOR_KEY: scope.generateUidIdentifier(\"iterator\"),\n GET_ITERATOR: getAsyncIterator,\n OBJECT: node.right,\n STEP_KEY: t.cloneNode(stepKey),\n });\n\n // remove async function wrapper\n // @ts-expect-error todo(flow->ts) improve type annotation for buildForAwait\n template = template.body.body as t.Statement[];\n\n const isLabeledParent = t.isLabeledStatement(parent);\n const tryBody = (template[3] as t.TryStatement).block.body;\n const loop = tryBody[0] as t.ForStatement;\n\n if (isLabeledParent) {\n tryBody[0] = t.labeledStatement(parent.label, loop);\n }\n\n return {\n replaceParent: isLabeledParent,\n node: template,\n declar,\n loop,\n };\n}\n"],"mappings":";;;;;;AAAA;AAGA,MAAMA,aAAa,GAAG,IAAAC,cAAQ,EAAE;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,CAAC;AAEa,kBACbC,IAAgC,EAChC;EAAEC;AAAqD,CAAC,EACxD;EACA,MAAM;IAAEC,IAAI;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGJ,IAAI;EAEpC,MAAMK,OAAO,GAAGF,KAAK,CAACG,qBAAqB,CAAC,MAAM,CAAC;EACnD,MAAMC,SAAS,GAAGC,WAAC,CAACC,gBAAgB,CAACJ,OAAO,EAAEG,WAAC,CAACE,UAAU,CAAC,OAAO,CAAC,CAAC;EACpE,MAAMC,IAAI,GAAGT,IAAI,CAACS,IAAI;EACtB,IAAIC,MAAM;EAEV,IAAIJ,WAAC,CAACK,YAAY,CAACF,IAAI,CAAC,IAAIH,WAAC,CAACM,SAAS,CAACH,IA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perty(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 _pluginSyntaxAsyncGenerators = require("@babel/plugin-syntax-async-generators");
var _core = require("@babel/core");
var _forAwait = require("./for-await");
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
var _default = (0, _helperPluginUtils.declare)(api => {
api.assertVersion(7);
const yieldStarVisitor = _core.traverse.visitors.merge([{
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")]);
}
}, _helperEnvironmentVisitor.default]);
const forAwaitVisitor = _core.traverse.visitors.merge([{
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);
if (build.replaceParent) {
path.parentPath.replaceWithMultiple(build.node);
} else {
path.replaceWithMultiple(build.node);
}
}
}, _helperEnvironmentVisitor.default]);
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;
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"names":["declare","api","assertVersion","yieldStarVisitor","traverse","visitors","merge","ArrowFunctionExpression","path","skip","YieldExpression","node","state","delegate","asyncIter","t","callExpression","addHelper","argument","environmentVisitor","forAwaitVisitor","ForOfStatement","file","await","build","rewriteForAwait","getAsyncIterator","declar","loop","block","body","ensureBlock","push","length","blockStatement","inherits","replaceParent","parentPath","replaceWithMultiple","visitor","Function","async","generator","remapAsyncToGenerator","wrapAsync","wrapAwait","name","syntaxAsyncGenerators","default","Program"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport remapAsyncToGenerator from \"@babel/helper-remap-async-to-generator\";\nimport syntaxAsyncGenerators from \"@babel/plugin-syntax-async-generators\";\nimport type { NodePath, Visitor } from \"@babel/traverse\";\nimport { traverse, types as t, type PluginPass } from \"@babel/core\";\nimport rewriteForAwait from \"./for-await\";\nimport environmentVisitor from \"@babel/helper-environment-visitor\";\n\nexport default declare(api => {\n api.assertVersion(7);\n\n const yieldStarVisitor = traverse.visitors.merge<PluginPass>([\n {\n ArrowFunctionExpression(path) {\n path.skip();\n },\n\n YieldExpression({ node }, state) {\n if (!node.delegate) return;\n const asyncIter = t.callExpression(state.addHelper(\"asyncIterator\"), [\n node.argument,\n ]);\n node.argument = t.callExpression(\n state.addHelper(\"asyncGeneratorDelegate\"),\n process.env.BABEL_8_BREAKING\n ? [asyncIter]\n : [asyncIter, state.addHelper(\"awaitAsyncGenerator\")],\n );\n },\n },\n environmentVisitor,\n ]);\n\n const forAwaitVisitor = traverse.visitors.merge<PluginPass>([\n {\n ArrowFunctionExpression(path) {\n path.skip();\n },\n\n ForOfStatement(path: NodePath<t.ForOfStatement>, { file }) {\n const { node } = path;\n if (!node.await) return;\n\n const build = rewriteForAwait(path, {\n getAsyncIterator: file.addHelper(\"asyncIterator\"),\n });\n\n const { declar, loop } = build;\n const block = loop.body as t.BlockStatement;\n\n // ensure that it's a block so we can take all its statements\n path.ensureBlock();\n\n // add the value declaration to the new loop body\n if (declar) {\n block.body.push(declar);\n if (path.node.body.body.length) {\n block.body.push(t.blockStatement(path.node.body.body));\n }\n } else {\n block.body.push(...path.node.body.body);\n }\n\n t.inherits(loop, node);\n t.inherits(loop.body, node.body);\n\n if (build.replaceParent) {\n path.parentPath.replaceWithMultiple(build.node);\n } else {\n path.replaceWithMultiple(build.node);\n }\n },\n },\n environmentVisitor,\n ]);\n\n const visitor: Visitor<PluginPass> = {\n Function(path, state) {\n if (!path.node.async) return;\n\n path.traverse(forAwaitVisitor, state);\n\n if (!path.node.generator) return;\n\n path.traverse(yieldStarVisitor, state);\n\n // We don't need to pass the noNewArrows assumption, since\n // async generators are never arrow functions.\n remapAsyncToGenerator(path, {\n wrapAsync: state.addHelper(\"wrapAsyncGenerator\"),\n wrapAwait: state.addHelper(\"awaitAsyncGenerator\"),\n });\n },\n };\n\n return {\n name: \"proposal-async-generator-functions\",\n inherits: syntaxAsyncGenerators.default,\n\n visitor: {\n Program(path, state) {\n // We need to traverse the ast here (instead of just vising Function\n // in the top level visitor) because for-await needs to run before the\n // async-to-generator plugin. This is because for-await is transpiled\n // using \"await\" expressions, which are then converted to \"yield\".\n //\n // This is bad for performance, but plugin ordering will allow as to\n // directly visit Function in the top level visitor.\n path.traverse(visitor, state);\n },\n },\n };\n});\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAEA;AACA;AACA;AAAmE,eAEpD,IAAAA,0BAAO,EAACC,GAAG,IAAI;EAC5BA,GAAG,CAACC,aAAa,CAAC,CAAC,CAAC;EAEpB,MAAMC,gBAAgB,GAAGC,cAAQ,CAACC,QAAQ,CAACC,KAAK,CAAa,CAC3D;IACEC,uBAAuB,CAACC,IAAI,EAAE;MAC5BA,IAAI,CAACC,IAAI,EAAE;IACb,CAAC;IAEDC,eAAe,CAAC;MAAEC;IAAK,CAAC,EAAEC,KAAK,EAAE;MAC/B,IAAI,CAACD,IAAI,CAACE,QAAQ,EAAE;MACpB,MAAMC,SAAS,GAAGC,WAAC,CAACC,cAAc,CAACJ,KAAK,CAACK,SAAS,CAAC,eAAe,CAAC,EAAE,CACnEN,IAAI,CAACO,QAAQ,CACd,CAAC;MACFP,IAAI,CAACO,QAAQ,GAAGH,WAAC,CAACC,cAAc,CAC9BJ,KAAK,CAACK,SAAS,CAAC,wBAAwB,CAAC,EAGrC,CAACH,SAAS,EAAEF,KAAK,CAACK,SAAS,CAAC,qBAAqB,CAAC,CAAC,CACxD;IACH;EACF,CAAC,EACDE,iCAAkB,CACnB,CAACLine truncated
@@ -0,0 +1,39 @@
{
"name": "@babel/plugin-proposal-async-generator-functions",
"version": "7.20.1",
"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-environment-visitor": "^7.18.9",
"@babel/helper-plugin-utils": "^7.19.0",
"@babel/helper-remap-async-to-generator": "^7.18.9",
"@babel/plugin-syntax-async-generators": "^7.8.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "^7.19.6",
"@babel/helper-plugin-test-runner": "^7.18.6",
"babel-plugin-polyfill-corejs3": "^0.6.0",
"core-js-pure": "^3.25.1"
},
"engines": {
"node": ">=6.9.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
}