@babel/plugin-transform-async-generator-functions
Advanced tools
Comparing version 7.22.7 to 8.0.0-alpha.0
@@ -1,9 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
var _core = require("@babel/core"); | ||
const buildForAwait = (0, _core.template)(` | ||
import { types as t, template } from "@babel/core"; | ||
const buildForAwait = template(` | ||
async function wrapper() { | ||
@@ -36,3 +30,3 @@ var ITERATOR_ABRUPT_COMPLETION = false; | ||
`); | ||
function _default(path, { | ||
export default function (path, { | ||
getAsyncIterator | ||
@@ -46,9 +40,9 @@ }) { | ||
const stepKey = scope.generateUidIdentifier("step"); | ||
const stepValue = _core.types.memberExpression(stepKey, _core.types.identifier("value")); | ||
const stepValue = t.memberExpression(stepKey, t.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)]); | ||
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { | ||
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue)); | ||
} else if (t.isVariableDeclaration(left)) { | ||
declar = t.variableDeclaration(left.kind, [t.variableDeclarator(left.declarations[0].id, stepValue)]); | ||
} | ||
@@ -62,10 +56,10 @@ let template = buildForAwait({ | ||
OBJECT: node.right, | ||
STEP_KEY: _core.types.cloneNode(stepKey) | ||
STEP_KEY: t.cloneNode(stepKey) | ||
}); | ||
template = template.body.body; | ||
const isLabeledParent = _core.types.isLabeledStatement(parent); | ||
const isLabeledParent = t.isLabeledStatement(parent); | ||
const tryBody = template[3].block.body; | ||
const loop = tryBody[0]; | ||
if (isLabeledParent) { | ||
tryBody[0] = _core.types.labeledStatement(parent.label, loop); | ||
tryBody[0] = t.labeledStatement(parent.label, loop); | ||
} | ||
@@ -72,0 +66,0 @@ return { |
113
lib/index.js
@@ -1,16 +0,79 @@ | ||
"use strict"; | ||
import { declare } from '@babel/helper-plugin-utils'; | ||
import remapAsyncToGenerator from '@babel/helper-remap-async-to-generator'; | ||
import syntaxAsyncGenerators from '@babel/plugin-syntax-async-generators'; | ||
import { template, types, traverse } from '@babel/core'; | ||
import environmentVisitor from '@babel/helper-environment-visitor'; | ||
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 _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 => { | ||
const buildForAwait = 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 rewriteForAwait (path, { | ||
getAsyncIterator | ||
}) { | ||
const { | ||
node, | ||
scope, | ||
parent | ||
} = path; | ||
const stepKey = scope.generateUidIdentifier("step"); | ||
const stepValue = types.memberExpression(stepKey, types.identifier("value")); | ||
const left = node.left; | ||
let declar; | ||
if (types.isIdentifier(left) || types.isPattern(left) || types.isMemberExpression(left)) { | ||
declar = types.expressionStatement(types.assignmentExpression("=", left, stepValue)); | ||
} else if (types.isVariableDeclaration(left)) { | ||
declar = types.variableDeclaration(left.kind, [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: types.cloneNode(stepKey) | ||
}); | ||
template = template.body.body; | ||
const isLabeledParent = types.isLabeledStatement(parent); | ||
const tryBody = template[3].block.body; | ||
const loop = tryBody[0]; | ||
if (isLabeledParent) { | ||
tryBody[0] = types.labeledStatement(parent.label, loop); | ||
} | ||
return { | ||
replaceParent: isLabeledParent, | ||
node: template, | ||
declar, | ||
loop | ||
}; | ||
} | ||
var index = declare(api => { | ||
api.assertVersion(7); | ||
const yieldStarVisitor = _core.traverse.visitors.merge([{ | ||
const yieldStarVisitor = traverse.visitors.merge([{ | ||
ArrowFunctionExpression(path) { | ||
@@ -23,7 +86,7 @@ path.skip(); | ||
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 asyncIter = types.callExpression(state.addHelper("asyncIterator"), [node.argument]); | ||
node.argument = types.callExpression(state.addHelper("asyncGeneratorDelegate"), [asyncIter]); | ||
} | ||
}, _helperEnvironmentVisitor.default]); | ||
const forAwaitVisitor = _core.traverse.visitors.merge([{ | ||
}, environmentVisitor]); | ||
const forAwaitVisitor = traverse.visitors.merge([{ | ||
ArrowFunctionExpression(path) { | ||
@@ -39,3 +102,3 @@ path.skip(); | ||
if (!node.await) return; | ||
const build = (0, _forAwait.default)(path, { | ||
const build = rewriteForAwait(path, { | ||
getAsyncIterator: file.addHelper("asyncIterator") | ||
@@ -52,3 +115,3 @@ }); | ||
if (path.node.body.body.length) { | ||
block.body.push(_core.types.blockStatement(path.node.body.body)); | ||
block.body.push(types.blockStatement(path.node.body.body)); | ||
} | ||
@@ -58,4 +121,4 @@ } else { | ||
} | ||
_core.types.inherits(loop, node); | ||
_core.types.inherits(loop.body, node.body); | ||
types.inherits(loop, node); | ||
types.inherits(loop.body, node.body); | ||
const p = build.replaceParent ? path.parentPath : path; | ||
@@ -65,3 +128,3 @@ p.replaceWithMultiple(build.node); | ||
} | ||
}, _helperEnvironmentVisitor.default]); | ||
}, environmentVisitor]); | ||
const visitor = { | ||
@@ -73,3 +136,3 @@ Function(path, state) { | ||
path.traverse(yieldStarVisitor, state); | ||
(0, _helperRemapAsyncToGenerator.default)(path, { | ||
remapAsyncToGenerator(path, { | ||
wrapAsync: state.addHelper("wrapAsyncGenerator"), | ||
@@ -82,3 +145,3 @@ wrapAwait: state.addHelper("awaitAsyncGenerator") | ||
name: "transform-async-generator-functions", | ||
inherits: _pluginSyntaxAsyncGenerators.default, | ||
inherits: syntaxAsyncGenerators.default, | ||
visitor: { | ||
@@ -91,4 +154,4 @@ Program(path, state) { | ||
}); | ||
exports.default = _default; | ||
export { index as default }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/plugin-transform-async-generator-functions", | ||
"version": "7.22.7", | ||
"version": "8.0.0-alpha.0", | ||
"description": "Turn async generator functions into ES2015 generators", | ||
@@ -20,13 +20,13 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-environment-visitor": "^7.22.5", | ||
"@babel/helper-plugin-utils": "^7.22.5", | ||
"@babel/helper-remap-async-to-generator": "^7.22.5", | ||
"@babel/helper-environment-visitor": "^8.0.0-alpha.0", | ||
"@babel/helper-plugin-utils": "^8.0.0-alpha.0", | ||
"@babel/helper-remap-async-to-generator": "^8.0.0-alpha.0", | ||
"@babel/plugin-syntax-async-generators": "^7.8.4" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0-0" | ||
"@babel/core": "^8.0.0-alpha.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.22.7", | ||
"@babel/helper-plugin-test-runner": "^7.22.5", | ||
"@babel/core": "^8.0.0-alpha.0", | ||
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0", | ||
"babel-plugin-polyfill-corejs3": "^0.8.2", | ||
@@ -36,6 +36,10 @@ "core-js-pure": "^3.30.2" | ||
"engines": { | ||
"node": ">=6.9.0" | ||
"node": "^16.20.0 || ^18.16.0 || >=20.0.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"type": "commonjs" | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "module" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27427
216
Yes
1
+ Added@babel/code-frame@8.0.0-alpha.12(transitive)
+ Added@babel/compat-data@8.0.0-alpha.12(transitive)
+ Added@babel/core@8.0.0-alpha.12(transitive)
+ Added@babel/generator@8.0.0-alpha.12(transitive)
+ Added@babel/helper-annotate-as-pure@8.0.0-alpha.12(transitive)
+ Added@babel/helper-compilation-targets@8.0.0-alpha.12(transitive)
+ Added@babel/helper-environment-visitor@8.0.0-alpha.11(transitive)
+ Added@babel/helper-plugin-utils@8.0.0-alpha.12(transitive)
+ Added@babel/helper-remap-async-to-generator@8.0.0-alpha.12(transitive)
+ Added@babel/helper-string-parser@8.0.0-alpha.12(transitive)
+ Added@babel/helper-validator-identifier@8.0.0-alpha.12(transitive)
+ Added@babel/helper-validator-option@8.0.0-alpha.12(transitive)
+ Added@babel/helper-wrap-function@8.0.0-alpha.12(transitive)
+ Added@babel/helpers@8.0.0-alpha.12(transitive)
+ Added@babel/highlight@8.0.0-alpha.12(transitive)
+ Added@babel/parser@8.0.0-alpha.12(transitive)
+ Added@babel/template@8.0.0-alpha.12(transitive)
+ Added@babel/traverse@8.0.0-alpha.12(transitive)
+ Added@babel/types@8.0.0-alpha.12(transitive)
+ Addedglobals@15.9.0(transitive)
+ Addedjs-tokens@8.0.3(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedlru-cache@7.18.3(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedto-fast-properties@3.0.1(transitive)
- Removed@babel/helper-annotate-as-pure@7.24.7(transitive)
- Removed@babel/helper-environment-visitor@7.24.7(transitive)
- Removed@babel/helper-remap-async-to-generator@7.25.0(transitive)
- Removed@babel/helper-wrap-function@7.25.0(transitive)
Updated@babel/helper-remap-async-to-generator@^8.0.0-alpha.0