nav tabs on admin dashboard

This commit is contained in:
2019-03-07 00:20:34 -06:00
parent f73d6ae228
commit e4f473f376
11661 changed files with 216240 additions and 1544253 deletions
+223 -271
View File
File diff suppressed because it is too large Load Diff
+29 -52
View File
@@ -1,47 +1,29 @@
"use strict";
var _keys = require("babel-runtime/core-js/object/keys");
var util = _interopRequireWildcard(require("./util"));
var _keys2 = _interopRequireDefault(_keys);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _util = require("./util");
var util = _interopRequireWildcard(_util);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
/**
* 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.
*/
var hasOwn = Object.prototype.hasOwnProperty;
// The hoist function takes a FunctionExpression or FunctionDeclaration
var hasOwn = Object.prototype.hasOwnProperty; // The hoist function takes a FunctionExpression or FunctionDeclaration
// and replaces any Declaration nodes in its body with assignments, then
// returns a VariableDeclaration containing just the names of the removed
// declarations.
exports.hoist = function (funPath) {
t.assertFunction(funPath.node);
exports.hoist = function (funPath) {
var t = util.getTypes();
t.assertFunction(funPath.node);
var vars = {};
function varDeclToExpr(vdec, includeIdentifiers) {
t.assertVariableDeclaration(vdec);
// TODO assert.equal(vdec.kind, "var");
var exprs = [];
t.assertVariableDeclaration(vdec); // TODO assert.equal(vdec.kind, "var");
var exprs = [];
vdec.declarations.forEach(function (dec) {
// Note: We duplicate 'dec.id' here to ensure that the variable declaration IDs don't
// have the same 'loc' value, since that can make sourcemaps and retainLines behave poorly.
@@ -53,11 +35,8 @@ exports.hoist = function (funPath) {
exprs.push(dec.id);
}
});
if (exprs.length === 0) return null;
if (exprs.length === 1) return exprs[0];
return t.sequenceExpression(exprs);
}
@@ -65,79 +44,77 @@ exports.hoist = function (funPath) {
VariableDeclaration: {
exit: function exit(path) {
var expr = varDeclToExpr(path.node, false);
if (expr === null) {
path.remove();
} else {
// We don't need to traverse this expression any further because
// there can't be any new declarations inside an expression.
util.replaceWithOrRemove(path, t.expressionStatement(expr));
}
// Since the original node has been either removed or replaced,
} // Since the original node has been either removed or replaced,
// avoid traversing it any further.
path.skip();
}
},
ForStatement: function ForStatement(path) {
var init = path.node.init;
if (t.isVariableDeclaration(init)) {
util.replaceWithOrRemove(path.get("init"), varDeclToExpr(init, false));
}
},
ForXStatement: function ForXStatement(path) {
var left = path.get("left");
if (left.isVariableDeclaration()) {
util.replaceWithOrRemove(left, varDeclToExpr(left.node, true));
}
},
FunctionDeclaration: function FunctionDeclaration(path) {
var node = path.node;
vars[node.id.name] = node.id;
var assignment = t.expressionStatement(t.assignmentExpression("=", node.id, t.functionExpression(node.id, node.params, node.body, node.generator, node.expression)));
var assignment = t.expressionStatement(t.assignmentExpression("=", t.clone(node.id), t.functionExpression(path.scope.generateUidIdentifierBasedOnNode(node), node.params, node.body, node.generator, node.expression)));
if (path.parentPath.isBlockStatement()) {
// Insert the assignment form before the first statement in the
// enclosing block.
path.parentPath.unshiftContainer("body", assignment);
// Remove the function declaration now that we've inserted the
path.parentPath.unshiftContainer("body", assignment); // Remove the function declaration now that we've inserted the
// equivalent assignment form at the beginning of the block.
path.remove();
} else {
// If the parent node is not a block statement, then we can just
// replace the declaration with the equivalent assignment form
// without worrying about hoisting it.
util.replaceWithOrRemove(path, assignment);
}
} // Don't hoist variables out of inner functions.
// Don't hoist variables out of inner functions.
path.skip();
},
FunctionExpression: function FunctionExpression(path) {
// Don't descend into nested function expressions.
path.skip();
},
ArrowFunctionExpression: function ArrowFunctionExpression(path) {
// Don't descend into nested function expressions.
path.skip();
}
});
var paramNames = {};
funPath.get("params").forEach(function (paramPath) {
var param = paramPath.node;
if (t.isIdentifier(param)) {
paramNames[param.name] = param;
} else {
// Variables declared by destructuring parameter patterns will be
} else {// Variables declared by destructuring parameter patterns will be
// harmlessly re-declared.
}
});
var declarations = [];
(0, _keys2.default)(vars).forEach(function (name) {
Object.keys(vars).forEach(function (name) {
if (!hasOwn.call(paramNames, name)) {
declarations.push(t.variableDeclarator(vars[name], null));
}
+15 -8
View File
@@ -1,22 +1,29 @@
"use strict";
exports.__esModule = true;
exports.default = _default;
exports.default = function (context) {
var _visit = require("./visit");
/**
* 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.
*/
function _default(context) {
var plugin = {
visitor: require("./visit").visitor
};
// Some presets manually call child presets, but fail to pass along the
visitor: (0, _visit.getVisitor)(context)
}; // Some presets manually call child presets, but fail to pass along the
// context object. Out of an abundance of caution, we verify that it
// exists first to avoid causing unnecessary breaking changes.
var version = context && context.version;
// The "name" property is not allowed in older versions of Babel (6.x)
var version = context && context.version; // The "name" property is not allowed in older versions of Babel (6.x)
// and will cause the plugin validator to throw an exception.
if (version && parseInt(version, 10) >= 7) {
plugin.name = "regenerator-transform";
}
return plugin;
};
}
+32 -37
View File
@@ -1,34 +1,28 @@
"use strict";
var _assert = require("assert");
var _assert = _interopRequireDefault(require("assert"));
var _assert2 = _interopRequireDefault(_assert);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _emit = require("./emit");
var _util = require("util");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var _util2 = require("./util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* 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.
*/
function Entry() {
_assert2.default.ok(this instanceof Entry);
} /**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* 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.
*/
_assert.default.ok(this instanceof Entry);
}
function FunctionEntry(returnLoc) {
Entry.call(this);
t.assertLiteral(returnLoc);
(0, _util2.getTypes)().assertLiteral(returnLoc);
this.returnLoc = returnLoc;
}
@@ -37,7 +31,7 @@ exports.FunctionEntry = FunctionEntry;
function LoopEntry(breakLoc, continueLoc, label) {
Entry.call(this);
var t = (0, _util2.getTypes)();
t.assertLiteral(breakLoc);
t.assertLiteral(continueLoc);
@@ -57,7 +51,7 @@ exports.LoopEntry = LoopEntry;
function SwitchEntry(breakLoc) {
Entry.call(this);
t.assertLiteral(breakLoc);
(0, _util2.getTypes)().assertLiteral(breakLoc);
this.breakLoc = breakLoc;
}
@@ -66,23 +60,23 @@ exports.SwitchEntry = SwitchEntry;
function TryEntry(firstLoc, catchEntry, finallyEntry) {
Entry.call(this);
var t = (0, _util2.getTypes)();
t.assertLiteral(firstLoc);
if (catchEntry) {
_assert2.default.ok(catchEntry instanceof CatchEntry);
_assert.default.ok(catchEntry instanceof CatchEntry);
} else {
catchEntry = null;
}
if (finallyEntry) {
_assert2.default.ok(finallyEntry instanceof FinallyEntry);
_assert.default.ok(finallyEntry instanceof FinallyEntry);
} else {
finallyEntry = null;
}
} // Have to have one or the other (or both).
// Have to have one or the other (or both).
_assert2.default.ok(catchEntry || finallyEntry);
_assert.default.ok(catchEntry || finallyEntry);
this.firstLoc = firstLoc;
this.catchEntry = catchEntry;
@@ -94,10 +88,9 @@ exports.TryEntry = TryEntry;
function CatchEntry(firstLoc, paramId) {
Entry.call(this);
var t = (0, _util2.getTypes)();
t.assertLiteral(firstLoc);
t.assertIdentifier(paramId);
this.firstLoc = firstLoc;
this.paramId = paramId;
}
@@ -107,6 +100,7 @@ exports.CatchEntry = CatchEntry;
function FinallyEntry(firstLoc, afterLoc) {
Entry.call(this);
var t = (0, _util2.getTypes)();
t.assertLiteral(firstLoc);
t.assertLiteral(afterLoc);
this.firstLoc = firstLoc;
@@ -118,10 +112,9 @@ exports.FinallyEntry = FinallyEntry;
function LabeledEntry(breakLoc, label) {
Entry.call(this);
var t = (0, _util2.getTypes)();
t.assertLiteral(breakLoc);
t.assertIdentifier(label);
this.breakLoc = breakLoc;
this.label = label;
}
@@ -130,10 +123,9 @@ function LabeledEntry(breakLoc, label) {
exports.LabeledEntry = LabeledEntry;
function LeapManager(emitter) {
_assert2.default.ok(this instanceof LeapManager);
_assert.default.ok(this instanceof LeapManager);
var Emitter = require("./emit").Emitter;
_assert2.default.ok(emitter instanceof Emitter);
_assert.default.ok(emitter instanceof _emit.Emitter);
this.emitter = emitter;
this.entryStack = [new FunctionEntry(emitter.finalLoc)];
@@ -143,13 +135,16 @@ var LMp = LeapManager.prototype;
exports.LeapManager = LeapManager;
LMp.withEntry = function (entry, callback) {
_assert2.default.ok(entry instanceof Entry);
_assert.default.ok(entry instanceof Entry);
this.entryStack.push(entry);
try {
callback.call(this.emitter);
} finally {
var popped = this.entryStack.pop();
_assert2.default.strictEqual(popped, entry);
_assert.default.strictEqual(popped, entry);
}
};
@@ -157,13 +152,13 @@ LMp._findLeapLocation = function (property, label) {
for (var i = this.entryStack.length - 1; i >= 0; --i) {
var entry = this.entryStack[i];
var loc = entry[property];
if (loc) {
if (label) {
if (entry.label && entry.label.name === label.name) {
return loc;
}
} else if (entry instanceof LabeledEntry) {
// Ignore LabeledEntry entries unless we are actually breaking to
} else if (entry instanceof LabeledEntry) {// Ignore LabeledEntry entries unless we are actually breaking to
// a label.
} else {
return loc;
+39 -45
View File
@@ -1,49 +1,44 @@
"use strict";
var _assert = require("assert");
var _assert = _interopRequireDefault(require("assert"));
var _assert2 = _interopRequireDefault(_assert);
var _util = require("./util.js");
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var _private = require("private");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var m = require("private").makeAccessor(); /**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* 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.
*/
/**
* 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.
*/
var m = (0, _private.makeAccessor)();
var hasOwn = Object.prototype.hasOwnProperty;
function makePredicate(propertyName, knownTypes) {
function onlyChildren(node) {
t.assertNode(node);
var t = (0, _util.getTypes)();
t.assertNode(node); // Assume no side effects until we find out otherwise.
// Assume no side effects until we find out otherwise.
var result = false;
function check(child) {
if (result) {
// Do nothing.
if (result) {// Do nothing.
} else if (Array.isArray(child)) {
child.some(check);
} else if (t.isNode(child)) {
_assert2.default.strictEqual(result, false);
_assert.default.strictEqual(result, false);
result = predicate(child);
}
return result;
}
var keys = t.VISITOR_KEYS[node.type];
if (keys) {
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
@@ -56,52 +51,51 @@ function makePredicate(propertyName, knownTypes) {
}
function predicate(node) {
t.assertNode(node);
(0, _util.getTypes)().assertNode(node);
var meta = m(node);
if (hasOwn.call(meta, propertyName)) return meta[propertyName];
// Certain types are "opaque," which means they have no side
if (hasOwn.call(meta, propertyName)) return meta[propertyName]; // Certain types are "opaque," which means they have no side
// effects or leaps and we don't care about their subexpressions.
if (hasOwn.call(opaqueTypes, node.type)) return meta[propertyName] = false;
if (hasOwn.call(knownTypes, node.type)) return meta[propertyName] = true;
return meta[propertyName] = onlyChildren(node);
}
predicate.onlyChildren = onlyChildren;
return predicate;
}
var opaqueTypes = {
FunctionExpression: true,
ArrowFunctionExpression: true
};
// These types potentially have side effects regardless of what side
}; // These types potentially have side effects regardless of what side
// effects their subexpressions have.
var sideEffectTypes = {
CallExpression: true, // Anything could happen!
ForInStatement: true, // Modifies the key variable.
UnaryExpression: true, // Think delete.
BinaryExpression: true, // Might invoke .toString() or .valueOf().
AssignmentExpression: true, // Side-effecting by definition.
UpdateExpression: true, // Updates are essentially assignments.
NewExpression: true // Similar to CallExpression.
};
// These types are the direct cause of all leaps in control flow.
var sideEffectTypes = {
CallExpression: true,
// Anything could happen!
ForInStatement: true,
// Modifies the key variable.
UnaryExpression: true,
// Think delete.
BinaryExpression: true,
// Might invoke .toString() or .valueOf().
AssignmentExpression: true,
// Side-effecting by definition.
UpdateExpression: true,
// Updates are essentially assignments.
NewExpression: true // Similar to CallExpression.
}; // These types are the direct cause of all leaps in control flow.
var leapTypes = {
YieldExpression: true,
BreakStatement: true,
ContinueStatement: true,
ReturnStatement: true,
ThrowStatement: true
};
}; // All leap types are also side effect types.
// All leap types are also side effect types.
for (var type in leapTypes) {
if (hasOwn.call(leapTypes, type)) {
sideEffectTypes[type] = leapTypes[type];
+17 -18
View File
@@ -3,16 +3,16 @@
exports.__esModule = true;
exports.default = replaceShorthandObjectMethod;
var _babelTypes = require("babel-types");
var util = _interopRequireWildcard(require("./util"));
var t = _interopRequireWildcard(_babelTypes);
var _util = require("./util");
var util = _interopRequireWildcard(_util);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
/**
* 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.
*/
// this function converts a shorthand object generator method into a normal
// (non-shorthand) object property which is a generator function expression. for
// example, this:
@@ -42,17 +42,19 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
// 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.
function replaceShorthandObjectMethod(path) {
var t = util.getTypes();
if (!path.node || !t.isFunction(path.node)) {
throw new Error("replaceShorthandObjectMethod can only be called on Function AST node paths.");
}
// this function only replaces shorthand object methods (called ObjectMethod
} // this function only replaces shorthand object methods (called ObjectMethod
// in Babel-speak).
if (!t.isObjectMethod(path.node)) {
return path;
}
} // this function only replaces generators.
// this function only replaces generators.
if (!path.node.generator) {
return path;
}
@@ -60,21 +62,18 @@ function replaceShorthandObjectMethod(path) {
var parameters = path.node.params.map(function (param) {
return t.cloneDeep(param);
});
var functionExpression = t.functionExpression(null, // id
parameters, // params
t.cloneDeep(path.node.body), // body
path.node.generator, path.node.async);
util.replaceWithOrRemove(path, t.objectProperty(t.cloneDeep(path.node.key), // key
functionExpression, //value
path.node.computed, // computed
false // shorthand
));
// path now refers to the ObjectProperty AST node path, but we want to return a
)); // path now refers to the ObjectProperty AST node path, but we want to return a
// Function AST node path for the function expression we created. we know that
// the FunctionExpression we just created is the value of the ObjectProperty,
// so return the "value" path off of this path.
return path.get("value");
}
+33 -13
View File
@@ -1,30 +1,50 @@
"use strict";
exports.__esModule = true;
exports.wrapWithTypes = wrapWithTypes;
exports.getTypes = getTypes;
exports.runtimeProperty = runtimeProperty;
exports.isReference = isReference;
exports.replaceWithOrRemove = replaceWithOrRemove;
var _babelTypes = require("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.
*/
var currentTypes = null;
var t = _interopRequireWildcard(_babelTypes);
function wrapWithTypes(types, fn) {
return function () {
var oldTypes = currentTypes;
currentTypes = types;
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
try {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return fn.apply(this, args);
} finally {
currentTypes = oldTypes;
}
};
}
function getTypes() {
return currentTypes;
}
function runtimeProperty(name) {
var t = getTypes();
return t.memberExpression(t.identifier("regeneratorRuntime"), t.identifier(name), false);
} /**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* 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.
*/
}
function isReference(path) {
return path.isReferenced() || path.parentPath.isAssignmentExpression({ left: path.node });
return path.isReferenced() || path.parentPath.isAssignmentExpression({
left: path.node
});
}
function replaceWithOrRemove(path, replacement) {
+172 -173
View File
@@ -1,180 +1,196 @@
/**
* 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";
var _assert = require("assert");
var _assert2 = _interopRequireDefault(_assert);
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _assert = _interopRequireDefault(require("assert"));
var _hoist = require("./hoist");
var _emit = require("./emit");
var _replaceShorthandObjectMethod = require("./replaceShorthandObjectMethod");
var _replaceShorthandObjectMethod = _interopRequireDefault(require("./replaceShorthandObjectMethod"));
var _replaceShorthandObjectMethod2 = _interopRequireDefault(_replaceShorthandObjectMethod);
var util = _interopRequireWildcard(require("./util"));
var _util = require("./util");
var _private = require("private");
var util = _interopRequireWildcard(_util);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.visitor = {
Function: {
exit: function exit(path, state) {
var node = path.node;
exports.getVisitor = function (_ref) {
var t = _ref.types;
return {
Function: {
exit: util.wrapWithTypes(t, function (path, state) {
var node = path.node;
if (node.generator) {
if (node.async) {
// Async generator
if (state.opts.asyncGenerators === false) return;
} else {
// Plain generator
if (state.opts.generators === false) return;
}
} else if (node.async) {
// Async function
if (state.opts.async === false) return;
} else {
// Not a generator or async function.
return;
} // if this is an ObjectMethod, we need to convert it to an ObjectProperty
path = (0, _replaceShorthandObjectMethod.default)(path);
node = path.node;
var contextId = path.scope.generateUidIdentifier("context");
var argsId = path.scope.generateUidIdentifier("args");
path.ensureBlock();
var bodyBlockPath = path.get("body");
if (node.generator) {
if (node.async) {
// Async generator
if (state.opts.asyncGenerators === false) return;
} else {
// Plain generator
if (state.opts.generators === false) return;
bodyBlockPath.traverse(awaitVisitor);
}
} else if (node.async) {
// Async function
if (state.opts.async === false) return;
} else {
// Not a generator or async function.
return;
}
// if this is an ObjectMethod, we need to convert it to an ObjectProperty
path = (0, _replaceShorthandObjectMethod2.default)(path);
node = path.node;
bodyBlockPath.traverse(functionSentVisitor, {
context: contextId
});
var outerBody = [];
var innerBody = [];
bodyBlockPath.get("body").forEach(function (childPath) {
var node = childPath.node;
var contextId = path.scope.generateUidIdentifier("context");
var argsId = path.scope.generateUidIdentifier("args");
if (t.isExpressionStatement(node) && t.isStringLiteral(node.expression)) {
// Babylon represents directives like "use strict" as elements
// of a bodyBlockPath.node.directives array, but they could just
// as easily be represented (by other parsers) as traditional
// string-literal-valued expression statements, so we need to
// handle that here. (#248)
outerBody.push(node);
} else if (node && node._blockHoist != null) {
outerBody.push(node);
} else {
innerBody.push(node);
}
});
path.ensureBlock();
var bodyBlockPath = path.get("body");
if (node.async) {
bodyBlockPath.traverse(awaitVisitor);
}
bodyBlockPath.traverse(functionSentVisitor, {
context: contextId
});
var outerBody = [];
var innerBody = [];
bodyBlockPath.get("body").forEach(function (childPath) {
var node = childPath.node;
if (t.isExpressionStatement(node) && t.isStringLiteral(node.expression)) {
// Babylon represents directives like "use strict" as elements
// of a bodyBlockPath.node.directives array, but they could just
// as easily be represented (by other parsers) as traditional
// string-literal-valued expression statements, so we need to
// handle that here. (#248)
outerBody.push(node);
} else if (node && node._blockHoist != null) {
outerBody.push(node);
} else {
innerBody.push(node);
if (outerBody.length > 0) {
// Only replace the inner body if we actually hoisted any statements
// to the outer body.
bodyBlockPath.node.body = innerBody;
}
});
if (outerBody.length > 0) {
// Only replace the inner body if we actually hoisted any statements
// to the outer body.
bodyBlockPath.node.body = innerBody;
}
var outerFnExpr = getOuterFnExpr(path); // Note that getOuterFnExpr has the side-effect of ensuring that the
// function has a name (so node.id will always be an Identifier), even
// if a temporary name has to be synthesized.
var outerFnExpr = getOuterFnExpr(path);
// Note that getOuterFnExpr has the side-effect of ensuring that the
// function has a name (so node.id will always be an Identifier), even
// if a temporary name has to be synthesized.
t.assertIdentifier(node.id);
var innerFnId = t.identifier(node.id.name + "$");
t.assertIdentifier(node.id);
var innerFnId = t.identifier(node.id.name + "$"); // Turn all declarations into vars, and replace the original
// declarations with equivalent assignment expressions.
// Turn all declarations into vars, and replace the original
// declarations with equivalent assignment expressions.
var vars = (0, _hoist.hoist)(path);
var vars = (0, _hoist.hoist)(path);
var context = {
usesThis: false,
usesArguments: false,
getArgsId: function getArgsId() {
return t.clone(argsId);
}
};
path.traverse(argumentsThisVisitor, context);
var didRenameArguments = renameArguments(path, argsId);
if (didRenameArguments) {
vars = vars || t.variableDeclaration("var", []);
var 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));
}
if (context.usesArguments) {
vars = vars || t.variableDeclaration("var", []);
var argumentIdentifier = t.identifier("arguments"); // we need to do this as otherwise arguments in arrow functions gets hoisted
var emitter = new _emit.Emitter(contextId);
emitter.explode(path.get("body"));
argumentIdentifier._shadowedFunctionLiteral = path;
vars.declarations.push(t.variableDeclarator(t.clone(argsId), argumentIdentifier));
}
if (vars && vars.declarations.length > 0) {
outerBody.push(vars);
}
var emitter = new _emit.Emitter(contextId);
emitter.explode(path.get("body"));
var wrapArgs = [emitter.getContextFunction(innerFnId),
// 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()];
if (vars && vars.declarations.length > 0) {
outerBody.push(vars);
}
var tryLocsList = emitter.getTryLocsList();
if (tryLocsList) {
wrapArgs.push(tryLocsList);
}
var wrapArgs = [emitter.getContextFunction(innerFnId)];
var tryLocsList = emitter.getTryLocsList();
var wrapCall = t.callExpression(util.runtimeProperty(node.async ? "async" : "wrap"), wrapArgs);
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.
wrapArgs.push(t.nullLiteral());
}
outerBody.push(t.returnStatement(wrapCall));
node.body = t.blockStatement(outerBody);
if (context.usesThis) {
wrapArgs.push(t.thisExpression());
} else if (tryLocsList) {
wrapArgs.push(t.nullLiteral());
}
var oldDirectives = bodyBlockPath.node.directives;
if (oldDirectives) {
// Babylon represents directives like "use strict" as elements of
// a bodyBlockPath.node.directives array. (#248)
node.body.directives = oldDirectives;
}
if (tryLocsList) {
wrapArgs.push(tryLocsList);
}
var wasGeneratorFunction = node.generator;
if (wasGeneratorFunction) {
node.generator = false;
}
var wrapCall = t.callExpression(util.runtimeProperty(node.async ? "async" : "wrap"), wrapArgs);
outerBody.push(t.returnStatement(wrapCall));
node.body = t.blockStatement(outerBody);
var oldDirectives = bodyBlockPath.node.directives;
if (node.async) {
node.async = false;
}
if (oldDirectives) {
// Babylon represents directives like "use strict" as elements of
// a bodyBlockPath.node.directives array. (#248)
node.body.directives = oldDirectives;
}
if (wasGeneratorFunction && t.isExpression(node)) {
util.replaceWithOrRemove(path, t.callExpression(util.runtimeProperty("mark"), [node]));
path.addComment("leading", "#__PURE__");
}
var wasGeneratorFunction = node.generator;
// 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();
if (wasGeneratorFunction) {
node.generator = false;
}
if (node.async) {
node.async = false;
}
if (wasGeneratorFunction && t.isExpression(node)) {
util.replaceWithOrRemove(path, t.callExpression(util.runtimeProperty("mark"), [node]));
path.addComment("leading", "#__PURE__");
}
var insertedLocs = emitter.getInsertedLocs();
path.traverse({
NumericLiteral: function 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
};
}; // 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) {
var t = util.getTypes();
var node = funPath.node;
t.assertFunction(node);
@@ -190,15 +206,15 @@ function getOuterFnExpr(funPath) {
return getMarkedFunctionId(funPath);
}
return node.id;
return t.clone(node.id);
}
var getMarkInfo = require("private").makeAccessor();
var getMarkInfo = (0, _private.makeAccessor)();
function getMarkedFunctionId(funPath) {
var t = util.getTypes();
var node = funPath.node;
t.assertIdentifier(node.id);
var blockPath = funPath.findParent(function (path) {
return path.isProgram() || path.isBlockStatement();
});
@@ -208,83 +224,66 @@ function getMarkedFunctionId(funPath) {
}
var block = blockPath.node;
_assert2.default.ok(Array.isArray(block.body));
_assert.default.ok(Array.isArray(block.body));
var info = getMarkInfo(block);
if (!info.decl) {
info.decl = t.variableDeclaration("var", []);
blockPath.unshiftContainer("body", info.decl);
info.declPath = blockPath.get("body.0");
}
_assert2.default.strictEqual(info.declPath.node, info.decl);
_assert.default.strictEqual(info.declPath.node, info.decl); // Get a new unique identifier for our marked variable.
// Get a new unique identifier for our marked variable.
var markedId = blockPath.scope.generateUidIdentifier("marked");
var markCallExp = t.callExpression(util.runtimeProperty("mark"), [node.id]);
var markCallExp = t.callExpression(util.runtimeProperty("mark"), [t.clone(node.id)]);
var index = info.decl.declarations.push(t.variableDeclarator(markedId, markCallExp)) - 1;
var markCallExpPath = info.declPath.get("declarations." + index + ".init");
_assert2.default.strictEqual(markCallExpPath.node, markCallExp);
_assert.default.strictEqual(markCallExpPath.node, markCallExp);
markCallExpPath.addComment("leading", "#__PURE__");
return markedId;
return t.clone(markedId);
}
function renameArguments(funcPath, argsId) {
var 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;
}
var argumentsVisitor = {
var argumentsThisVisitor = {
"FunctionExpression|FunctionDeclaration": function FunctionExpressionFunctionDeclaration(path) {
path.skip();
},
Identifier: function Identifier(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 ThisExpression(path, state) {
state.usesThis = true;
}
};
var functionSentVisitor = {
MetaProperty: function MetaProperty(path) {
var node = path.node;
if (node.meta.name === "function" && node.property.name === "sent") {
util.replaceWithOrRemove(path, t.memberExpression(this.context, t.identifier("_sent")));
var t = util.getTypes();
util.replaceWithOrRemove(path, t.memberExpression(t.clone(this.context), t.identifier("_sent")));
}
}
};
var awaitVisitor = {
Function: function Function(path) {
path.skip(); // Don't descend into nested function scopes.
},
AwaitExpression: function AwaitExpression(path) {
// Convert await expressions to yield expressions.
var argument = path.node.argument;
var t = util.getTypes(); // Convert await expressions to yield expressions.
// Transforming `await x` to `yield regeneratorRuntime.awrap(x)`
var argument = path.node.argument; // Transforming `await x` to `yield regeneratorRuntime.awrap(x)`
// causes the argument to be wrapped in such a way that the runtime
// can distinguish between awaited and merely yielded values.
util.replaceWithOrRemove(path, t.yieldExpression(t.callExpression(util.runtimeProperty("awrap"), [argument]), false));
}
};