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");
|
||||
|
||||
Reference in New Issue
Block a user