Befor generating
This commit is contained in:
1 parent
3383f4bf4a
commit
1aa1b5f625
6756 files changed
+649946
-1
No files matched your search
+23
@@ -0,0 +1,23 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
Copyright (c) 2014-present Facebook, Inc.
|
||||
|
||||
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.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# @babel/plugin-transform-regenerator
|
||||
|
||||
> Explode async and generator functions into a state machine.
|
||||
|
||||
See our website [@babel/plugin-transform-regenerator](https://babeljs.io/docs/babel-plugin-transform-regenerator) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/plugin-transform-regenerator
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/plugin-transform-regenerator --dev
|
||||
```
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
||||
var _visit = require("./regenerator/visit.js");
|
||||
var _default = exports.default = (0, _helperPluginUtils.declare)(({
|
||||
types: t,
|
||||
traverse,
|
||||
assertVersion
|
||||
}) => {
|
||||
assertVersion(7);
|
||||
return {
|
||||
name: "transform-regenerator",
|
||||
visitor: traverse.visitors.merge([(0, _visit.getVisitor)(), {
|
||||
CallExpression(path) {
|
||||
var _this$availableHelper;
|
||||
if (!((_this$availableHelper = this.availableHelper) != null && _this$availableHelper.call(this, "regeneratorRuntime"))) {
|
||||
return;
|
||||
}
|
||||
const callee = path.get("callee");
|
||||
if (!callee.isMemberExpression()) return;
|
||||
const obj = callee.get("object");
|
||||
if (obj.isIdentifier({
|
||||
name: "regeneratorRuntime"
|
||||
})) {
|
||||
const helper = this.addHelper("regeneratorRuntime");
|
||||
if (t.isArrowFunctionExpression(helper)) {
|
||||
obj.replaceWith(helper.body);
|
||||
return;
|
||||
}
|
||||
obj.replaceWith(t.callExpression(helper, []));
|
||||
}
|
||||
}
|
||||
}])
|
||||
};
|
||||
});
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_helperPluginUtils","require","_visit","_default","exports","default","declare","types","t","traverse","assertVersion","name","visitor","visitors","merge","getVisitor","CallExpression","path","_this$availableHelper","availableHelper","call","callee","get","isMemberExpression","obj","isIdentifier","helper","addHelper","isArrowFunctionExpression","replaceWith","body","callExpression"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport type { types as t } from \"@babel/core\";\nimport { getVisitor } from \"./regenerator/visit.ts\";\n\nexport default declare(({ types: t, traverse, assertVersion }) => {\n assertVersion(REQUIRED_VERSION(7));\n\n return {\n name: \"transform-regenerator\",\n\n visitor: process.env.BABEL_8_BREAKING\n ? getVisitor()\n : traverse.visitors.merge([\n getVisitor(),\n {\n // We visit CallExpression so that we always transform\n // regeneratorRuntime.*() before babel-plugin-polyfill-regenerator.\n CallExpression(path) {\n if (!this.availableHelper?.(\"regeneratorRuntime\")) {\n // When using an older @babel/helpers version, fallback\n // to the old behavior.\n return;\n }\n\n const callee = path.get(\"callee\");\n if (!callee.isMemberExpression()) return;\n\n const obj = callee.get(\"object\");\n if (obj.isIdentifier({ name: \"regeneratorRuntime\" })) {\n const helper = this.addHelper(\"regeneratorRuntime\") as\n | t.Identifier\n | t.ArrowFunctionExpression;\n\n if (\n // It's necessary to avoid the IIFE when using older Babel versions.\n t.isArrowFunctionExpression(helper)\n ) {\n obj.replaceWith(helper.body);\n return;\n }\n\n obj.replaceWith(t.callExpression(helper, []));\n }\n },\n },\n ]),\n };\n});\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAAoD,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAErC,IAAAC,0BAAO,EAAC,CAAC;EAAEC,KAAK,EAAEC,CAAC;EAAEC,QAAQ;EAAEC;AAAc,CAAC,KAAK;EAChEA,aAAa,CAAkB,CAAE,CAAC;EAElC,OAAO;IACLC,IAAI,EAAE,uBAAuB;IAE7BC,OAAO,EAEHH,QAAQ,CAACI,QAAQ,CAACC,KAAK,CAAC,CACtB,IAAAC,iBAAU,EAAC,CAAC,EACZ;MAGEC,cAAcA,CAACC,IAAI,EAAE;QAAA,IAAAC,qBAAA;QACnB,IAAI,GAAAA,qBAAA,GAAC,IAAI,CAACC,eAAe,aAApBD,qBAAA,CAAAE,IAAA,KAAI,EAAmB,oBAAoB,CAAC,GAAE;UAGjD;QACF;QAEA,MAAMC,MAAM,GAAGJ,IAAI,CAACK,GAAG,CAAC,QAAQ,CAAC;QACjC,IAAI,CAACD,MAAM,CAACE,kBAAkB,CAAC,CAAC,EAAE;QAElC,MAAMC,GAAG,GAAGH,MAAM,CAACC,GAAG,CAAC,QAAQ,CAAC;QAChC,IAAIE,GAAG,CAACC,YAAY,CAAC;UAAEd,IAAI,EAAE;QAAqB,CAAC,CAAC,EAAE;UACpD,MAAMe,MAAM,GAAG,IAAI,CAACC,SAAS,CAAC,oBAAoB,CAErB;UAE7B,IAEEnB,CAAC,CAACoB,yBAAyB,CAACF,MAAM,CAAC,EACnC;YACAF,GAAG,CAACK,WAAW,CAACH,MAAM,CAACI,IAAI,CAAC;YAC5B;UACF;UAEAN,GAAG,CAACK,WAAW,CAACrB,CAAC,CAACuB,cAAc,CAACL,MAAM,EAAE,EAAE,CAAC,CAAC;QAC/C;MACF;IACF,CAAC,CACF;EACP,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
||||
Generated
Vendored
+639
@@ -0,0 +1,639 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.Emitter = void 0;
|
||||
var _assert = require("assert");
|
||||
var leap = require("./leap.js");
|
||||
var meta = require("./meta.js");
|
||||
var util = require("./util.js");
|
||||
var _core = require("@babel/core");
|
||||
const PENDING_LOCATION = Number.MAX_VALUE;
|
||||
function getDeclError(node) {
|
||||
return new Error("all declarations should have been transformed into " + "assignments before the Exploder began its work: " + JSON.stringify(node));
|
||||
}
|
||||
const catchParamVisitor = {
|
||||
Identifier: function (path, state) {
|
||||
if (path.node.name === state.catchParamName && util.isReference(path)) {
|
||||
path.replaceWith(state.getSafeParam());
|
||||
}
|
||||
},
|
||||
Scope: function (path, state) {
|
||||
if (path.scope.hasOwnBinding(state.catchParamName)) {
|
||||
path.skip();
|
||||
}
|
||||
}
|
||||
};
|
||||
class Emitter {
|
||||
constructor(contextId, scope, vars, pluginPass) {
|
||||
this.nextTempId = void 0;
|
||||
this.contextId = void 0;
|
||||
this.index = void 0;
|
||||
this.indexMap = void 0;
|
||||
this.listing = void 0;
|
||||
this.returns = void 0;
|
||||
this.lastReferenceIndex = 0;
|
||||
this.marked = void 0;
|
||||
this.insertedLocs = void 0;
|
||||
this.finalLoc = void 0;
|
||||
this.tryEntries = void 0;
|
||||
this.leapManager = void 0;
|
||||
this.scope = void 0;
|
||||
this.vars = void 0;
|
||||
this.pluginPass = void 0;
|
||||
this.pluginPass = pluginPass;
|
||||
this.scope = scope;
|
||||
this.vars = vars;
|
||||
this.nextTempId = 0;
|
||||
this.contextId = contextId;
|
||||
this.listing = [];
|
||||
this.index = 0;
|
||||
this.indexMap = new Map([[0, 0]]);
|
||||
this.returns = new Set();
|
||||
this.lastReferenceIndex = 0;
|
||||
this.marked = [true];
|
||||
this.insertedLocs = new Set();
|
||||
this.finalLoc = this.loc();
|
||||
this.tryEntries = [];
|
||||
this.leapManager = new leap.LeapManager(this);
|
||||
}
|
||||
loc() {
|
||||
const l = _core.types.numericLiteral(PENDING_LOCATION);
|
||||
this.insertedLocs.add(l);
|
||||
return l;
|
||||
}
|
||||
getInsertedLocs() {
|
||||
return this.insertedLocs;
|
||||
}
|
||||
getContextId() {
|
||||
return _core.types.cloneNode(this.contextId);
|
||||
}
|
||||
getIndex() {
|
||||
if (!this.indexMap.has(this.listing.length)) {
|
||||
this.indexMap.set(this.listing.length, ++this.index);
|
||||
}
|
||||
return this.index;
|
||||
}
|
||||
mark(loc) {
|
||||
if (loc.value === PENDING_LOCATION) {
|
||||
loc.value = this.getIndex();
|
||||
} else {
|
||||
_assert.strictEqual(loc.value, this.index);
|
||||
}
|
||||
this.marked[this.listing.length] = true;
|
||||
if (loc.value > this.lastReferenceIndex) {
|
||||
this.lastReferenceIndex = loc.value;
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
emit(node) {
|
||||
if (_core.types.isExpression(node)) {
|
||||
node = _core.types.expressionStatement(node);
|
||||
}
|
||||
_core.types.assertStatement(node);
|
||||
this.listing.push(node);
|
||||
}
|
||||
emitAssign(lhs, rhs) {
|
||||
this.emit(this.assign(lhs, rhs));
|
||||
return lhs;
|
||||
}
|
||||
assign(lhs, rhs) {
|
||||
return _core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(lhs), rhs));
|
||||
}
|
||||
contextProperty(name) {
|
||||
const computed = name === "catch";
|
||||
return _core.types.memberExpression(this.getContextId(), computed ? _core.types.stringLiteral(name) : _core.types.identifier(name), !!computed);
|
||||
}
|
||||
clearPendingException(tryLoc, assignee) {
|
||||
const catchCall = _core.types.callExpression(this.contextProperty("catch"), [_core.types.cloneNode(tryLoc)]);
|
||||
if (assignee) {
|
||||
this.emitAssign(assignee, catchCall);
|
||||
} else {
|
||||
this.emit(catchCall);
|
||||
}
|
||||
}
|
||||
jump(toLoc) {
|
||||
this.emitAssign(this.contextProperty(util.newHelpersAvailable(this.pluginPass) ? "n" : "next"), toLoc);
|
||||
this.emit(_core.types.breakStatement());
|
||||
}
|
||||
jumpIf(test, toLoc) {
|
||||
this.emit(_core.types.ifStatement(test, _core.types.blockStatement([this.assign(this.contextProperty(util.newHelpersAvailable(this.pluginPass) ? "n" : "next"), toLoc), _core.types.breakStatement()])));
|
||||
}
|
||||
jumpIfNot(test, toLoc) {
|
||||
let negatedTest;
|
||||
if (_core.types.isUnaryExpression(test) && test.operator === "!") {
|
||||
negatedTest = test.argument;
|
||||
} else {
|
||||
negatedTest = _core.types.unaryExpression("!", test);
|
||||
}
|
||||
this.emit(_core.types.ifStatement(negatedTest, _core.types.blockStatement([this.assign(this.contextProperty(util.newHelpersAvailable(this.pluginPass) ? "n" : "next"), toLoc), _core.types.breakStatement()])));
|
||||
}
|
||||
makeContextTempVar() {
|
||||
return this.contextProperty("t" + this.nextTempId++);
|
||||
}
|
||||
makeTempVar() {
|
||||
const id = this.scope.generateUidIdentifier("t");
|
||||
this.vars.push(_core.types.variableDeclarator(id));
|
||||
return _core.types.cloneNode(id);
|
||||
}
|
||||
getContextFunction() {
|
||||
return _core.types.functionExpression(null, [this.getContextId()], _core.types.blockStatement([this.getDispatchLoop()]), false, false);
|
||||
}
|
||||
getDispatchLoop() {
|
||||
const self = this;
|
||||
const cases = [];
|
||||
let current;
|
||||
let alreadyEnded = false;
|
||||
self.listing.forEach(function (stmt, i) {
|
||||
if (self.marked[i]) {
|
||||
cases.push(_core.types.switchCase(_core.types.numericLiteral(self.indexMap.get(i)), current = []));
|
||||
alreadyEnded = false;
|
||||
}
|
||||
if (!alreadyEnded) {
|
||||
current.push(stmt);
|
||||
if (_core.types.isCompletionStatement(stmt)) alreadyEnded = true;
|
||||
}
|
||||
});
|
||||
this.finalLoc.value = this.getIndex();
|
||||
if (util.newHelpersAvailable(this.pluginPass)) {
|
||||
if (this.lastReferenceIndex === this.index || !this.returns.has(this.listing.length)) {
|
||||
cases.push(_core.types.switchCase(this.finalLoc, [_core.types.returnStatement(_core.types.callExpression(this.contextProperty("a"), [_core.types.numericLiteral(2)]))]));
|
||||
}
|
||||
} else {
|
||||
cases.push(_core.types.switchCase(this.finalLoc, []), _core.types.switchCase(_core.types.stringLiteral("end"), [_core.types.returnStatement(_core.types.callExpression(this.contextProperty("stop"), []))]));
|
||||
}
|
||||
return _core.types.whileStatement(_core.types.numericLiteral(1), _core.types.switchStatement(util.newHelpersAvailable(this.pluginPass) ? this.tryEntries.length === 0 ? this.contextProperty("n") : _core.types.assignmentExpression("=", this.contextProperty("p"), this.contextProperty("n")) : _core.types.assignmentExpression("=", this.contextProperty("prev"), this.contextProperty("next")), cases));
|
||||
}
|
||||
getTryLocsList() {
|
||||
if (this.tryEntries.length === 0) {
|
||||
return null;
|
||||
}
|
||||
let lastLocValue = 0;
|
||||
const arrayExpression = _core.types.arrayExpression(this.tryEntries.map(function (tryEntry) {
|
||||
const thisLocValue = tryEntry.firstLoc.value;
|
||||
_assert.ok(thisLocValue >= lastLocValue, "try entries out of order");
|
||||
lastLocValue = thisLocValue;
|
||||
const ce = tryEntry.catchEntry;
|
||||
const fe = tryEntry.finallyEntry;
|
||||
const locs = [tryEntry.firstLoc, ce ? ce.firstLoc : null];
|
||||
if (fe) {
|
||||
locs[2] = fe.firstLoc;
|
||||
locs[3] = fe.afterLoc;
|
||||
}
|
||||
return _core.types.arrayExpression(locs.map(loc => loc && _core.types.cloneNode(loc)));
|
||||
}));
|
||||
if (util.newHelpersAvailable(this.pluginPass)) {
|
||||
arrayExpression.elements.reverse();
|
||||
}
|
||||
return arrayExpression;
|
||||
}
|
||||
explode(path, ignoreResult) {
|
||||
const node = path.node;
|
||||
const self = this;
|
||||
if (_core.types.isDeclaration(node)) throw getDeclError(node);
|
||||
if (path.isStatement()) return self.explodeStatement(path);
|
||||
if (path.isExpression()) return self.explodeExpression(path, ignoreResult);
|
||||
switch (node.type) {
|
||||
case "VariableDeclarator":
|
||||
throw getDeclError(node);
|
||||
case "ObjectProperty":
|
||||
case "SwitchCase":
|
||||
case "CatchClause":
|
||||
throw new Error(node.type + " nodes should be handled by their parents");
|
||||
default:
|
||||
throw new Error("unknown Node of type " + JSON.stringify(node.type));
|
||||
}
|
||||
}
|
||||
explodeStatement(path, labelId = null) {
|
||||
const stmt = path.node;
|
||||
const self = this;
|
||||
let before, after, head;
|
||||
if (path.isBlockStatement()) {
|
||||
path.get("body").forEach(function (path) {
|
||||
self.explodeStatement(path);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!meta.containsLeap(stmt)) {
|
||||
self.emit(stmt);
|
||||
return;
|
||||
}
|
||||
switch (path.type) {
|
||||
case "ExpressionStatement":
|
||||
self.explodeExpression(path.get("expression"), true);
|
||||
break;
|
||||
case "LabeledStatement":
|
||||
after = this.loc();
|
||||
self.leapManager.withEntry(new leap.LabeledEntry(after, path.node.label), function () {
|
||||
self.explodeStatement(path.get("body"), path.node.label);
|
||||
});
|
||||
self.mark(after);
|
||||
break;
|
||||
case "WhileStatement":
|
||||
before = this.loc();
|
||||
after = this.loc();
|
||||
self.mark(before);
|
||||
self.jumpIfNot(self.explodeExpression(path.get("test")), after);
|
||||
self.leapManager.withEntry(new leap.LoopEntry(after, before, labelId), function () {
|
||||
self.explodeStatement(path.get("body"));
|
||||
});
|
||||
self.jump(before);
|
||||
self.mark(after);
|
||||
break;
|
||||
case "DoWhileStatement":
|
||||
const first = this.loc();
|
||||
const test = this.loc();
|
||||
after = this.loc();
|
||||
self.mark(first);
|
||||
self.leapManager.withEntry(new leap.LoopEntry(after, test, labelId), function () {
|
||||
self.explode(path.get("body"));
|
||||
});
|
||||
self.mark(test);
|
||||
self.jumpIf(self.explodeExpression(path.get("test")), first);
|
||||
self.mark(after);
|
||||
break;
|
||||
case "ForStatement":
|
||||
head = this.loc();
|
||||
const update = this.loc();
|
||||
after = this.loc();
|
||||
if (path.node.init) {
|
||||
self.explode(path.get("init"), true);
|
||||
}
|
||||
self.mark(head);
|
||||
if (path.node.test) {
|
||||
self.jumpIfNot(self.explodeExpression(path.get("test")), after);
|
||||
} else {}
|
||||
self.leapManager.withEntry(new leap.LoopEntry(after, update, labelId), function () {
|
||||
self.explodeStatement(path.get("body"));
|
||||
});
|
||||
self.mark(update);
|
||||
if (path.node.update) {
|
||||
self.explode(path.get("update"), true);
|
||||
}
|
||||
self.jump(head);
|
||||
self.mark(after);
|
||||
break;
|
||||
case "TypeCastExpression":
|
||||
return self.explodeExpression(path.get("expression"));
|
||||
case "ForInStatement":
|
||||
head = this.loc();
|
||||
after = this.loc();
|
||||
const keyIterNextFn = self.makeTempVar();
|
||||
const helper = util.newHelpersAvailable(this.pluginPass) ? this.pluginPass.addHelper("regeneratorKeys") : util.runtimeProperty(this.pluginPass, "keys");
|
||||
self.emitAssign(keyIterNextFn, _core.types.callExpression(helper, [self.explodeExpression(path.get("right"))]));
|
||||
self.mark(head);
|
||||
const keyInfoTmpVar = self.makeTempVar();
|
||||
self.jumpIf(_core.types.memberExpression(_core.types.assignmentExpression("=", keyInfoTmpVar, _core.types.callExpression(_core.types.cloneNode(keyIterNextFn), [])), _core.types.identifier("done"), false), after);
|
||||
self.emitAssign(path.node.left, _core.types.memberExpression(_core.types.cloneNode(keyInfoTmpVar), _core.types.identifier("value"), false));
|
||||
self.leapManager.withEntry(new leap.LoopEntry(after, head, labelId), function () {
|
||||
self.explodeStatement(path.get("body"));
|
||||
});
|
||||
self.jump(head);
|
||||
self.mark(after);
|
||||
break;
|
||||
case "BreakStatement":
|
||||
self.emitAbruptCompletion({
|
||||
type: 3,
|
||||
target: self.leapManager.getBreakLoc(path.node.label)
|
||||
});
|
||||
break;
|
||||
case "ContinueStatement":
|
||||
self.emitAbruptCompletion({
|
||||
type: 3,
|
||||
target: self.leapManager.getContinueLoc(path.node.label)
|
||||
});
|
||||
break;
|
||||
case "SwitchStatement":
|
||||
const disc = self.emitAssign(self.makeTempVar(), self.explodeExpression(path.get("discriminant")));
|
||||
after = this.loc();
|
||||
const defaultLoc = this.loc();
|
||||
let condition = defaultLoc;
|
||||
const caseLocs = [];
|
||||
const cases = path.node.cases || [];
|
||||
for (let i = cases.length - 1; i >= 0; --i) {
|
||||
const c = cases[i];
|
||||
if (c.test) {
|
||||
condition = _core.types.conditionalExpression(_core.types.binaryExpression("===", _core.types.cloneNode(disc), c.test), caseLocs[i] = this.loc(), condition);
|
||||
} else {
|
||||
caseLocs[i] = defaultLoc;
|
||||
}
|
||||
}
|
||||
const discriminant = path.get("discriminant");
|
||||
discriminant.replaceWith(condition);
|
||||
self.jump(self.explodeExpression(discriminant));
|
||||
self.leapManager.withEntry(new leap.SwitchEntry(after), function () {
|
||||
path.get("cases").forEach(function (casePath) {
|
||||
const i = casePath.key;
|
||||
self.mark(caseLocs[i]);
|
||||
casePath.get("consequent").forEach(function (path) {
|
||||
self.explodeStatement(path);
|
||||
});
|
||||
});
|
||||
});
|
||||
self.mark(after);
|
||||
if (defaultLoc.value === PENDING_LOCATION) {
|
||||
self.mark(defaultLoc);
|
||||
_assert.strictEqual(after.value, defaultLoc.value);
|
||||
}
|
||||
break;
|
||||
case "IfStatement":
|
||||
const elseLoc = path.node.alternate && this.loc();
|
||||
after = this.loc();
|
||||
self.jumpIfNot(self.explodeExpression(path.get("test")), elseLoc || after);
|
||||
self.explodeStatement(path.get("consequent"));
|
||||
if (elseLoc) {
|
||||
self.jump(after);
|
||||
self.mark(elseLoc);
|
||||
self.explodeStatement(path.get("alternate"));
|
||||
}
|
||||
self.mark(after);
|
||||
break;
|
||||
case "ReturnStatement":
|
||||
self.emitAbruptCompletion({
|
||||
type: 2,
|
||||
value: self.explodeExpression(path.get("argument"))
|
||||
});
|
||||
break;
|
||||
case "WithStatement":
|
||||
throw new Error("WithStatement not supported in generator functions.");
|
||||
case "TryStatement":
|
||||
after = this.loc();
|
||||
const handler = path.node.handler;
|
||||
const catchLoc = handler && this.loc();
|
||||
const catchEntry = catchLoc && new leap.CatchEntry(catchLoc, handler.param);
|
||||
const finallyLoc = path.node.finalizer && this.loc();
|
||||
const finallyEntry = finallyLoc && new leap.FinallyEntry(finallyLoc, after);
|
||||
const tryEntry = new leap.TryEntry(self.getUnmarkedCurrentLoc(), catchEntry, finallyEntry);
|
||||
self.tryEntries.push(tryEntry);
|
||||
self.updateContextPrevLoc(tryEntry.firstLoc);
|
||||
self.leapManager.withEntry(tryEntry, () => {
|
||||
self.explodeStatement(path.get("block"));
|
||||
if (catchLoc) {
|
||||
const body = path.node.block.body;
|
||||
if (finallyLoc) {
|
||||
self.jump(finallyLoc);
|
||||
} else if (body.length && body[body.length - 1].type === "ReturnStatement") {
|
||||
after = null;
|
||||
} else {
|
||||
self.jump(after);
|
||||
}
|
||||
self.updateContextPrevLoc(self.mark(catchLoc));
|
||||
const bodyPath = path.get("handler.body");
|
||||
const safeParam = self.makeTempVar();
|
||||
if (util.newHelpersAvailable(this.pluginPass)) {
|
||||
this.emitAssign(safeParam, self.contextProperty("v"));
|
||||
} else {
|
||||
self.clearPendingException(tryEntry.firstLoc, safeParam);
|
||||
}
|
||||
bodyPath.traverse(catchParamVisitor, {
|
||||
getSafeParam: () => _core.types.cloneNode(safeParam),
|
||||
catchParamName: handler.param.name
|
||||
});
|
||||
self.leapManager.withEntry(catchEntry, function () {
|
||||
self.explodeStatement(bodyPath);
|
||||
});
|
||||
}
|
||||
if (finallyLoc) {
|
||||
self.updateContextPrevLoc(self.mark(finallyLoc));
|
||||
self.leapManager.withEntry(finallyEntry, function () {
|
||||
self.explodeStatement(path.get("finalizer"));
|
||||
});
|
||||
self.emit(_core.types.returnStatement(_core.types.callExpression(self.contextProperty(util.newHelpersAvailable(this.pluginPass) ? "f" : "finish"), [finallyEntry.firstLoc])));
|
||||
}
|
||||
});
|
||||
if (after) self.mark(after);
|
||||
break;
|
||||
case "ThrowStatement":
|
||||
self.emit(_core.types.throwStatement(self.explodeExpression(path.get("argument"))));
|
||||
break;
|
||||
case "ClassDeclaration":
|
||||
self.emit(self.explodeClass(path));
|
||||
break;
|
||||
default:
|
||||
throw new Error("unknown Statement of type " + JSON.stringify(stmt.type));
|
||||
}
|
||||
}
|
||||
emitAbruptCompletion(record) {
|
||||
const abruptArgs = [util.newHelpersAvailable(this.pluginPass) ? _core.types.numericLiteral(record.type) : _core.types.stringLiteral(record.type === 3 ? "continue" : "return")];
|
||||
if (record.type === 3) {
|
||||
abruptArgs[1] = this.insertedLocs.has(record.target) ? record.target : _core.types.cloneNode(record.target);
|
||||
} else if (record.type === 2) {
|
||||
if (record.value) {
|
||||
abruptArgs[1] = _core.types.cloneNode(record.value);
|
||||
}
|
||||
}
|
||||
this.emit(_core.types.returnStatement(_core.types.callExpression(this.contextProperty(util.newHelpersAvailable(this.pluginPass) ? "a" : "abrupt"), abruptArgs)));
|
||||
if (record.type === 2) {
|
||||
this.returns.add(this.listing.length);
|
||||
}
|
||||
}
|
||||
getUnmarkedCurrentLoc() {
|
||||
return _core.types.numericLiteral(this.getIndex());
|
||||
}
|
||||
updateContextPrevLoc(loc) {
|
||||
if (loc) {
|
||||
if (loc.value === PENDING_LOCATION) {
|
||||
loc.value = this.getIndex();
|
||||
} else {
|
||||
_assert.strictEqual(loc.value, this.index);
|
||||
}
|
||||
} else {
|
||||
loc = this.getUnmarkedCurrentLoc();
|
||||
}
|
||||
this.emitAssign(this.contextProperty(util.newHelpersAvailable(this.pluginPass) ? "p" : "prev"), loc);
|
||||
}
|
||||
explodeViaTempVar(tempVar, childPath, hasLeapingChildren, ignoreChildResult) {
|
||||
_assert.ok(!ignoreChildResult || !tempVar, "Ignoring the result of a child expression but forcing it to " + "be assigned to a temporary variable?");
|
||||
let result = this.explodeExpression(childPath, ignoreChildResult);
|
||||
if (ignoreChildResult) {} else if (tempVar || hasLeapingChildren && !_core.types.isLiteral(result)) {
|
||||
result = this.emitAssign(tempVar || this.makeTempVar(), result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
explodeExpression(path, ignoreResult) {
|
||||
const expr = path.node;
|
||||
if (!expr) {
|
||||
return expr;
|
||||
}
|
||||
const self = this;
|
||||
let result;
|
||||
let after;
|
||||
function finish(expr) {
|
||||
if (ignoreResult) {
|
||||
self.emit(expr);
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
if (!meta.containsLeap(expr)) {
|
||||
return finish(expr);
|
||||
}
|
||||
const hasLeapingChildren = meta.containsLeap.onlyChildren(expr);
|
||||
switch (path.type) {
|
||||
case "MemberExpression":
|
||||
return finish(_core.types.memberExpression(self.explodeExpression(path.get("object")), path.node.computed ? self.explodeViaTempVar(null, path.get("property"), hasLeapingChildren) : path.node.property, path.node.computed));
|
||||
case "CallExpression":
|
||||
const calleePath = path.get("callee");
|
||||
const argsPath = path.get("arguments");
|
||||
let newCallee;
|
||||
let newArgs;
|
||||
let lastLeapingArgIndex = argsPath.length - 1;
|
||||
while (lastLeapingArgIndex >= 0 && !meta.containsLeap(argsPath[lastLeapingArgIndex].node)) {
|
||||
lastLeapingArgIndex--;
|
||||
}
|
||||
let injectFirstArg = null;
|
||||
if (_core.types.isMemberExpression(calleePath.node)) {
|
||||
if (lastLeapingArgIndex !== -1) {
|
||||
const newObject = self.explodeViaTempVar(self.makeTempVar(), calleePath.get("object"), hasLeapingChildren);
|
||||
const newProperty = calleePath.node.computed ? self.explodeViaTempVar(null, calleePath.get("property"), hasLeapingChildren) : calleePath.node.property;
|
||||
injectFirstArg = newObject;
|
||||
newCallee = _core.types.memberExpression(_core.types.memberExpression(_core.types.cloneNode(newObject), newProperty, calleePath.node.computed), _core.types.identifier("call"), false);
|
||||
} else {
|
||||
newCallee = self.explodeExpression(calleePath);
|
||||
}
|
||||
} else {
|
||||
newCallee = self.explodeViaTempVar(null, calleePath, hasLeapingChildren);
|
||||
if (_core.types.isMemberExpression(newCallee)) {
|
||||
newCallee = _core.types.sequenceExpression([_core.types.numericLiteral(0), _core.types.cloneNode(newCallee)]);
|
||||
}
|
||||
}
|
||||
if (lastLeapingArgIndex !== -1) {
|
||||
newArgs = argsPath.map((argPath, index) => index >= lastLeapingArgIndex ? self.explodeExpression(argPath) : self.explodeViaTempVar(null, argPath, hasLeapingChildren));
|
||||
if (injectFirstArg) newArgs.unshift(injectFirstArg);
|
||||
newArgs = newArgs.map(arg => _core.types.cloneNode(arg));
|
||||
} else {
|
||||
newArgs = path.node.arguments;
|
||||
}
|
||||
return finish(_core.types.callExpression(newCallee, newArgs));
|
||||
case "NewExpression":
|
||||
return finish(_core.types.newExpression(self.explodeViaTempVar(null, path.get("callee"), hasLeapingChildren), path.get("arguments").map(function (argPath) {
|
||||
return self.explodeViaTempVar(null, argPath, hasLeapingChildren);
|
||||
})));
|
||||
case "ObjectExpression":
|
||||
return finish(_core.types.objectExpression(path.get("properties").map(function (propPath) {
|
||||
if (propPath.isObjectProperty()) {
|
||||
return _core.types.objectProperty(propPath.node.key, self.explodeViaTempVar(null, propPath.get("value"), hasLeapingChildren), propPath.node.computed);
|
||||
} else {
|
||||
return propPath.node;
|
||||
}
|
||||
})));
|
||||
case "ArrayExpression":
|
||||
return finish(_core.types.arrayExpression(path.get("elements").map(function (elemPath) {
|
||||
if (!elemPath.node) {
|
||||
return null;
|
||||
}
|
||||
if (elemPath.isSpreadElement()) {
|
||||
return _core.types.spreadElement(self.explodeViaTempVar(null, elemPath.get("argument"), hasLeapingChildren));
|
||||
} else {
|
||||
return self.explodeViaTempVar(null, elemPath, hasLeapingChildren);
|
||||
}
|
||||
})));
|
||||
case "SequenceExpression":
|
||||
const lastIndex = path.node.expressions.length - 1;
|
||||
path.get("expressions").forEach(function (exprPath) {
|
||||
if (exprPath.key === lastIndex) {
|
||||
result = self.explodeExpression(exprPath, ignoreResult);
|
||||
} else {
|
||||
self.explodeExpression(exprPath, true);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
case "LogicalExpression":
|
||||
after = this.loc();
|
||||
if (!ignoreResult) {
|
||||
result = self.makeTempVar();
|
||||
}
|
||||
const left = self.explodeViaTempVar(result, path.get("left"), hasLeapingChildren);
|
||||
if (path.node.operator === "&&") {
|
||||
self.jumpIfNot(left, after);
|
||||
} else {
|
||||
_assert.strictEqual(path.node.operator, "||");
|
||||
self.jumpIf(left, after);
|
||||
}
|
||||
self.explodeViaTempVar(result, path.get("right"), hasLeapingChildren, ignoreResult);
|
||||
self.mark(after);
|
||||
return result;
|
||||
case "ConditionalExpression":
|
||||
const elseLoc = this.loc();
|
||||
after = this.loc();
|
||||
const test = self.explodeExpression(path.get("test"));
|
||||
self.jumpIfNot(test, elseLoc);
|
||||
if (!ignoreResult) {
|
||||
result = self.makeTempVar();
|
||||
}
|
||||
self.explodeViaTempVar(result, path.get("consequent"), hasLeapingChildren, ignoreResult);
|
||||
self.jump(after);
|
||||
self.mark(elseLoc);
|
||||
self.explodeViaTempVar(result, path.get("alternate"), hasLeapingChildren, ignoreResult);
|
||||
self.mark(after);
|
||||
return result;
|
||||
case "UnaryExpression":
|
||||
return finish(_core.types.unaryExpression(path.node.operator, self.explodeExpression(path.get("argument")), !!path.node.prefix));
|
||||
case "BinaryExpression":
|
||||
return finish(_core.types.binaryExpression(path.node.operator, self.explodeViaTempVar(null, path.get("left"), hasLeapingChildren), self.explodeViaTempVar(null, path.get("right"), hasLeapingChildren)));
|
||||
case "AssignmentExpression":
|
||||
if (path.node.operator === "=") {
|
||||
return finish(_core.types.assignmentExpression(path.node.operator, self.explodeExpression(path.get("left")), self.explodeExpression(path.get("right"))));
|
||||
}
|
||||
const lhs = self.explodeExpression(path.get("left"));
|
||||
const temp = self.emitAssign(self.makeTempVar(), lhs);
|
||||
return finish(_core.types.assignmentExpression("=", _core.types.cloneNode(lhs), _core.types.assignmentExpression(path.node.operator, _core.types.cloneNode(temp), self.explodeExpression(path.get("right")))));
|
||||
case "UpdateExpression":
|
||||
return finish(_core.types.updateExpression(path.node.operator, self.explodeExpression(path.get("argument")), path.node.prefix));
|
||||
case "YieldExpression":
|
||||
after = this.loc();
|
||||
const arg = path.node.argument && self.explodeExpression(path.get("argument"));
|
||||
if (arg && path.node.delegate) {
|
||||
if (util.newHelpersAvailable(this.pluginPass)) {
|
||||
const ret = _core.types.returnStatement(_core.types.callExpression(self.contextProperty("d"), [_core.types.callExpression(this.pluginPass.addHelper("regeneratorValues"), [arg]), after]));
|
||||
ret.loc = expr.loc;
|
||||
self.emit(ret);
|
||||
self.mark(after);
|
||||
return self.contextProperty("v");
|
||||
} else {
|
||||
const result = self.makeContextTempVar();
|
||||
const ret = _core.types.returnStatement(_core.types.callExpression(self.contextProperty("delegateYield"), [arg, _core.types.stringLiteral(result.property.name), after]));
|
||||
ret.loc = expr.loc;
|
||||
self.emit(ret);
|
||||
self.mark(after);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
self.emitAssign(self.contextProperty(util.newHelpersAvailable(this.pluginPass) ? "n" : "next"), after);
|
||||
const ret = _core.types.returnStatement(_core.types.cloneNode(arg) || null);
|
||||
ret.loc = expr.loc;
|
||||
self.emit(ret);
|
||||
self.mark(after);
|
||||
return self.contextProperty(util.newHelpersAvailable(self.pluginPass) ? "v" : "sent");
|
||||
case "ClassExpression":
|
||||
return finish(self.explodeClass(path));
|
||||
default:
|
||||
throw new Error("unknown Expression of type " + JSON.stringify(expr.type));
|
||||
}
|
||||
}
|
||||
explodeClass(path) {
|
||||
const explodingChildren = [];
|
||||
if (path.node.superClass) {
|
||||
explodingChildren.push(path.get("superClass"));
|
||||
}
|
||||
path.get("body.body").forEach(member => {
|
||||
if (member.node.computed) {
|
||||
explodingChildren.push(member.get("key"));
|
||||
}
|
||||
});
|
||||
const hasLeapingChildren = explodingChildren.some(child => meta.containsLeap(child.node));
|
||||
for (let i = 0; i < explodingChildren.length; i++) {
|
||||
const child = explodingChildren[i];
|
||||
const isLast = i === explodingChildren.length - 1;
|
||||
if (isLast) {
|
||||
child.replaceWith(this.explodeExpression(child));
|
||||
} else {
|
||||
child.replaceWith(this.explodeViaTempVar(null, child, hasLeapingChildren));
|
||||
}
|
||||
}
|
||||
return path.node;
|
||||
}
|
||||
}
|
||||
exports.Emitter = Emitter;
|
||||
|
||||
//# sourceMappingURL=emit.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_assert","require","leap","meta","util","_core","PENDING_LOCATION","Number","MAX_VALUE","getDeclError","node","Error","JSON","stringify","catchParamVisitor","Identifier","path","state","name","catchParamName","isReference","replaceWith","getSafeParam","Scope","scope","hasOwnBinding","skip","Emitter","constructor","contextId","vars","pluginPass","nextTempId","index","indexMap","listing","returns","lastReferenceIndex","marked","insertedLocs","finalLoc","tryEntries","leapManager","Map","Set","loc","LeapManager","l","t","numericLiteral","add","getInsertedLocs","getContextId","cloneNode","getIndex","has","length","set","mark","value","assert","strictEqual","emit","isExpression","expressionStatement","assertStatement","push","emitAssign","lhs","rhs","assign","assignmentExpression","contextProperty","computed","memberExpression","stringLiteral","identifier","clearPendingException","tryLoc","assignee","catchCall","callExpression","jump","toLoc","newHelpersAvailable","breakStatement","jumpIf","test","ifStatement","blockStatement","jumpIfNot","negatedTest","isUnaryExpression","operator","argument","unaryExpression","makeContextTempVar","makeTempVar","id","generateUidIdentifier","variableDeclarator","getContextFunction","functionExpression","getDispatchLoop","self","cases","current","alreadyEnded","forEach","stmt","i","switchCase","get","isCompletionStatement","returnStatement","whileStatement","switchStatement","getTryLocsList","lastLocValue","arrayExpression","map","tryEntry","thisLocValue","firstLoc","ok","ce","catchEntry","fe","finallyEntry","locs","afterLoc","elements","reverse","explode","ignoreResult","isDeclaration","isStatement","explodeStatement","explodeExpression","type","labelId","before","after","head","isBlockStatement","containsLeap","withEntry","LabeledEntry","label","LoopEntry","first","update","init","keyIterNextFn","helper","addHelper","runtimeProperty","keyInfoTmpVar","left","emitAbruptCompletion","target","getBreakLoc","getContinueLoc","disc","defaultLoc","condition","caseLocs","c","conditionalExpression","binaryExpression","discriminant","SwitchEntry","casePath","key","elseLoc","alternate","handler","catchLoc","CatchEntry","param","finallyLoc","finalizer","FinallyEntry","TryEntry","getUnmarkedCurrentLoc","updateContextPrevLoc","body","block","bodyPath","safeParam","traverse","throwStatement","explodeClass","record","abruptArgs","explodeViaTempVar","tempVar","childPath","hasLeapingChildren","ignoreChildResult","result","isLiteral","expr","finish","onlyChildren","property","calleePath","argsPath","newCallee","newArgs","lastLeapingArgIndex","injectFirstArg","isMemberExpression","newObject","newProperty","sequenceExpression","argPath","unshift","arg","arguments","newExpression","objectExpression","propPath","isObjectProperty","objectProperty","elemPath","isSpreadElement","spreadElement","lastIndex","expressions","exprPath","prefix","temp","updateExpression","delegate","ret","explodingChildren","superClass","member","some","child","isLast","exports"],"sources":["../../src/regenerator/emit.ts"],"sourcesContent":["/* eslint-disable no-case-declarations */\nimport assert from \"node:assert\";\nimport * as leap from \"./leap.ts\";\nimport * as meta from \"./meta.ts\";\nimport * as util from \"./util.ts\";\n\nimport type { NodePath, PluginPass, Visitor, Scope } from \"@babel/core\";\nimport { types as t } from \"@babel/core\";\n\n// From packages/babel-helpers/src/helpers/regenerator.ts\nconst enum OperatorType {\n Return = 2,\n Jump,\n}\n\ntype AbruptCompletion =\n | {\n type: OperatorType.Jump;\n target: t.NumericLiteral;\n }\n | {\n type: OperatorType.Return;\n value: t.Expression | null;\n };\n\n// Offsets into this.listing that could be used as targets for branches or\n// jumps are represented as numeric Literal nodes. This representation has\n// the amazingly convenient benefit of allowing the exact value of the\n// location to be determined at any time, even after generating code that\n// refers to the location.\n// We use 'Number.MAX_VALUE' to mark uninitialized location. We can safely do\n// so because no code can realistically have about 1.8e+308 locations before\n// hitting memory limit of the machine it's running on. For comparison, the\n// estimated number of atoms in the observable universe is around 1e+80.\nconst PENDING_LOCATION = Number.MAX_VALUE;\n\nfunction getDeclError(node: t.Node) {\n return new Error(\n \"all declarations should have been transformed into \" +\n \"assignments before the Exploder began its work: \" +\n JSON.stringify(node),\n );\n}\n\nconst catchParamVisitor: Visitor<{\n getSafeParam: () => t.Identifier;\n catchParamName: string;\n}> = {\n Identifier: function (path, state) {\n if (path.node.name === state.catchParamName && util.isReference(path)) {\n path.replaceWith(state.getSafeParam());\n }\n },\n\n Scope: function (path, state) {\n if (path.scope.hasOwnBinding(state.catchParaLine truncated
|
||||
Generated
Vendored
+100
@@ -0,0 +1,100 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.hoist = hoist;
|
||||
var _core = require("@babel/core");
|
||||
function hoist(funPath) {
|
||||
_core.types.assertFunction(funPath.node);
|
||||
const vars = {
|
||||
__proto__: null
|
||||
};
|
||||
function varDeclToExpr({
|
||||
node: vdec
|
||||
}, includeIdentifiers) {
|
||||
_core.types.assertVariableDeclaration(vdec);
|
||||
const exprs = [];
|
||||
vdec.declarations.forEach(function (dec) {
|
||||
vars[dec.id.name] = _core.types.identifier(dec.id.name);
|
||||
if (dec.init) {
|
||||
exprs.push(_core.types.assignmentExpression("=", dec.id, dec.init));
|
||||
} else if (includeIdentifiers) {
|
||||
exprs.push(dec.id);
|
||||
}
|
||||
});
|
||||
if (exprs.length === 0) return null;
|
||||
if (exprs.length === 1) return exprs[0];
|
||||
return _core.types.sequenceExpression(exprs);
|
||||
}
|
||||
funPath.get("body").traverse({
|
||||
VariableDeclaration: {
|
||||
exit: function (path) {
|
||||
const expr = varDeclToExpr(path, false);
|
||||
if (expr === null) {
|
||||
path.remove();
|
||||
} else {
|
||||
for (const name of Object.keys(vars)) {
|
||||
path.scope.removeBinding(name);
|
||||
}
|
||||
path.replaceWith(_core.types.expressionStatement(expr));
|
||||
}
|
||||
path.skip();
|
||||
}
|
||||
},
|
||||
ForStatement: function (path) {
|
||||
const init = path.get("init");
|
||||
if (init.isVariableDeclaration()) {
|
||||
const expr = varDeclToExpr(init, false);
|
||||
if (expr) {
|
||||
init.replaceWith(expr);
|
||||
} else {
|
||||
init.remove();
|
||||
}
|
||||
}
|
||||
},
|
||||
ForXStatement: function (path) {
|
||||
const left = path.get("left");
|
||||
if (left.isVariableDeclaration()) {
|
||||
left.replaceWith(varDeclToExpr(left, true));
|
||||
}
|
||||
},
|
||||
FunctionDeclaration: function (path) {
|
||||
const node = path.node;
|
||||
vars[node.id.name] = node.id;
|
||||
const assignment = _core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(node.id), _core.types.functionExpression(path.scope.generateUidIdentifierBasedOnNode(node), node.params, node.body, node.generator, node.async)));
|
||||
if (path.parentPath.isBlockStatement()) {
|
||||
path.parentPath.unshiftContainer("body", assignment);
|
||||
path.remove();
|
||||
} else {
|
||||
path.replaceWith(assignment);
|
||||
path.scope.removeBinding(node.id.name);
|
||||
}
|
||||
path.skip();
|
||||
},
|
||||
FunctionExpression: function (path) {
|
||||
path.skip();
|
||||
},
|
||||
ArrowFunctionExpression: function (path) {
|
||||
path.skip();
|
||||
}
|
||||
});
|
||||
const paramNames = {
|
||||
__proto__: null
|
||||
};
|
||||
funPath.get("params").forEach(function (paramPath) {
|
||||
const param = paramPath.node;
|
||||
if (_core.types.isIdentifier(param)) {
|
||||
paramNames[param.name] = param;
|
||||
} else {}
|
||||
});
|
||||
const declarations = [];
|
||||
Object.keys(vars).forEach(function (name) {
|
||||
if (!hasOwnProperty.call(paramNames, name)) {
|
||||
declarations.push(_core.types.variableDeclarator(vars[name], null));
|
||||
}
|
||||
});
|
||||
return declarations;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=hoist.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_core","require","hoist","funPath","t","assertFunction","node","vars","__proto__","varDeclToExpr","vdec","includeIdentifiers","assertVariableDeclaration","exprs","declarations","forEach","dec","id","name","identifier","init","push","assignmentExpression","length","sequenceExpression","get","traverse","VariableDeclaration","exit","path","expr","remove","Object","keys","scope","removeBinding","replaceWith","expressionStatement","skip","ForStatement","isVariableDeclaration","ForXStatement","left","FunctionDeclaration","assignment","cloneNode","functionExpression","generateUidIdentifierBasedOnNode","params","body","generator","async","parentPath","isBlockStatement","unshiftContainer","FunctionExpression","ArrowFunctionExpression","paramNames","paramPath","param","isIdentifier","hasOwnProperty","call","variableDeclarator"],"sources":["../../src/regenerator/hoist.ts"],"sourcesContent":["import type { NodePath } from \"@babel/core\";\nimport { types as t } from \"@babel/core\";\n\n// The hoist function takes a FunctionExpression or FunctionDeclaration\n// and replaces any Declaration nodes in its body with assignments, then\n// returns a VariableDeclaration containing just the names of the removed\n// declarations.\nexport function hoist(\n funPath: NodePath<t.FunctionExpression | t.FunctionDeclaration>,\n) {\n t.assertFunction(funPath.node);\n\n const vars: Record<string, t.Identifier> = { __proto__: null };\n\n function varDeclToExpr(\n { node: vdec }: NodePath,\n includeIdentifiers: boolean,\n ) {\n t.assertVariableDeclaration(vdec);\n // TODO assert.equal(vdec.kind, \"var\");\n const exprs: t.Expression[] = [];\n\n vdec.declarations.forEach(function (\n dec: t.VariableDeclarator & { id: t.Identifier },\n ) {\n // Note: We duplicate 'dec.id' here to ensure that the variable declaration IDs don't\n // have the same 'loc' value, since that can make sourcemaps and retainLines behave poorly.\n vars[dec.id.name] = t.identifier(dec.id.name);\n\n if (dec.init) {\n exprs.push(t.assignmentExpression(\"=\", dec.id, dec.init));\n } else if (includeIdentifiers) {\n exprs.push(dec.id);\n }\n });\n\n if (exprs.length === 0) return null;\n\n if (exprs.length === 1) return exprs[0];\n\n return t.sequenceExpression(exprs);\n }\n\n funPath.get(\"body\").traverse({\n VariableDeclaration: {\n exit: function (path) {\n const expr = varDeclToExpr(path, false);\n if (expr === null) {\n path.remove();\n } else {\n for (const name of Object.keys(vars)) {\n // Remove the binding, to avoid \"duplicate declaration\" errors when it will\n // be injected again.\n path.scope.removeBinding(name);\n }\n\n // We don't need to traverse this expression any further because\n // there can't be any new declarations inside an expression.\n path.replaceWith(t.expressionStatement(expr));\n }\n\n // Since the original node has been either removed or replaced,\n // avoid traversing it any further.\n path.skip();\n },\n },\n\n ForStatement: function (path) {\n const init = path.get(\"init\");\n if (init.isVariableDeclaration()) {\n const expr = varDeclToExpr(init, false);\n if (expr) {\n init.replaceWith(expr);\n } else {\n init.remove();\n }\n }\n },\n\n ForXStatement: function (path) {\n const left = path.get(\"left\");\n if (left.isVariableDeclaration()) {\n left.replaceWith(varDeclToExpr(left, true));\n }\n },\n\n FunctionDeclaration: function (path) {\n const node = path.node;\n vars[node.id.name] = node.id;\n\n const assignment = t.expressionStatement(\n t.assignmentExpression(\n \"=\",\n t.cloneNode(node.id),\n t.functionExpression(\n path.scope.generateUidIdentifierBasedOnNode(node),\n node.params,\n node.body,\n node.generator,\n node.async,\n ),\n ),\n );\n\n if (path.parentPath.isBlockStatement()) {\n // Insert the assignment form before the first statement in the\n // enclosing block.\n path.parentPath.unshiftContainer(\"body\", assignment);\n\n // Remove the function declaration now that we've inserted the\n // equivalent assignment form at the beginning of the block.\n path.remove();\n } else {\n // If the parent node is not a block statement, then we can just\n // replace the declaration with the equivalent assignment form\n // without worrying about hoisting it.\n path.replaceWith(assignment);\n\n // Remove the binding, to avoid \"duplicate declaration\" errors when it will\n // be injected again.\n path.scope.removeBinding(node.id.name);\n }\n\n // DoLine truncated
|
||||
Generated
Vendored
+122
@@ -0,0 +1,122 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.TryEntry = exports.SwitchEntry = exports.LoopEntry = exports.LeapManager = exports.LabeledEntry = exports.FunctionEntry = exports.FinallyEntry = exports.Entry = exports.CatchEntry = void 0;
|
||||
var _assert = require("assert");
|
||||
class Entry {}
|
||||
exports.Entry = Entry;
|
||||
class FunctionEntry extends Entry {
|
||||
constructor(returnLoc) {
|
||||
super();
|
||||
this.returnLoc = void 0;
|
||||
this.returnLoc = returnLoc;
|
||||
}
|
||||
}
|
||||
exports.FunctionEntry = FunctionEntry;
|
||||
class LoopEntry extends Entry {
|
||||
constructor(breakLoc, continueLoc, label = null) {
|
||||
super();
|
||||
this.breakLoc = void 0;
|
||||
this.continueLoc = void 0;
|
||||
this.label = void 0;
|
||||
this.breakLoc = breakLoc;
|
||||
this.continueLoc = continueLoc;
|
||||
this.label = label;
|
||||
}
|
||||
}
|
||||
exports.LoopEntry = LoopEntry;
|
||||
class SwitchEntry extends Entry {
|
||||
constructor(breakLoc) {
|
||||
super();
|
||||
this.breakLoc = void 0;
|
||||
this.breakLoc = breakLoc;
|
||||
}
|
||||
}
|
||||
exports.SwitchEntry = SwitchEntry;
|
||||
class TryEntry extends Entry {
|
||||
constructor(firstLoc, catchEntry = null, finallyEntry = null) {
|
||||
super();
|
||||
this.firstLoc = void 0;
|
||||
this.catchEntry = void 0;
|
||||
this.finallyEntry = void 0;
|
||||
_assert.ok(catchEntry || finallyEntry);
|
||||
this.firstLoc = firstLoc;
|
||||
this.catchEntry = catchEntry;
|
||||
this.finallyEntry = finallyEntry;
|
||||
}
|
||||
}
|
||||
exports.TryEntry = TryEntry;
|
||||
class CatchEntry extends Entry {
|
||||
constructor(firstLoc, paramId) {
|
||||
super();
|
||||
this.firstLoc = void 0;
|
||||
this.paramId = void 0;
|
||||
this.firstLoc = firstLoc;
|
||||
this.paramId = paramId;
|
||||
}
|
||||
}
|
||||
exports.CatchEntry = CatchEntry;
|
||||
class FinallyEntry extends Entry {
|
||||
constructor(firstLoc, afterLoc) {
|
||||
super();
|
||||
this.firstLoc = void 0;
|
||||
this.afterLoc = void 0;
|
||||
this.firstLoc = firstLoc;
|
||||
this.afterLoc = afterLoc;
|
||||
}
|
||||
}
|
||||
exports.FinallyEntry = FinallyEntry;
|
||||
class LabeledEntry extends Entry {
|
||||
constructor(breakLoc, label) {
|
||||
super();
|
||||
this.breakLoc = void 0;
|
||||
this.label = void 0;
|
||||
this.breakLoc = breakLoc;
|
||||
this.label = label;
|
||||
}
|
||||
}
|
||||
exports.LabeledEntry = LabeledEntry;
|
||||
class LeapManager {
|
||||
constructor(emitter) {
|
||||
this.emitter = void 0;
|
||||
this.entryStack = void 0;
|
||||
this.emitter = emitter;
|
||||
this.entryStack = [new FunctionEntry(emitter.finalLoc)];
|
||||
}
|
||||
withEntry(entry, callback) {
|
||||
this.entryStack.push(entry);
|
||||
try {
|
||||
callback.call(this.emitter);
|
||||
} finally {
|
||||
const popped = this.entryStack.pop();
|
||||
_assert.strictEqual(popped, entry);
|
||||
}
|
||||
}
|
||||
_findLeapLocation(property, label) {
|
||||
for (let i = this.entryStack.length - 1; i >= 0; --i) {
|
||||
const entry = this.entryStack[i];
|
||||
const loc = entry[property];
|
||||
if (loc) {
|
||||
if (label) {
|
||||
if (entry.label && entry.label.name === label.name) {
|
||||
return loc;
|
||||
}
|
||||
} else if (entry instanceof LabeledEntry) {} else {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
getBreakLoc(label) {
|
||||
return this._findLeapLocation("breakLoc", label);
|
||||
}
|
||||
getContinueLoc(label) {
|
||||
return this._findLeapLocation("continueLoc", label);
|
||||
}
|
||||
}
|
||||
exports.LeapManager = LeapManager;
|
||||
|
||||
//# sourceMappingURL=leap.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_assert","require","Entry","exports","FunctionEntry","constructor","returnLoc","LoopEntry","breakLoc","continueLoc","label","SwitchEntry","TryEntry","firstLoc","catchEntry","finallyEntry","assert","ok","CatchEntry","paramId","FinallyEntry","afterLoc","LabeledEntry","LeapManager","emitter","entryStack","finalLoc","withEntry","entry","callback","push","call","popped","pop","strictEqual","_findLeapLocation","property","i","length","loc","name","getBreakLoc","getContinueLoc"],"sources":["../../src/regenerator/leap.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport type { Emitter } from \"./emit.ts\";\nimport type { types as t } from \"@babel/core\";\n\nexport class Entry {}\n\nexport class FunctionEntry extends Entry {\n returnLoc: t.NumericLiteral;\n\n constructor(returnLoc: t.NumericLiteral) {\n super();\n this.returnLoc = returnLoc;\n }\n}\n\nexport class LoopEntry extends Entry {\n breakLoc: t.NumericLiteral;\n continueLoc: t.NumericLiteral;\n label: t.Identifier;\n\n constructor(\n breakLoc: t.NumericLiteral,\n continueLoc: t.NumericLiteral,\n label: t.Identifier = null,\n ) {\n super();\n this.breakLoc = breakLoc;\n this.continueLoc = continueLoc;\n this.label = label;\n }\n}\n\nexport class SwitchEntry extends Entry {\n breakLoc: t.NumericLiteral;\n\n constructor(breakLoc: t.NumericLiteral) {\n super();\n this.breakLoc = breakLoc;\n }\n}\n\nexport class TryEntry extends Entry {\n firstLoc: t.NumericLiteral;\n catchEntry: CatchEntry;\n finallyEntry: FinallyEntry;\n\n constructor(\n firstLoc: t.NumericLiteral,\n catchEntry: CatchEntry | null = null,\n finallyEntry: FinallyEntry | null = null,\n ) {\n super();\n assert.ok(catchEntry || finallyEntry);\n this.firstLoc = firstLoc;\n this.catchEntry = catchEntry;\n this.finallyEntry = finallyEntry;\n }\n}\n\nexport class CatchEntry extends Entry {\n firstLoc: t.NumericLiteral;\n paramId: t.Identifier;\n\n constructor(firstLoc: t.NumericLiteral, paramId: t.Identifier) {\n super();\n this.firstLoc = firstLoc;\n this.paramId = paramId;\n }\n}\n\nexport class FinallyEntry extends Entry {\n firstLoc: t.NumericLiteral;\n afterLoc: t.NumericLiteral;\n\n constructor(firstLoc: t.NumericLiteral, afterLoc: t.NumericLiteral) {\n super();\n this.firstLoc = firstLoc;\n this.afterLoc = afterLoc;\n }\n}\n\nexport class LabeledEntry extends Entry {\n breakLoc: t.NumericLiteral;\n label: t.Identifier;\n\n constructor(breakLoc: t.NumericLiteral, label: t.Identifier) {\n super();\n this.breakLoc = breakLoc;\n this.label = label;\n }\n}\n\nexport class LeapManager {\n emitter: Emitter;\n entryStack: Entry[];\n\n constructor(emitter: Emitter) {\n this.emitter = emitter;\n this.entryStack = [new FunctionEntry(emitter.finalLoc)];\n }\n\n withEntry(entry: Entry, callback: any) {\n this.entryStack.push(entry);\n try {\n callback.call(this.emitter);\n } finally {\n const popped = this.entryStack.pop();\n assert.strictEqual(popped, entry);\n }\n }\n\n _findLeapLocation(property: \"breakLoc\" | \"continueLoc\", label: t.Identifier) {\n for (let i = this.entryStack.length - 1; i >= 0; --i) {\n const entry = this.entryStack[i];\n // @ts-expect-error Element implicitly has an 'any' type\n const loc = entry[property] as t.NumericLiteral;\n if (loc) {\n if (label) {\n // @ts-expect-error entry.label may not exist\n if (entry.label && entry.label.name === label.name) {\n return loc;\n }\n } else if (entry instanceof LabeledEntry) {\n // Ignore LabeledEntry entries unless we are actually breaking to\n // a label.\n } else {\n return loc;\n }\n }\n }\n return null;\n }\n\n getBreakLoc(label: t.Identifier) {\n return this._findLeapLocation(\"breakLoc\", label);\n }\n\n getContinueLoc(label: t.Identifier) {\n return this._findLeapLocation(\"continueLoc\", label);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAIO,MAAMC,KAAK,CAAC;AAAEC,OAAA,CAAAD,KAAA,GAAAA,KAAA;AAEd,MAAME,aAAa,SAASF,KAAK,CAAC;EAGvCG,WAAWA,CAACC,SAA2B,EAAE;IACvC,KAAK,CAAC,CAAC;IAAC,KAHVA,SAAS;IAIP,IAAI,CAACA,SAAS,GAAGA,SAAS;EAC5B;AACF;AAACH,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEM,MAAMG,SAAS,SAASL,KAAK,CAAC;EAKnCG,WAAWA,CACTG,QAA0B,EAC1BC,WAA6B,EAC7BC,KAAmB,GAAG,IAAI,EAC1B;IACA,KAAK,CAAC,CAAC;IAAC,KATVF,QAAQ;IAAA,KACRC,WAAW;IAAA,KACXC,KAAK;IAQH,IAAI,CAACF,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;AACF;AAACP,OAAA,CAAAI,SAAA,GAAAA,SAAA;AAEM,MAAMI,WAAW,SAAST,KAAK,CAAC;EAGrCG,WAAWA,CAACG,QAA0B,EAAE;IACtC,KAAK,CAAC,CAAC;IAAC,KAHVA,QAAQ;IAIN,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC1B;AACF;AAACL,OAAA,CAAAQ,WAAA,GAAAA,WAAA;AAEM,MAAMC,QAAQ,SAASV,KAAK,CAAC;EAKlCG,WAAWA,CACTQ,QAA0B,EAC1BC,UAA6B,GAAG,IAAI,EACpCC,YAAiC,GAAG,IAAI,EACxC;IACA,KAAK,CAAC,CAAC;IAAC,KATVF,QAAQ;IAAA,KACRC,UALine truncated
|
||||
Generated
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.hasSideEffects = exports.containsLeap = void 0;
|
||||
var _assert = require("assert");
|
||||
var _core = require("@babel/core");
|
||||
const mMap = new WeakMap();
|
||||
function m(node) {
|
||||
if (!mMap.has(node)) {
|
||||
mMap.set(node, {});
|
||||
}
|
||||
return mMap.get(node);
|
||||
}
|
||||
function makePredicate(propertyName, knownTypes) {
|
||||
function onlyChildren(node) {
|
||||
_core.types.assertNode(node);
|
||||
let result = false;
|
||||
function check(child) {
|
||||
if (result) {} else if (Array.isArray(child)) {
|
||||
child.some(check);
|
||||
} else if (_core.types.isNode(child)) {
|
||||
_assert.strictEqual(result, false);
|
||||
result = predicate(child);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
const keys = _core.types.VISITOR_KEYS[node.type];
|
||||
if (keys) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const key = keys[i];
|
||||
const child = node[key];
|
||||
check(child);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function predicate(node) {
|
||||
_core.types.assertNode(node);
|
||||
const meta = m(node);
|
||||
if (hasOwnProperty.call(meta, propertyName)) return meta[propertyName];
|
||||
if (hasOwnProperty.call(opaqueTypes, node.type)) return meta[propertyName] = false;
|
||||
if (hasOwnProperty.call(knownTypes, node.type)) return meta[propertyName] = true;
|
||||
return meta[propertyName] = onlyChildren(node);
|
||||
}
|
||||
predicate.onlyChildren = onlyChildren;
|
||||
return predicate;
|
||||
}
|
||||
const opaqueTypes = {
|
||||
FunctionExpression: true,
|
||||
ArrowFunctionExpression: true
|
||||
};
|
||||
const sideEffectTypes = {
|
||||
CallExpression: true,
|
||||
ForInStatement: true,
|
||||
UnaryExpression: true,
|
||||
BinaryExpression: true,
|
||||
AssignmentExpression: true,
|
||||
UpdateExpression: true,
|
||||
NewExpression: true
|
||||
};
|
||||
const leapTypes = {
|
||||
YieldExpression: true,
|
||||
BreakStatement: true,
|
||||
ContinueStatement: true,
|
||||
ReturnStatement: true,
|
||||
ThrowStatement: true
|
||||
};
|
||||
for (const type in leapTypes) {
|
||||
if (hasOwnProperty.call(leapTypes, type)) {
|
||||
sideEffectTypes[type] = leapTypes[type];
|
||||
}
|
||||
}
|
||||
const hasSideEffects = exports.hasSideEffects = makePredicate("hasSideEffects", sideEffectTypes);
|
||||
const containsLeap = exports.containsLeap = makePredicate("containsLeap", leapTypes);
|
||||
|
||||
//# sourceMappingURL=meta.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_assert","require","_core","mMap","WeakMap","m","node","has","set","get","makePredicate","propertyName","knownTypes","onlyChildren","t","assertNode","result","check","child","Array","isArray","some","isNode","assert","strictEqual","predicate","keys","VISITOR_KEYS","type","i","length","key","meta","hasOwnProperty","call","opaqueTypes","FunctionExpression","ArrowFunctionExpression","sideEffectTypes","CallExpression","ForInStatement","UnaryExpression","BinaryExpression","AssignmentExpression","UpdateExpression","NewExpression","leapTypes","YieldExpression","BreakStatement","ContinueStatement","ReturnStatement","ThrowStatement","hasSideEffects","exports","containsLeap"],"sources":["../../src/regenerator/meta.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport { types as t } from \"@babel/core\";\n\nconst mMap = new WeakMap();\nfunction m(node: t.Node) {\n if (!mMap.has(node)) {\n mMap.set(node, {});\n }\n return mMap.get(node);\n}\n\nfunction makePredicate(\n propertyName: string,\n knownTypes: Record<string, boolean>,\n) {\n function onlyChildren(node: t.Node) {\n t.assertNode(node);\n\n // Assume no side effects until we find out otherwise.\n let result = false;\n\n function check(child: any) {\n if (result) {\n // Do nothing.\n } else if (Array.isArray(child)) {\n child.some(check);\n } else if (t.isNode(child)) {\n assert.strictEqual(result, false);\n result = predicate(child);\n }\n return result;\n }\n\n const keys = t.VISITOR_KEYS[node.type];\n if (keys) {\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const child = node[key as keyof typeof node];\n check(child);\n }\n }\n\n return result;\n }\n\n function predicate(node: t.Node) {\n t.assertNode(node);\n\n const meta = m(node);\n if (Object.hasOwn(meta, propertyName)) return meta[propertyName];\n\n // Certain types are \"opaque,\" which means they have no side\n // effects or leaps and we don't care about their subexpressions.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n if (Object.hasOwn(opaqueTypes, node.type))\n return (meta[propertyName] = false);\n\n if (Object.hasOwn(knownTypes, node.type))\n return (meta[propertyName] = true);\n\n return (meta[propertyName] = onlyChildren(node));\n }\n\n predicate.onlyChildren = onlyChildren;\n\n return predicate;\n}\n\nconst opaqueTypes = {\n FunctionExpression: true,\n ArrowFunctionExpression: true,\n};\n\n// These types potentially have side effects regardless of what side\n// effects their subexpressions have.\nconst sideEffectTypes = {\n CallExpression: true, // Anything could happen!\n ForInStatement: true, // Modifies the key variable.\n UnaryExpression: true, // Think delete.\n BinaryExpression: true, // Might invoke .toString() or .valueOf().\n AssignmentExpression: true, // Side-effecting by definition.\n UpdateExpression: true, // Updates are essentially assignments.\n NewExpression: true, // Similar to CallExpression.\n};\n\n// These types are the direct cause of all leaps in control flow.\nconst leapTypes = {\n YieldExpression: true,\n BreakStatement: true,\n ContinueStatement: true,\n ReturnStatement: true,\n ThrowStatement: true,\n};\n\n// All leap types are also side effect types.\nfor (const type in leapTypes) {\n if (Object.hasOwn(leapTypes, type)) {\n sideEffectTypes[type as keyof typeof sideEffectTypes] =\n leapTypes[type as keyof typeof leapTypes];\n }\n}\n\nexport const hasSideEffects = makePredicate(\"hasSideEffects\", sideEffectTypes);\nexport const containsLeap = makePredicate(\"containsLeap\", leapTypes);\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,MAAME,IAAI,GAAG,IAAIC,OAAO,CAAC,CAAC;AAC1B,SAASC,CAACA,CAACC,IAAY,EAAE;EACvB,IAAI,CAACH,IAAI,CAACI,GAAG,CAACD,IAAI,CAAC,EAAE;IACnBH,IAAI,CAACK,GAAG,CAACF,IAAI,EAAE,CAAC,CAAC,CAAC;EACpB;EACA,OAAOH,IAAI,CAACM,GAAG,CAACH,IAAI,CAAC;AACvB;AAEA,SAASI,aAAaA,CACpBC,YAAoB,EACpBC,UAAmC,EACnC;EACA,SAASC,YAAYA,CAACP,IAAY,EAAE;IAClCQ,WAAC,CAACC,UAAU,CAACT,IAAI,CAAC;IAGlB,IAAIU,MAAM,GAAG,KAAK;IAElB,SAASC,KAAKA,CAACC,KAAU,EAAE;MACzB,IAAIF,MAAM,EAAE,CAEZ,CAAC,MAAM,IAAIG,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;QAC/BA,KAAK,CAACG,IAAI,CAACJ,KAAK,CAAC;MACnB,CAAC,MAAM,IAAIH,WAAC,CAACQ,MAAM,CAACJ,KAAK,CAAC,EAAE;QAC1BK,OAAM,CAACC,WAAW,CAACR,MAAM,EAAE,KAAK,CAAC;QACjCA,MAAM,GAAGS,SAAS,CAACP,KAAK,CAAC;MAC3B;MACA,OAAOF,MAAM;IACf;IAEA,MAAMU,IAAI,GAAGZ,WAAC,CAACa,YAAY,CAACrB,IAAI,CAACsB,IAAI,CAAC;IACtC,IAAIF,IAAI,EAAE;MACR,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,EAAE,EAAE;QACpC,MAAME,GAAG,GAAGL,IAAI,CAACG,CAAC,CAAC;QACnB,MAAMX,KAAK,GAAGZ,IAAI,CAACyB,GAAG,CAAsB;QAC5Cd,KAAK,CAACC,KAAK,CAAC;MACd;IACF;IAEA,OAAOF,MAAM;EACf;EAEA,SAASS,SAASA,CAACnB,IAAY,EAAE;IAC/BQ,WAAC,CAACC,UAAU,CAACT,IAAI,CAAC;IAElB,MAAM0B,IAAI,GAAG3B,CAAC,CAACC,IAAI,CAAC;IACpB,Line truncated
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = replaceShorthandObjectMethod;
|
||||
var _core = require("@babel/core");
|
||||
function replaceShorthandObjectMethod(path) {
|
||||
if (!path.node || !_core.types.isFunction(path.node)) {
|
||||
throw new Error("replaceShorthandObjectMethod can only be called on Function AST node paths.");
|
||||
}
|
||||
if (!_core.types.isObjectMethod(path.node)) {
|
||||
return path;
|
||||
}
|
||||
if (!path.node.generator) {
|
||||
return path;
|
||||
}
|
||||
const parameters = path.node.params.map(function (param) {
|
||||
return _core.types.cloneNode(param);
|
||||
});
|
||||
const functionExpression = _core.types.functionExpression(null, parameters, _core.types.cloneNode(path.node.body), path.node.generator, path.node.async);
|
||||
path.replaceWith(_core.types.objectProperty(_core.types.cloneNode(path.node.key), functionExpression, path.node.computed, false));
|
||||
return path.get("value");
|
||||
}
|
||||
|
||||
//# sourceMappingURL=replaceShorthandObjectMethod.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_core","require","replaceShorthandObjectMethod","path","node","t","isFunction","Error","isObjectMethod","generator","parameters","params","map","param","cloneNode","functionExpression","body","async","replaceWith","objectProperty","key","computed","get"],"sources":["../../src/regenerator/replaceShorthandObjectMethod.ts"],"sourcesContent":["import type { NodePath } from \"@babel/core\";\nimport { types as t } from \"@babel/core\";\n\n// this function converts a shorthand object generator method into a normal\n// (non-shorthand) object property which is a generator function expression. for\n// example, this:\n//\n// var foo = {\n// *bar(baz) { return 5; }\n// }\n//\n// should be replaced with:\n//\n// var foo = {\n// bar: function*(baz) { return 5; }\n// }\n//\n// to do this, it clones the parameter array and the body of the object generator\n// method into a new FunctionExpression.\n//\n// this method can be passed any Function AST node path, and it will return\n// either:\n// a) the path that was passed in (iff the path did not need to be replaced) or\n// b) the path of the new FunctionExpression that was created as a replacement\n// (iff the path did need to be replaced)\n//\n// In either case, though, the caller can count on the fact that the return value\n// is a Function AST node path.\n//\n// If this function is called with an AST node path that is not a Function (or with an\n// argument that isn't an AST node path), it will throw an error.\nexport default function replaceShorthandObjectMethod(path: NodePath): NodePath {\n if (!path.node || !t.isFunction(path.node)) {\n throw new Error(\n \"replaceShorthandObjectMethod can only be called on Function AST node paths.\",\n );\n }\n\n // this function only replaces shorthand object methods (called ObjectMethod\n // in Babel-speak).\n if (!t.isObjectMethod(path.node)) {\n return path;\n }\n\n // this function only replaces generators.\n if (!path.node.generator) {\n return path;\n }\n\n const parameters = path.node.params.map(function (param: any) {\n return t.cloneNode(param);\n });\n\n const functionExpression = t.functionExpression(\n null, // id\n parameters, // params\n t.cloneNode(path.node.body), // body\n path.node.generator,\n path.node.async,\n );\n\n path.replaceWith(\n t.objectProperty(\n t.cloneNode(path.node.key), // key\n functionExpression, //value\n path.node.computed, // computed\n false, // shorthand\n ),\n );\n\n // path now refers to the ObjectProperty AST node path, but we want to return a\n // Function AST node path for the function expression we created. we know that\n // the FunctionExpression we just created is the value of the ObjectProperty,\n // so return the \"value\" path off of this path.\n return path.get(\"value\");\n}\n"],"mappings":";;;;;;AACA,IAAAA,KAAA,GAAAC,OAAA;AA8Be,SAASC,4BAA4BA,CAACC,IAAc,EAAY;EAC7E,IAAI,CAACA,IAAI,CAACC,IAAI,IAAI,CAACC,WAAC,CAACC,UAAU,CAACH,IAAI,CAACC,IAAI,CAAC,EAAE;IAC1C,MAAM,IAAIG,KAAK,CACb,6EACF,CAAC;EACH;EAIA,IAAI,CAACF,WAAC,CAACG,cAAc,CAACL,IAAI,CAACC,IAAI,CAAC,EAAE;IAChC,OAAOD,IAAI;EACb;EAGA,IAAI,CAACA,IAAI,CAACC,IAAI,CAACK,SAAS,EAAE;IACxB,OAAON,IAAI;EACb;EAEA,MAAMO,UAAU,GAAGP,IAAI,CAACC,IAAI,CAACO,MAAM,CAACC,GAAG,CAAC,UAAUC,KAAU,EAAE;IAC5D,OAAOR,WAAC,CAACS,SAAS,CAACD,KAAK,CAAC;EAC3B,CAAC,CAAC;EAEF,MAAME,kBAAkB,GAAGV,WAAC,CAACU,kBAAkB,CAC7C,IAAI,EACJL,UAAU,EACVL,WAAC,CAACS,SAAS,CAACX,IAAI,CAACC,IAAI,CAACY,IAAI,CAAC,EAC3Bb,IAAI,CAACC,IAAI,CAACK,SAAS,EACnBN,IAAI,CAACC,IAAI,CAACa,KACZ,CAAC;EAEDd,IAAI,CAACe,WAAW,CACdb,WAAC,CAACc,cAAc,CACdd,WAAC,CAACS,SAAS,CAACX,IAAI,CAACC,IAAI,CAACgB,GAAG,CAAC,EAC1BL,kBAAkB,EAClBZ,IAAI,CAACC,IAAI,CAACiB,QAAQ,EAClB,KACF,CACF,CAAC;EAMD,OAAOlB,IAAI,CAACmB,GAAG,CAAC,OAAO,CAAC;AAC1B","ignoreList":[]}
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isReference = isReference;
|
||||
exports.runtimeProperty = exports.newHelpersAvailable = void 0;
|
||||
var _core = require("@babel/core");
|
||||
let newHelpersAvailable = exports.newHelpersAvailable = void 0;
|
||||
exports.newHelpersAvailable = newHelpersAvailable = file => {
|
||||
return file.availableHelper("regenerator") && !_core.types.isIdentifier(file.addHelper("regenerator"), {
|
||||
name: "__interal_marker_fallback_regenerator__"
|
||||
});
|
||||
};
|
||||
let runtimeProperty = exports.runtimeProperty = void 0;
|
||||
exports.runtimeProperty = runtimeProperty = function (file, name) {
|
||||
const helper = file.addHelper("regeneratorRuntime");
|
||||
return _core.types.memberExpression(_core.types.isArrowFunctionExpression(helper) && _core.types.isIdentifier(helper.body) ? helper.body : _core.types.callExpression(helper, []), _core.types.identifier(name), false);
|
||||
};
|
||||
function isReference(path) {
|
||||
return path.isReferenced() || path.parentPath.isAssignmentExpression({
|
||||
left: path.node
|
||||
});
|
||||
}
|
||||
|
||||
//# sourceMappingURL=util.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_core","require","newHelpersAvailable","exports","file","availableHelper","t","isIdentifier","addHelper","name","runtimeProperty","helper","memberExpression","isArrowFunctionExpression","body","callExpression","identifier","isReference","path","isReferenced","parentPath","isAssignmentExpression","left","node"],"sources":["../../src/regenerator/util.ts"],"sourcesContent":["import type { PluginPass } from \"@babel/core\";\nimport { types as t } from \"@babel/core\";\n\nexport let newHelpersAvailable: (file: PluginPass) => boolean;\nif (!process.env.BABEL_8_BREAKING) {\n newHelpersAvailable = (file: PluginPass) => {\n if (!process.env.IS_PUBLISH && process.env.FORCE_OLD_REGENERATOR) {\n // Only for testing purposes.\n return false;\n }\n return (\n file.availableHelper(\"regenerator\") &&\n // At this point, we can safely try to inject the `regenerator` helper.\n // If this plugin tries to inject any helper, than we are sure that\n // `regenerator` is one of them.\n !t.isIdentifier(file.addHelper(\"regenerator\"), {\n // This is a special marker returned by transform-runtime, which means\n // \"the version of `@babel/runtime` does not have the helper\".\n // Normally transform-runtime will fallback to just injecting the\n // helper inline, but we special handle this case to instead be able\n // to fallback to the old `regeneratorRuntime` helper\n name: \"__interal_marker_fallback_regenerator__\",\n })\n );\n };\n}\n\nexport let runtimeProperty: (file: PluginPass, name: any) => any;\nif (!process.env.BABEL_8_BREAKING) {\n runtimeProperty = function (file, name) {\n const helper = file.addHelper(\"regeneratorRuntime\");\n return t.memberExpression(\n // In some cases, `helper` will be (() => regeneratorRuntime).\n // Se the implementation in transform-runtime for more details.\n t.isArrowFunctionExpression(helper) &&\n t.isIdentifier((helper as any).body)\n ? (helper as any).body\n : t.callExpression(helper, []),\n t.identifier(name),\n false,\n );\n };\n}\n\nexport function isReference(path: any) {\n return (\n path.isReferenced() ||\n path.parentPath.isAssignmentExpression({ left: path.node })\n );\n}\n"],"mappings":";;;;;;;AACA,IAAAA,KAAA,GAAAC,OAAA;AAEO,IAAIC,mBAAkD,GAAAC,OAAA,CAAAD,mBAAA;AAE3DC,OAAA,CAAAD,mBAAA,GAAAA,mBAAmB,GAAIE,IAAgB,IAAK;EAK1C,OACEA,IAAI,CAACC,eAAe,CAAC,aAAa,CAAC,IAInC,CAACC,WAAC,CAACC,YAAY,CAACH,IAAI,CAACI,SAAS,CAAC,aAAa,CAAC,EAAE;IAM7CC,IAAI,EAAE;EACR,CAAC,CAAC;AAEN,CAAC;AAGI,IAAIC,eAAqD,GAAAP,OAAA,CAAAO,eAAA;AAE9DP,OAAA,CAAAO,eAAA,GAAAA,eAAe,GAAG,SAAAA,CAAUN,IAAI,EAAEK,IAAI,EAAE;EACtC,MAAME,MAAM,GAAGP,IAAI,CAACI,SAAS,CAAC,oBAAoB,CAAC;EACnD,OAAOF,WAAC,CAACM,gBAAgB,CAGvBN,WAAC,CAACO,yBAAyB,CAACF,MAAM,CAAC,IACjCL,WAAC,CAACC,YAAY,CAAEI,MAAM,CAASG,IAAI,CAAC,GACjCH,MAAM,CAASG,IAAI,GACpBR,WAAC,CAACS,cAAc,CAACJ,MAAM,EAAE,EAAE,CAAC,EAChCL,WAAC,CAACU,UAAU,CAACP,IAAI,CAAC,EAClB,KACF,CAAC;AACH,CAAC;AAGI,SAASQ,WAAWA,CAACC,IAAS,EAAE;EACrC,OACEA,IAAI,CAACC,YAAY,CAAC,CAAC,IACnBD,IAAI,CAACE,UAAU,CAACC,sBAAsB,CAAC;IAAEC,IAAI,EAAEJ,IAAI,CAACK;EAAK,CAAC,CAAC;AAE/D","ignoreList":[]}
|
||||
Generated
Vendored
+221
@@ -0,0 +1,221 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getVisitor = void 0;
|
||||
var _assert = require("assert");
|
||||
var _hoist = require("./hoist.js");
|
||||
var _emit = require("./emit.js");
|
||||
var _replaceShorthandObjectMethod = require("./replaceShorthandObjectMethod.js");
|
||||
var util = require("./util.js");
|
||||
var _core = require("@babel/core");
|
||||
const getVisitor = () => ({
|
||||
Method(path, state) {
|
||||
const node = path.node;
|
||||
if (!shouldRegenerate(node, state)) return;
|
||||
const container = _core.types.functionExpression(null, [], _core.types.cloneNode(node.body, false), node.generator, node.async);
|
||||
path.get("body").set("body", [_core.types.returnStatement(_core.types.callExpression(container, []))]);
|
||||
node.async = false;
|
||||
node.generator = false;
|
||||
path.get("body.body.0.argument.callee").unwrapFunctionEnvironment();
|
||||
},
|
||||
Function: {
|
||||
exit(path, state) {
|
||||
let node = path.node;
|
||||
if (!shouldRegenerate(node, state)) return;
|
||||
path = (0, _replaceShorthandObjectMethod.default)(path);
|
||||
node = path.node;
|
||||
const contextId = path.scope.generateUidIdentifier("context");
|
||||
const argsId = path.scope.generateUidIdentifier("args");
|
||||
path.ensureBlock();
|
||||
const bodyBlockPath = path.get("body");
|
||||
if (node.async) {
|
||||
bodyBlockPath.traverse(awaitVisitor, this);
|
||||
}
|
||||
bodyBlockPath.traverse(functionSentVisitor, {
|
||||
context: contextId,
|
||||
pluginPass: this
|
||||
});
|
||||
const outerBody = [];
|
||||
const innerBody = [];
|
||||
bodyBlockPath.get("body").forEach(function (childPath) {
|
||||
const node = childPath.node;
|
||||
if (_core.types.isExpressionStatement(node) && _core.types.isStringLiteral(node.expression)) {
|
||||
outerBody.push(node);
|
||||
} else if ((node == null ? void 0 : node._blockHoist) != null) {
|
||||
outerBody.push(node);
|
||||
} else {
|
||||
innerBody.push(node);
|
||||
}
|
||||
});
|
||||
if (outerBody.length > 0) {
|
||||
bodyBlockPath.node.body = innerBody;
|
||||
}
|
||||
const outerFnExpr = getOuterFnExpr(this, path);
|
||||
_core.types.assertIdentifier(node.id);
|
||||
const vars = (0, _hoist.hoist)(path);
|
||||
const context = {
|
||||
usesThis: false,
|
||||
usesArguments: false,
|
||||
getArgsId: () => _core.types.cloneNode(argsId)
|
||||
};
|
||||
path.traverse(argumentsThisVisitor, context);
|
||||
if (context.usesArguments) {
|
||||
vars.push(_core.types.variableDeclarator(_core.types.cloneNode(argsId), _core.types.identifier("arguments")));
|
||||
}
|
||||
const emitter = new _emit.Emitter(contextId, path.scope, vars, this);
|
||||
emitter.explode(path.get("body"));
|
||||
if (vars.length > 0) {
|
||||
outerBody.push(_core.types.variableDeclaration("var", vars));
|
||||
}
|
||||
const wrapArgs = [emitter.getContextFunction()];
|
||||
const tryLocsList = emitter.getTryLocsList();
|
||||
if (node.generator) {
|
||||
wrapArgs.push(outerFnExpr);
|
||||
} else if (context.usesThis || tryLocsList || node.async) {
|
||||
wrapArgs.push(_core.types.nullLiteral());
|
||||
}
|
||||
if (context.usesThis) {
|
||||
wrapArgs.push(_core.types.thisExpression());
|
||||
} else if (tryLocsList || node.async) {
|
||||
wrapArgs.push(_core.types.nullLiteral());
|
||||
}
|
||||
if (tryLocsList) {
|
||||
wrapArgs.push(tryLocsList);
|
||||
} else if (node.async) {
|
||||
wrapArgs.push(_core.types.nullLiteral());
|
||||
}
|
||||
if (node.async) {
|
||||
let currentScope = path.scope;
|
||||
do {
|
||||
if (currentScope.hasOwnBinding("Promise")) currentScope.rename("Promise");
|
||||
} while (currentScope = currentScope.parent);
|
||||
wrapArgs.push(_core.types.identifier("Promise"));
|
||||
}
|
||||
const wrapCall = _core.types.callExpression(util.newHelpersAvailable(this) ? !node.async ? _core.types.memberExpression(_core.types.callExpression(this.addHelper("regenerator"), []), _core.types.identifier("w")) : node.generator ? this.addHelper("regeneratorAsyncGen") : this.addHelper("regeneratorAsync") : util.runtimeProperty(this, node.async ? "async" : "wrap"), wrapArgs);
|
||||
outerBody.push(_core.types.returnStatement(wrapCall));
|
||||
node.body = _core.types.blockStatement(outerBody);
|
||||
path.get("body.body").forEach(p => p.scope.registerDeclaration(p));
|
||||
const oldDirectives = bodyBlockPath.node.directives;
|
||||
if (oldDirectives) {
|
||||
node.body.directives = oldDirectives;
|
||||
}
|
||||
const wasGeneratorFunction = node.generator;
|
||||
if (wasGeneratorFunction) {
|
||||
node.generator = false;
|
||||
}
|
||||
if (node.async) {
|
||||
node.async = false;
|
||||
}
|
||||
if (wasGeneratorFunction && _core.types.isExpression(node)) {
|
||||
path.replaceWith(_core.types.callExpression(util.newHelpersAvailable(this) ? _core.types.memberExpression(_core.types.callExpression(this.addHelper("regenerator"), []), _core.types.identifier("m")) : util.runtimeProperty(this, "mark"), [node]));
|
||||
path.addComment("leading", "#__PURE__");
|
||||
}
|
||||
const insertedLocs = emitter.getInsertedLocs();
|
||||
path.traverse({
|
||||
NumericLiteral(path) {
|
||||
if (!insertedLocs.has(path.node)) {
|
||||
return;
|
||||
}
|
||||
path.replaceWith(_core.types.numericLiteral(path.node.value));
|
||||
}
|
||||
});
|
||||
path.requeue();
|
||||
}
|
||||
}
|
||||
});
|
||||
exports.getVisitor = getVisitor;
|
||||
function shouldRegenerate(node, state) {
|
||||
if (node.generator) {
|
||||
if (node.async) {
|
||||
return state.opts.asyncGenerators !== false;
|
||||
} else {
|
||||
return state.opts.generators !== false;
|
||||
}
|
||||
} else if (node.async) {
|
||||
return state.opts.async !== false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getOuterFnExpr(state, funPath) {
|
||||
const node = funPath.node;
|
||||
_core.types.assertFunction(node);
|
||||
if (!node.id) {
|
||||
node.id = funPath.scope.parent.generateUidIdentifier("callee");
|
||||
}
|
||||
if (node.generator && _core.types.isFunctionDeclaration(node)) {
|
||||
return getMarkedFunctionId(state, funPath);
|
||||
}
|
||||
return _core.types.cloneNode(node.id);
|
||||
}
|
||||
const markInfo = new WeakMap();
|
||||
function getMarkInfo(node) {
|
||||
if (!markInfo.has(node)) {
|
||||
markInfo.set(node, {});
|
||||
}
|
||||
return markInfo.get(node);
|
||||
}
|
||||
function getMarkedFunctionId(state, funPath) {
|
||||
const node = funPath.node;
|
||||
_core.types.assertIdentifier(node.id);
|
||||
const blockPath = funPath.findParent(function (path) {
|
||||
return path.isProgram() || path.isBlockStatement();
|
||||
});
|
||||
if (!blockPath) {
|
||||
return node.id;
|
||||
}
|
||||
const block = blockPath.node;
|
||||
_assert.ok(Array.isArray(block.body));
|
||||
const info = getMarkInfo(block);
|
||||
if (!info.decl) {
|
||||
info.decl = _core.types.variableDeclaration("var", []);
|
||||
blockPath.unshiftContainer("body", info.decl);
|
||||
info.declPath = blockPath.get("body.0");
|
||||
}
|
||||
_assert.strictEqual(info.declPath.node, info.decl);
|
||||
const markedId = blockPath.scope.generateUidIdentifier("marked");
|
||||
const markCallExp = _core.types.callExpression(util.newHelpersAvailable(state) ? _core.types.memberExpression(_core.types.callExpression(state.addHelper("regenerator"), []), _core.types.identifier("m")) : util.runtimeProperty(state, "mark"), [_core.types.cloneNode(node.id)]);
|
||||
const index = info.decl.declarations.push(_core.types.variableDeclarator(markedId, markCallExp)) - 1;
|
||||
const markCallExpPath = info.declPath.get("declarations." + index + ".init");
|
||||
_assert.strictEqual(markCallExpPath.node, markCallExp);
|
||||
markCallExpPath.addComment("leading", "#__PURE__");
|
||||
return _core.types.cloneNode(markedId);
|
||||
}
|
||||
const argumentsThisVisitor = {
|
||||
"FunctionExpression|FunctionDeclaration|Method": function (path) {
|
||||
path.skip();
|
||||
},
|
||||
Identifier: function (path, state) {
|
||||
if (path.node.name === "arguments" && util.isReference(path)) {
|
||||
path.replaceWith(state.getArgsId());
|
||||
state.usesArguments = true;
|
||||
}
|
||||
},
|
||||
ThisExpression: function (path, state) {
|
||||
state.usesThis = true;
|
||||
}
|
||||
};
|
||||
const functionSentVisitor = {
|
||||
MetaProperty(path, state) {
|
||||
const {
|
||||
node
|
||||
} = path;
|
||||
if (node.meta.name === "function" && node.property.name === "sent") {
|
||||
path.replaceWith(_core.types.memberExpression(_core.types.cloneNode(state.context), _core.types.identifier(util.newHelpersAvailable(state.pluginPass) ? "v" : "_sent")));
|
||||
}
|
||||
}
|
||||
};
|
||||
const awaitVisitor = {
|
||||
Function: function (path) {
|
||||
path.skip();
|
||||
},
|
||||
AwaitExpression: function (path) {
|
||||
const argument = path.node.argument;
|
||||
const helper = util.newHelpersAvailable(this) ? this.addHelper("awaitAsyncGenerator") : util.runtimeProperty(this, "awrap");
|
||||
path.replaceWith(_core.types.yieldExpression(_core.types.callExpression(helper, [argument]), false));
|
||||
}
|
||||
};
|
||||
|
||||
//# sourceMappingURL=visit.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["Object","defineProperty","exports","value","getVisitor","_assert","require","_hoist","_emit","_replaceShorthandObjectMethod","util","_core","Method","path","state","node","shouldRegenerate","container","t","functionExpression","cloneNode","body","generator","async","get","set","returnStatement","callExpression","unwrapFunctionEnvironment","Function","exit","replaceShorthandObjectMethod","contextId","scope","generateUidIdentifier","argsId","ensureBlock","bodyBlockPath","traverse","awaitVisitor","functionSentVisitor","context","pluginPass","outerBody","innerBody","forEach","childPath","isExpressionStatement","isStringLiteral","expression","push","_blockHoist","length","outerFnExpr","getOuterFnExpr","assertIdentifier","id","vars","hoist","usesThis","usesArguments","getArgsId","argumentsThisVisitor","variableDeclarator","identifier","emitter","Emitter","explode","variableDeclaration","wrapArgs","getContextFunction","tryLocsList","getTryLocsList","nullLiteral","thisExpression","currentScope","hasOwnBinding","rename","parent","wrapCall","newHelpersAvailable","memberExpression","addHelper","runtimeProperty","blockStatement","p","registerDeclaration","oldDirectives","directives","wasGeneratorFunction","isExpression","replaceWith","addComment","insertedLocs","getInsertedLocs","NumericLiteral","has","numericLiteral","requeue","opts","asyncGenerators","generators","funPath","assertFunction","isFunctionDeclaration","getMarkedFunctionId","markInfo","WeakMap","getMarkInfo","blockPath","findParent","isProgram","isBlockStatement","block","assert","ok","Array","isArray","info","decl","unshiftContainer","declPath","strictEqual","markedId","markCallExp","index","declarations","markCallExpPath","FunctionExpression|FunctionDeclaration|Method","skip","Identifier","name","isReference","ThisExpression","MetaProperty","meta","property","AwaitExpression","argument","helper","yieldExpression"],"sources":["../../src/regenerator/visit.ts"],"sourcesContent":["\"use strict\";\n\nimport assert from \"node:assert\";\nimport { hoist } from \"./hoist.ts\";\nimport { Emitter } from \"./emit.ts\";\nimport replaceShorthandObjectMethod from \"./replaceShorthandObjectMethod.ts\";\nimport * as util from \"./util.ts\";\nimport type { NodePath, PluginPass, Visitor } from \"@babel/core\";\nimport { types as t } from \"@babel/core\";\n\nexport const getVisitor = (): Visitor<PluginPass> => ({\n Method(path, state) {\n const node = path.node;\n\n if (!shouldRegenerate(node, state)) return;\n\n const container = t.functionExpression(\n null,\n [],\n t.cloneNode(node.body, false),\n node.generator,\n node.async,\n );\n\n path\n .get(\"body\")\n .set(\"body\", [t.returnStatement(t.callExpression(container, []))]);\n\n // Regardless of whether or not the wrapped function is a an async method\n // or generator the outer function should not be\n node.async = false;\n node.generator = false;\n\n // Unwrap the wrapper IIFE's environment so super and this and such still work.\n (\n path.get(\"body.body.0.argument.callee\") as NodePath\n ).unwrapFunctionEnvironment();\n },\n Function: {\n exit(\n path: NodePath<Exclude<t.Function, t.ArrowFunctionExpression>>,\n state,\n ) {\n let node = path.node;\n\n if (!shouldRegenerate(node, state)) return;\n\n // if this is an ObjectMethod, we need to convert it to an ObjectProperty\n path = replaceShorthandObjectMethod(path) as any;\n node = path.node;\n\n const contextId = path.scope.generateUidIdentifier(\"context\");\n const argsId = path.scope.generateUidIdentifier(\"args\");\n\n path.ensureBlock();\n const bodyBlockPath = path.get(\"body\");\n\n if (node.async) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n bodyBlockPath.traverse(awaitVisitor, this);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n bodyBlockPath.traverse(functionSentVisitor, {\n context: contextId,\n pluginPass: this,\n });\n\n const outerBody: any[] = [];\n const innerBody: any[] = [];\n\n bodyBlockPath.get(\"body\").forEach(function (childPath: any) {\n const node = childPath.node;\n if (\n t.isExpressionStatement(node) &&\n t.isStringLiteral(node.expression)\n ) {\n // Babylon represents directives like \"use strict\" as elements\n // of a bodyBlockPath.node.directives array, but they could just\n // as easily be represented (by other parsers) as traditional\n // string-literal-valued expression statements, so we need to\n // handle that here. (#248)\n outerBody.push(node);\n } else if (node?._blockHoist != null) {\n outerBody.push(node);\n } else {\n innerBody.push(node);\n }\n });\n\n if (outerBody.length > 0) {\n // OLine truncated
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@babel/plugin-transform-regenerator",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"description": "Explode async and generator functions into a state machine.",
|
||||
"version": "7.29.7",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-regenerator",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-plugin-transform-regenerator"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "^7.29.7"
|
||||
},
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.29.7",
|
||||
"@babel/helper-check-duplicate-nodes": "^7.29.7",
|
||||
"@babel/helper-plugin-test-runner": "^7.29.7",
|
||||
"@babel/plugin-proposal-function-sent": "^7.29.7",
|
||||
"@babel/plugin-transform-arrow-functions": "^7.29.7",
|
||||
"@babel/plugin-transform-block-scoping": "^7.29.7",
|
||||
"@babel/plugin-transform-classes": "^7.29.7",
|
||||
"@babel/plugin-transform-for-of": "^7.29.7",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.29.7",
|
||||
"@babel/plugin-transform-parameters": "^7.29.7",
|
||||
"@babel/plugin-transform-runtime": "^7.29.7",
|
||||
"babel-plugin-polyfill-regenerator": "^0.6.6",
|
||||
"mocha": "^10.0.0",
|
||||
"recast": "^0.23.3",
|
||||
"uglify-js": "^3.14.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"type": "commonjs"
|
||||
}
|
||||
Reference in new issue
Block a user