nav tabs on admin dashboard
This commit is contained in:
194
node_modules/regenerator-transform/src/emit.js
generated
vendored
194
node_modules/regenerator-transform/src/emit.js
generated
vendored
@@ -1,15 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
* additional grant of patent rights can be found in the PATENTS file in
|
||||
* the same directory.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import assert from "assert";
|
||||
import * as t from "babel-types";
|
||||
import * as leap from "./leap";
|
||||
import * as meta from "./meta";
|
||||
import * as util from "./util";
|
||||
@@ -18,7 +14,8 @@ let hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
function Emitter(contextId) {
|
||||
assert.ok(this instanceof Emitter);
|
||||
t.assertIdentifier(contextId);
|
||||
|
||||
util.getTypes().assertIdentifier(contextId);
|
||||
|
||||
// Used to generate unique temporary names.
|
||||
this.nextTempId = 0;
|
||||
@@ -37,9 +34,11 @@ function Emitter(contextId) {
|
||||
// that have been marked as branch/jump targets.
|
||||
this.marked = [true];
|
||||
|
||||
this.insertedLocs = new Set();
|
||||
|
||||
// The last location will be marked when this.getDispatchLoop is
|
||||
// called.
|
||||
this.finalLoc = loc();
|
||||
this.finalLoc = this.loc();
|
||||
|
||||
// A list of all leap.TryEntry statements emitted.
|
||||
this.tryEntries = [];
|
||||
@@ -58,14 +57,24 @@ exports.Emitter = Emitter;
|
||||
// the amazingly convenient benefit of allowing the exact value of the
|
||||
// location to be determined at any time, even after generating code that
|
||||
// refers to the location.
|
||||
function loc() {
|
||||
return t.numericLiteral(-1);
|
||||
Ep.loc = function() {
|
||||
const l = util.getTypes().numericLiteral(-1)
|
||||
this.insertedLocs.add(l);
|
||||
return l;
|
||||
}
|
||||
|
||||
Ep.getInsertedLocs = function() {
|
||||
return this.insertedLocs;
|
||||
}
|
||||
|
||||
Ep.getContextId = function() {
|
||||
return util.getTypes().clone(this.contextId);
|
||||
}
|
||||
|
||||
// Sets the exact value of the given location to the offset of the next
|
||||
// Statement emitted.
|
||||
Ep.mark = function(loc) {
|
||||
t.assertLiteral(loc);
|
||||
util.getTypes().assertLiteral(loc);
|
||||
let index = this.listing.length;
|
||||
if (loc.value === -1) {
|
||||
loc.value = index;
|
||||
@@ -79,6 +88,8 @@ Ep.mark = function(loc) {
|
||||
};
|
||||
|
||||
Ep.emit = function(node) {
|
||||
const t = util.getTypes();
|
||||
|
||||
if (t.isExpression(node)) {
|
||||
node = t.expressionStatement(node);
|
||||
}
|
||||
@@ -96,15 +107,17 @@ Ep.emitAssign = function(lhs, rhs) {
|
||||
|
||||
// Shorthand for an assignment statement.
|
||||
Ep.assign = function(lhs, rhs) {
|
||||
const t = util.getTypes();
|
||||
return t.expressionStatement(
|
||||
t.assignmentExpression("=", lhs, rhs));
|
||||
t.assignmentExpression("=", t.cloneDeep(lhs), rhs));
|
||||
};
|
||||
|
||||
// Convenience function for generating expressions like context.next,
|
||||
// context.sent, and context.rval.
|
||||
Ep.contextProperty = function(name, computed) {
|
||||
const t = util.getTypes();
|
||||
return t.memberExpression(
|
||||
this.contextId,
|
||||
this.getContextId(),
|
||||
computed ? t.stringLiteral(name) : t.identifier(name),
|
||||
!!computed
|
||||
);
|
||||
@@ -120,7 +133,7 @@ Ep.stop = function(rval) {
|
||||
};
|
||||
|
||||
Ep.setReturnValue = function(valuePath) {
|
||||
t.assertExpression(valuePath.value);
|
||||
util.getTypes().assertExpression(valuePath.value);
|
||||
|
||||
this.emitAssign(
|
||||
this.contextProperty("rval"),
|
||||
@@ -129,11 +142,13 @@ Ep.setReturnValue = function(valuePath) {
|
||||
};
|
||||
|
||||
Ep.clearPendingException = function(tryLoc, assignee) {
|
||||
const t = util.getTypes();
|
||||
|
||||
t.assertLiteral(tryLoc);
|
||||
|
||||
let catchCall = t.callExpression(
|
||||
this.contextProperty("catch", true),
|
||||
[tryLoc]
|
||||
[t.clone(tryLoc)]
|
||||
);
|
||||
|
||||
if (assignee) {
|
||||
@@ -147,11 +162,13 @@ Ep.clearPendingException = function(tryLoc, assignee) {
|
||||
// exact value of the location is not yet known.
|
||||
Ep.jump = function(toLoc) {
|
||||
this.emitAssign(this.contextProperty("next"), toLoc);
|
||||
this.emit(t.breakStatement());
|
||||
this.emit(util.getTypes().breakStatement());
|
||||
};
|
||||
|
||||
// Conditional jump.
|
||||
Ep.jumpIf = function(test, toLoc) {
|
||||
const t = util.getTypes();
|
||||
|
||||
t.assertExpression(test);
|
||||
t.assertLiteral(toLoc);
|
||||
|
||||
@@ -166,6 +183,8 @@ Ep.jumpIf = function(test, toLoc) {
|
||||
|
||||
// Conditional jump, with the condition negated.
|
||||
Ep.jumpIfNot = function(test, toLoc) {
|
||||
const t = util.getTypes();
|
||||
|
||||
t.assertExpression(test);
|
||||
t.assertLiteral(toLoc);
|
||||
|
||||
@@ -197,9 +216,11 @@ Ep.makeTempVar = function() {
|
||||
};
|
||||
|
||||
Ep.getContextFunction = function(id) {
|
||||
const t = util.getTypes();
|
||||
|
||||
return t.functionExpression(
|
||||
id || null/*Anonymous*/,
|
||||
[this.contextId],
|
||||
[this.getContextId()],
|
||||
t.blockStatement([this.getDispatchLoop()]),
|
||||
false, // Not a generator anymore!
|
||||
false // Nor an expression.
|
||||
@@ -218,7 +239,8 @@ Ep.getContextFunction = function(id) {
|
||||
// Each marked location in this.listing will correspond to one generated
|
||||
// case statement.
|
||||
Ep.getDispatchLoop = function() {
|
||||
let self = this;
|
||||
const self = this;
|
||||
const t = util.getTypes();
|
||||
let cases = [];
|
||||
let current;
|
||||
|
||||
@@ -280,6 +302,7 @@ Ep.getTryLocsList = function() {
|
||||
return null;
|
||||
}
|
||||
|
||||
const t = util.getTypes();
|
||||
let lastLocValue = 0;
|
||||
|
||||
return t.arrayExpression(
|
||||
@@ -302,7 +325,7 @@ Ep.getTryLocsList = function() {
|
||||
locs[3] = fe.afterLoc;
|
||||
}
|
||||
|
||||
return t.arrayExpression(locs);
|
||||
return t.arrayExpression(locs.map(loc => loc && t.clone(loc)));
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -315,6 +338,7 @@ Ep.getTryLocsList = function() {
|
||||
// No destructive modification of AST nodes.
|
||||
|
||||
Ep.explode = function(path, ignoreResult) {
|
||||
const t = util.getTypes();
|
||||
let node = path.node;
|
||||
let self = this;
|
||||
|
||||
@@ -362,6 +386,7 @@ function getDeclError(node) {
|
||||
}
|
||||
|
||||
Ep.explodeStatement = function(path, labelId) {
|
||||
const t = util.getTypes();
|
||||
let stmt = path.node;
|
||||
let self = this;
|
||||
let before, after, head;
|
||||
@@ -399,7 +424,7 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
break;
|
||||
|
||||
case "LabeledStatement":
|
||||
after = loc();
|
||||
after = this.loc();
|
||||
|
||||
// Did you know you can break from any labeled block statement or
|
||||
// control structure? Well, you can! Note: when a labeled loop is
|
||||
@@ -433,8 +458,8 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
break;
|
||||
|
||||
case "WhileStatement":
|
||||
before = loc();
|
||||
after = loc();
|
||||
before = this.loc();
|
||||
after = this.loc();
|
||||
|
||||
self.mark(before);
|
||||
self.jumpIfNot(self.explodeExpression(path.get("test")), after);
|
||||
@@ -448,9 +473,9 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
break;
|
||||
|
||||
case "DoWhileStatement":
|
||||
let first = loc();
|
||||
let test = loc();
|
||||
after = loc();
|
||||
let first = this.loc();
|
||||
let test = this.loc();
|
||||
after = this.loc();
|
||||
|
||||
self.mark(first);
|
||||
self.leapManager.withEntry(
|
||||
@@ -464,9 +489,9 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
break;
|
||||
|
||||
case "ForStatement":
|
||||
head = loc();
|
||||
let update = loc();
|
||||
after = loc();
|
||||
head = this.loc();
|
||||
let update = this.loc();
|
||||
after = this.loc();
|
||||
|
||||
if (stmt.init) {
|
||||
// We pass true here to indicate that if stmt.init is an expression
|
||||
@@ -505,8 +530,8 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
return self.explodeExpression(path.get("expression"));
|
||||
|
||||
case "ForInStatement":
|
||||
head = loc();
|
||||
after = loc();
|
||||
head = this.loc();
|
||||
after = this.loc();
|
||||
|
||||
let keyIterNextFn = self.makeTempVar();
|
||||
self.emitAssign(
|
||||
@@ -525,7 +550,7 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
t.assignmentExpression(
|
||||
"=",
|
||||
keyInfoTmpVar,
|
||||
t.callExpression(keyIterNextFn, [])
|
||||
t.callExpression(t.cloneDeep(keyIterNextFn), [])
|
||||
),
|
||||
t.identifier("done"),
|
||||
false
|
||||
@@ -536,7 +561,7 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
self.emitAssign(
|
||||
stmt.left,
|
||||
t.memberExpression(
|
||||
keyInfoTmpVar,
|
||||
t.cloneDeep(keyInfoTmpVar),
|
||||
t.identifier("value"),
|
||||
false
|
||||
)
|
||||
@@ -577,8 +602,8 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
self.explodeExpression(path.get("discriminant"))
|
||||
);
|
||||
|
||||
after = loc();
|
||||
let defaultLoc = loc();
|
||||
after = this.loc();
|
||||
let defaultLoc = this.loc();
|
||||
let condition = defaultLoc;
|
||||
let caseLocs = [];
|
||||
|
||||
@@ -591,8 +616,8 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
|
||||
if (c.test) {
|
||||
condition = t.conditionalExpression(
|
||||
t.binaryExpression("===", disc, c.test),
|
||||
caseLocs[i] = loc(),
|
||||
t.binaryExpression("===", t.cloneDeep(disc), c.test),
|
||||
caseLocs[i] = this.loc(),
|
||||
condition
|
||||
);
|
||||
} else {
|
||||
@@ -627,8 +652,8 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
break;
|
||||
|
||||
case "IfStatement":
|
||||
let elseLoc = stmt.alternate && loc();
|
||||
after = loc();
|
||||
let elseLoc = stmt.alternate && this.loc();
|
||||
after = this.loc();
|
||||
|
||||
self.jumpIfNot(
|
||||
self.explodeExpression(path.get("test")),
|
||||
@@ -659,17 +684,17 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
throw new Error("WithStatement not supported in generator functions.");
|
||||
|
||||
case "TryStatement":
|
||||
after = loc();
|
||||
after = this.loc();
|
||||
|
||||
let handler = stmt.handler;
|
||||
|
||||
let catchLoc = handler && loc();
|
||||
let catchLoc = handler && this.loc();
|
||||
let catchEntry = catchLoc && new leap.CatchEntry(
|
||||
catchLoc,
|
||||
handler.param
|
||||
);
|
||||
|
||||
let finallyLoc = stmt.finalizer && loc();
|
||||
let finallyLoc = stmt.finalizer && this.loc();
|
||||
let finallyEntry = finallyLoc &&
|
||||
new leap.FinallyEntry(finallyLoc, after);
|
||||
|
||||
@@ -705,7 +730,7 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
self.clearPendingException(tryEntry.firstLoc, safeParam);
|
||||
|
||||
bodyPath.traverse(catchParamVisitor, {
|
||||
safeParam: safeParam,
|
||||
getSafeParam: () => t.cloneDeep(safeParam),
|
||||
catchParamName: handler.param.name
|
||||
});
|
||||
|
||||
@@ -749,7 +774,7 @@ Ep.explodeStatement = function(path, labelId) {
|
||||
let catchParamVisitor = {
|
||||
Identifier: function(path, state) {
|
||||
if (path.node.name === state.catchParamName && util.isReference(path)) {
|
||||
util.replaceWithOrRemove(path, state.safeParam);
|
||||
util.replaceWithOrRemove(path, state.getSafeParam());
|
||||
}
|
||||
},
|
||||
|
||||
@@ -776,17 +801,22 @@ Ep.emitAbruptCompletion = function(record) {
|
||||
"normal completions are not abrupt"
|
||||
);
|
||||
|
||||
const t = util.getTypes();
|
||||
let abruptArgs = [t.stringLiteral(record.type)];
|
||||
|
||||
if (record.type === "break" ||
|
||||
record.type === "continue") {
|
||||
t.assertLiteral(record.target);
|
||||
abruptArgs[1] = record.target;
|
||||
abruptArgs[1] = this.insertedLocs.has(record.target)
|
||||
? record.target
|
||||
: t.cloneDeep(record.target);
|
||||
} else if (record.type === "return" ||
|
||||
record.type === "throw") {
|
||||
if (record.value) {
|
||||
t.assertExpression(record.value);
|
||||
abruptArgs[1] = record.value;
|
||||
abruptArgs[1] = this.insertedLocs.has(record.value)
|
||||
? record.value
|
||||
: t.cloneDeep(record.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -810,7 +840,7 @@ function isValidCompletion(record) {
|
||||
if (type === "break" ||
|
||||
type === "continue") {
|
||||
return !hasOwn.call(record, "value")
|
||||
&& t.isLiteral(record.target);
|
||||
&& util.getTypes().isLiteral(record.target);
|
||||
}
|
||||
|
||||
if (type === "return" ||
|
||||
@@ -833,7 +863,7 @@ function isValidCompletion(record) {
|
||||
// targets, but minimizing the number of switch cases keeps the generated
|
||||
// code shorter.
|
||||
Ep.getUnmarkedCurrentLoc = function() {
|
||||
return t.numericLiteral(this.listing.length);
|
||||
return util.getTypes().numericLiteral(this.listing.length);
|
||||
};
|
||||
|
||||
// The context.prev property takes the value of context.next whenever we
|
||||
@@ -847,6 +877,7 @@ Ep.getUnmarkedCurrentLoc = function() {
|
||||
// precision at all times, but we don't have that luxury here, as it would
|
||||
// be costly and verbose to set context.prev before every statement.
|
||||
Ep.updateContextPrevLoc = function(loc) {
|
||||
const t = util.getTypes();
|
||||
if (loc) {
|
||||
t.assertLiteral(loc);
|
||||
|
||||
@@ -870,6 +901,7 @@ Ep.updateContextPrevLoc = function(loc) {
|
||||
};
|
||||
|
||||
Ep.explodeExpression = function(path, ignoreResult) {
|
||||
const t = util.getTypes();
|
||||
let expr = path.node;
|
||||
if (expr) {
|
||||
t.assertExpression(expr);
|
||||
@@ -994,7 +1026,7 @@ Ep.explodeExpression = function(path, ignoreResult) {
|
||||
|
||||
newCallee = t.memberExpression(
|
||||
t.memberExpression(
|
||||
newObject,
|
||||
t.cloneDeep(newObject),
|
||||
newProperty,
|
||||
calleePath.node.computed
|
||||
),
|
||||
@@ -1020,7 +1052,7 @@ Ep.explodeExpression = function(path, ignoreResult) {
|
||||
// object.
|
||||
newCallee = t.sequenceExpression([
|
||||
t.numericLiteral(0),
|
||||
newCallee
|
||||
t.cloneDeep(newCallee)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1031,7 +1063,7 @@ Ep.explodeExpression = function(path, ignoreResult) {
|
||||
|
||||
return finish(t.callExpression(
|
||||
newCallee,
|
||||
newArgs
|
||||
newArgs.map(arg => t.cloneDeep(arg))
|
||||
));
|
||||
|
||||
case "NewExpression":
|
||||
@@ -1078,7 +1110,7 @@ Ep.explodeExpression = function(path, ignoreResult) {
|
||||
return result;
|
||||
|
||||
case "LogicalExpression":
|
||||
after = loc();
|
||||
after = this.loc();
|
||||
|
||||
if (!ignoreResult) {
|
||||
result = self.makeTempVar();
|
||||
@@ -1100,8 +1132,8 @@ Ep.explodeExpression = function(path, ignoreResult) {
|
||||
return result;
|
||||
|
||||
case "ConditionalExpression":
|
||||
let elseLoc = loc();
|
||||
after = loc();
|
||||
let elseLoc = this.loc();
|
||||
after = this.loc();
|
||||
let test = self.explodeExpression(path.get("test"));
|
||||
|
||||
self.jumpIfNot(test, elseLoc);
|
||||
@@ -1137,10 +1169,40 @@ Ep.explodeExpression = function(path, ignoreResult) {
|
||||
));
|
||||
|
||||
case "AssignmentExpression":
|
||||
if (expr.operator === "=") {
|
||||
// If this is a simple assignment, the left hand side does not need
|
||||
// to be read before the right hand side is evaluated, so we can
|
||||
// avoid the more complicated logic below.
|
||||
return finish(t.assignmentExpression(
|
||||
expr.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);
|
||||
|
||||
// For example,
|
||||
//
|
||||
// x += yield y
|
||||
//
|
||||
// becomes
|
||||
//
|
||||
// context.t0 = x
|
||||
// x = context.t0 += yield y
|
||||
//
|
||||
// so that the left-hand side expression is read before the yield.
|
||||
// Fixes https://github.com/facebook/regenerator/issues/345.
|
||||
|
||||
return finish(t.assignmentExpression(
|
||||
expr.operator,
|
||||
self.explodeExpression(path.get("left")),
|
||||
self.explodeExpression(path.get("right"))
|
||||
"=",
|
||||
t.cloneDeep(lhs),
|
||||
t.assignmentExpression(
|
||||
expr.operator,
|
||||
t.cloneDeep(temp),
|
||||
self.explodeExpression(path.get("right"))
|
||||
)
|
||||
));
|
||||
|
||||
case "UpdateExpression":
|
||||
@@ -1151,27 +1213,35 @@ Ep.explodeExpression = function(path, ignoreResult) {
|
||||
));
|
||||
|
||||
case "YieldExpression":
|
||||
after = loc();
|
||||
after = this.loc();
|
||||
let arg = expr.argument && self.explodeExpression(path.get("argument"));
|
||||
|
||||
if (arg && expr.delegate) {
|
||||
let result = self.makeTempVar();
|
||||
|
||||
self.emit(t.returnStatement(t.callExpression(
|
||||
self.contextProperty("delegateYield"), [
|
||||
let ret = t.returnStatement(t.callExpression(
|
||||
self.contextProperty("delegateYield"),
|
||||
[
|
||||
arg,
|
||||
t.stringLiteral(result.property.name),
|
||||
after
|
||||
]
|
||||
)));
|
||||
));
|
||||
ret.loc = expr.loc;
|
||||
|
||||
self.emit(ret);
|
||||
self.mark(after);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
self.emitAssign(self.contextProperty("next"), after);
|
||||
self.emit(t.returnStatement(arg || null));
|
||||
|
||||
let ret = t.returnStatement(t.cloneDeep(arg) || null);
|
||||
// Preserve the `yield` location so that source mappings for the statements
|
||||
// link back to the yield properly.
|
||||
ret.loc = expr.loc;
|
||||
self.emit(ret);
|
||||
self.mark(after);
|
||||
|
||||
return self.contextProperty("sent");
|
||||
|
||||
20
node_modules/regenerator-transform/src/hoist.js
generated
vendored
20
node_modules/regenerator-transform/src/hoist.js
generated
vendored
@@ -1,14 +1,10 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
* additional grant of patent rights can be found in the PATENTS file in
|
||||
* the same directory.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import * as t from "babel-types";
|
||||
import * as util from "./util";
|
||||
let hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
@@ -17,6 +13,7 @@ let hasOwn = Object.prototype.hasOwnProperty;
|
||||
// returns a VariableDeclaration containing just the names of the removed
|
||||
// declarations.
|
||||
exports.hoist = function(funPath) {
|
||||
const t = util.getTypes();
|
||||
t.assertFunction(funPath.node);
|
||||
|
||||
let vars = {};
|
||||
@@ -88,9 +85,9 @@ exports.hoist = function(funPath) {
|
||||
let assignment = t.expressionStatement(
|
||||
t.assignmentExpression(
|
||||
"=",
|
||||
node.id,
|
||||
t.clone(node.id),
|
||||
t.functionExpression(
|
||||
node.id,
|
||||
path.scope.generateUidIdentifierBasedOnNode(node),
|
||||
node.params,
|
||||
node.body,
|
||||
node.generator,
|
||||
@@ -121,6 +118,11 @@ exports.hoist = function(funPath) {
|
||||
FunctionExpression: function(path) {
|
||||
// Don't descend into nested function expressions.
|
||||
path.skip();
|
||||
},
|
||||
|
||||
ArrowFunctionExpression: function(path) {
|
||||
// Don't descend into nested function expressions.
|
||||
path.skip();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
13
node_modules/regenerator-transform/src/index.js
generated
vendored
13
node_modules/regenerator-transform/src/index.js
generated
vendored
@@ -1,16 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
* additional grant of patent rights can be found in the PATENTS file in
|
||||
* the same directory.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { getVisitor } from "./visit";
|
||||
|
||||
export default function (context) {
|
||||
const plugin = {
|
||||
visitor: require("./visit").visitor,
|
||||
visitor: getVisitor(context),
|
||||
};
|
||||
|
||||
// Some presets manually call child presets, but fail to pass along the
|
||||
|
||||
25
node_modules/regenerator-transform/src/leap.js
generated
vendored
25
node_modules/regenerator-transform/src/leap.js
generated
vendored
@@ -1,16 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
* additional grant of patent rights can be found in the PATENTS file in
|
||||
* the same directory.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import assert from "assert";
|
||||
import * as t from "babel-types";
|
||||
import { Emitter } from "./emit";
|
||||
import { inherits } from "util";
|
||||
import { getTypes } from "./util";
|
||||
|
||||
function Entry() {
|
||||
assert.ok(this instanceof Entry);
|
||||
@@ -18,7 +16,7 @@ function Entry() {
|
||||
|
||||
function FunctionEntry(returnLoc) {
|
||||
Entry.call(this);
|
||||
t.assertLiteral(returnLoc);
|
||||
getTypes().assertLiteral(returnLoc);
|
||||
this.returnLoc = returnLoc;
|
||||
}
|
||||
|
||||
@@ -28,6 +26,8 @@ exports.FunctionEntry = FunctionEntry;
|
||||
function LoopEntry(breakLoc, continueLoc, label) {
|
||||
Entry.call(this);
|
||||
|
||||
const t = getTypes();
|
||||
|
||||
t.assertLiteral(breakLoc);
|
||||
t.assertLiteral(continueLoc);
|
||||
|
||||
@@ -47,7 +47,7 @@ exports.LoopEntry = LoopEntry;
|
||||
|
||||
function SwitchEntry(breakLoc) {
|
||||
Entry.call(this);
|
||||
t.assertLiteral(breakLoc);
|
||||
getTypes().assertLiteral(breakLoc);
|
||||
this.breakLoc = breakLoc;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ exports.SwitchEntry = SwitchEntry;
|
||||
function TryEntry(firstLoc, catchEntry, finallyEntry) {
|
||||
Entry.call(this);
|
||||
|
||||
const t = getTypes();
|
||||
t.assertLiteral(firstLoc);
|
||||
|
||||
if (catchEntry) {
|
||||
@@ -85,6 +86,8 @@ exports.TryEntry = TryEntry;
|
||||
function CatchEntry(firstLoc, paramId) {
|
||||
Entry.call(this);
|
||||
|
||||
const t = getTypes();
|
||||
|
||||
t.assertLiteral(firstLoc);
|
||||
t.assertIdentifier(paramId);
|
||||
|
||||
@@ -97,6 +100,7 @@ exports.CatchEntry = CatchEntry;
|
||||
|
||||
function FinallyEntry(firstLoc, afterLoc) {
|
||||
Entry.call(this);
|
||||
const t = getTypes();
|
||||
t.assertLiteral(firstLoc);
|
||||
t.assertLiteral(afterLoc);
|
||||
this.firstLoc = firstLoc;
|
||||
@@ -109,6 +113,8 @@ exports.FinallyEntry = FinallyEntry;
|
||||
function LabeledEntry(breakLoc, label) {
|
||||
Entry.call(this);
|
||||
|
||||
const t = getTypes();
|
||||
|
||||
t.assertLiteral(breakLoc);
|
||||
t.assertIdentifier(label);
|
||||
|
||||
@@ -122,7 +128,6 @@ exports.LabeledEntry = LabeledEntry;
|
||||
function LeapManager(emitter) {
|
||||
assert.ok(this instanceof LeapManager);
|
||||
|
||||
let Emitter = require("./emit").Emitter;
|
||||
assert.ok(emitter instanceof Emitter);
|
||||
|
||||
this.emitter = emitter;
|
||||
|
||||
18
node_modules/regenerator-transform/src/meta.js
generated
vendored
18
node_modules/regenerator-transform/src/meta.js
generated
vendored
@@ -1,20 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
* additional grant of patent rights can be found in the PATENTS file in
|
||||
* the same directory.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import assert from "assert";
|
||||
let m = require("private").makeAccessor();
|
||||
import * as t from "babel-types";
|
||||
import { getTypes } from "./util.js";
|
||||
import { makeAccessor } from "private";
|
||||
|
||||
let m = makeAccessor();
|
||||
let hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
function makePredicate(propertyName, knownTypes) {
|
||||
function onlyChildren(node) {
|
||||
const t = getTypes();
|
||||
t.assertNode(node);
|
||||
|
||||
// Assume no side effects until we find out otherwise.
|
||||
@@ -45,7 +45,7 @@ function makePredicate(propertyName, knownTypes) {
|
||||
}
|
||||
|
||||
function predicate(node) {
|
||||
t.assertNode(node);
|
||||
getTypes().assertNode(node);
|
||||
|
||||
let meta = m(node);
|
||||
if (hasOwn.call(meta, propertyName))
|
||||
|
||||
10
node_modules/regenerator-transform/src/replaceShorthandObjectMethod.js
generated
vendored
10
node_modules/regenerator-transform/src/replaceShorthandObjectMethod.js
generated
vendored
@@ -1,4 +1,10 @@
|
||||
import * as t from "babel-types";
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import * as util from "./util";
|
||||
|
||||
// this function converts a shorthand object generator method into a normal
|
||||
@@ -30,6 +36,8 @@ import * as util from "./util";
|
||||
// If this function is called with an AST node path that is not a Function (or with an
|
||||
// argument that isn't an AST node path), it will throw an error.
|
||||
export default function replaceShorthandObjectMethod(path) {
|
||||
const t = util.getTypes();
|
||||
|
||||
if (!path.node || !t.isFunction(path.node)) {
|
||||
throw new Error("replaceShorthandObjectMethod can only be called on Function AST node paths.");
|
||||
}
|
||||
|
||||
28
node_modules/regenerator-transform/src/util.js
generated
vendored
28
node_modules/regenerator-transform/src/util.js
generated
vendored
@@ -1,16 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
* additional grant of patent rights can be found in the PATENTS file in
|
||||
* the same directory.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import * as t from "babel-types";
|
||||
let currentTypes = null;
|
||||
|
||||
export function wrapWithTypes(types, fn) {
|
||||
return function (...args) {
|
||||
const oldTypes = currentTypes;
|
||||
currentTypes = types;
|
||||
try {
|
||||
return fn.apply(this, args);
|
||||
} finally {
|
||||
currentTypes = oldTypes;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function getTypes() {
|
||||
return currentTypes;
|
||||
}
|
||||
|
||||
export function runtimeProperty(name) {
|
||||
const t = getTypes();
|
||||
return t.memberExpression(
|
||||
t.identifier("regeneratorRuntime"),
|
||||
t.identifier(name),
|
||||
|
||||
112
node_modules/regenerator-transform/src/visit.js
generated
vendored
112
node_modules/regenerator-transform/src/visit.js
generated
vendored
@@ -1,25 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
* additional grant of patent rights can be found in the PATENTS file in
|
||||
* the same directory.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import assert from "assert";
|
||||
import * as t from "babel-types";
|
||||
import { hoist } from "./hoist";
|
||||
import { Emitter } from "./emit";
|
||||
import replaceShorthandObjectMethod from "./replaceShorthandObjectMethod";
|
||||
import * as util from "./util";
|
||||
import { makeAccessor } from "private";
|
||||
|
||||
exports.visitor = {
|
||||
exports.getVisitor = ({ types: t }) => ({
|
||||
Function: {
|
||||
exit: function(path, state) {
|
||||
exit: util.wrapWithTypes(t, function(path, state) {
|
||||
let node = path.node;
|
||||
|
||||
if (node.generator) {
|
||||
@@ -93,14 +90,20 @@ exports.visitor = {
|
||||
// declarations with equivalent assignment expressions.
|
||||
let vars = hoist(path);
|
||||
|
||||
let didRenameArguments = renameArguments(path, argsId);
|
||||
if (didRenameArguments) {
|
||||
let context = {
|
||||
usesThis: false,
|
||||
usesArguments: false,
|
||||
getArgsId: () => t.clone(argsId),
|
||||
};
|
||||
path.traverse(argumentsThisVisitor, context);
|
||||
|
||||
if (context.usesArguments) {
|
||||
vars = vars || t.variableDeclaration("var", []);
|
||||
const argumentIdentifier = t.identifier("arguments");
|
||||
// we need to do this as otherwise arguments in arrow functions gets hoisted
|
||||
argumentIdentifier._shadowedFunctionLiteral = path;
|
||||
vars.declarations.push(t.variableDeclarator(
|
||||
argsId, argumentIdentifier
|
||||
t.clone(argsId), argumentIdentifier
|
||||
));
|
||||
}
|
||||
|
||||
@@ -111,16 +114,22 @@ exports.visitor = {
|
||||
outerBody.push(vars);
|
||||
}
|
||||
|
||||
let wrapArgs = [
|
||||
emitter.getContextFunction(innerFnId),
|
||||
let wrapArgs = [emitter.getContextFunction(innerFnId)];
|
||||
let tryLocsList = emitter.getTryLocsList();
|
||||
|
||||
if (node.generator) {
|
||||
wrapArgs.push(outerFnExpr);
|
||||
} else if (context.usesThis || tryLocsList) {
|
||||
// Async functions that are not generators don't care about the
|
||||
// outer function because they don't need it to be marked and don't
|
||||
// inherit from its .prototype.
|
||||
node.generator ? outerFnExpr : t.nullLiteral(),
|
||||
t.thisExpression()
|
||||
];
|
||||
|
||||
let tryLocsList = emitter.getTryLocsList();
|
||||
wrapArgs.push(t.nullLiteral());
|
||||
}
|
||||
if (context.usesThis) {
|
||||
wrapArgs.push(t.thisExpression());
|
||||
} else if (tryLocsList) {
|
||||
wrapArgs.push(t.nullLiteral());
|
||||
}
|
||||
if (tryLocsList) {
|
||||
wrapArgs.push(tryLocsList);
|
||||
}
|
||||
@@ -154,19 +163,32 @@ exports.visitor = {
|
||||
path.addComment("leading", "#__PURE__");
|
||||
}
|
||||
|
||||
const insertedLocs = emitter.getInsertedLocs();
|
||||
|
||||
path.traverse({
|
||||
NumericLiteral(path) {
|
||||
if (!insertedLocs.has(path.node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
path.replaceWith(t.numericLiteral(path.node.value));
|
||||
},
|
||||
})
|
||||
|
||||
// Generators are processed in 'exit' handlers so that regenerator only has to run on
|
||||
// an ES5 AST, but that means traversal will not pick up newly inserted references
|
||||
// to things like 'regeneratorRuntime'. To avoid this, we explicitly requeue.
|
||||
path.requeue();
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// Given a NodePath for a Function, return an Expression node that can be
|
||||
// used to refer reliably to the function object from inside the function.
|
||||
// This expression is essentially a replacement for arguments.callee, with
|
||||
// the key advantage that it works in strict mode.
|
||||
function getOuterFnExpr(funPath) {
|
||||
const t = util.getTypes();
|
||||
let node = funPath.node;
|
||||
t.assertFunction(node);
|
||||
|
||||
@@ -182,12 +204,13 @@ function getOuterFnExpr(funPath) {
|
||||
return getMarkedFunctionId(funPath);
|
||||
}
|
||||
|
||||
return node.id;
|
||||
return t.clone(node.id);
|
||||
}
|
||||
|
||||
const getMarkInfo = require("private").makeAccessor();
|
||||
const getMarkInfo = makeAccessor();
|
||||
|
||||
function getMarkedFunctionId(funPath) {
|
||||
const t = util.getTypes();
|
||||
const node = funPath.node;
|
||||
t.assertIdentifier(node.id);
|
||||
|
||||
@@ -215,7 +238,7 @@ function getMarkedFunctionId(funPath) {
|
||||
const markedId = blockPath.scope.generateUidIdentifier("marked");
|
||||
const markCallExp = t.callExpression(
|
||||
util.runtimeProperty("mark"),
|
||||
[node.id]
|
||||
[t.clone(node.id)]
|
||||
);
|
||||
|
||||
const index = info.decl.declarations.push(
|
||||
@@ -229,34 +252,23 @@ function getMarkedFunctionId(funPath) {
|
||||
|
||||
markCallExpPath.addComment("leading", "#__PURE__");
|
||||
|
||||
return markedId;
|
||||
return t.clone(markedId);
|
||||
}
|
||||
|
||||
function renameArguments(funcPath, argsId) {
|
||||
let state = {
|
||||
didRenameArguments: false,
|
||||
argsId: argsId
|
||||
};
|
||||
|
||||
funcPath.traverse(argumentsVisitor, state);
|
||||
|
||||
// If the traversal replaced any arguments references, then we need to
|
||||
// alias the outer function's arguments binding (be it the implicit
|
||||
// arguments object or some other parameter or variable) to the variable
|
||||
// named by argsId.
|
||||
return state.didRenameArguments;
|
||||
}
|
||||
|
||||
let argumentsVisitor = {
|
||||
let argumentsThisVisitor = {
|
||||
"FunctionExpression|FunctionDeclaration": function(path) {
|
||||
path.skip();
|
||||
},
|
||||
|
||||
Identifier: function(path, state) {
|
||||
if (path.node.name === "arguments" && util.isReference(path)) {
|
||||
util.replaceWithOrRemove(path, state.argsId);
|
||||
state.didRenameArguments = true;
|
||||
util.replaceWithOrRemove(path, state.getArgsId());
|
||||
state.usesArguments = true;
|
||||
}
|
||||
},
|
||||
|
||||
ThisExpression: function(path, state) {
|
||||
state.usesThis = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -264,8 +276,16 @@ let functionSentVisitor = {
|
||||
MetaProperty(path) {
|
||||
let { node } = path;
|
||||
|
||||
if (node.meta.name === "function" && node.property.name === "sent") {
|
||||
util.replaceWithOrRemove(path, t.memberExpression(this.context, t.identifier("_sent")));
|
||||
if (node.meta.name === "function" &&
|
||||
node.property.name === "sent") {
|
||||
const t = util.getTypes();
|
||||
util.replaceWithOrRemove(
|
||||
path,
|
||||
t.memberExpression(
|
||||
t.clone(this.context),
|
||||
t.identifier("_sent")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -276,6 +296,8 @@ let awaitVisitor = {
|
||||
},
|
||||
|
||||
AwaitExpression: function(path) {
|
||||
const t = util.getTypes();
|
||||
|
||||
// Convert await expressions to yield expressions.
|
||||
let argument = path.node.argument;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user