nav tabs on admin dashboard
This commit is contained in:
-1
@@ -1 +0,0 @@
|
||||
/node_modules
|
||||
+1
-1
@@ -40,7 +40,7 @@ $ babel --plugins regenerator-transform script.js
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
require("@babel/core").transformSync("code", {
|
||||
plugins: ["regenerator-transform"]
|
||||
});
|
||||
```
|
||||
|
||||
+223
-271
File diff suppressed because it is too large
Load Diff
+29
-52
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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));
|
||||
}
|
||||
};
|
||||
+17
-22
@@ -1,27 +1,27 @@
|
||||
{
|
||||
"_from": "regenerator-transform@^0.10.0",
|
||||
"_id": "regenerator-transform@0.10.1",
|
||||
"_from": "regenerator-transform@^0.13.4",
|
||||
"_id": "regenerator-transform@0.13.4",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-PJepbvDbuK1xgIgnau7Y90cwaAmO/LCLMI2mPvaXq2heGMR3aWW5/BQvYrhJ8jgmQjXewXvBjzfqKcVOmhjZ6Q==",
|
||||
"_integrity": "sha512-T0QMBjK3J0MtxjPmdIMXm72Wvj2Abb0Bd4HADdfijwMdoIsyQZ6fWC7kDFhk2YinBBEMZDL7Y7wh0J1sGx3S4A==",
|
||||
"_location": "/regenerator-transform",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "regenerator-transform@^0.10.0",
|
||||
"raw": "regenerator-transform@^0.13.4",
|
||||
"name": "regenerator-transform",
|
||||
"escapedName": "regenerator-transform",
|
||||
"rawSpec": "^0.10.0",
|
||||
"rawSpec": "^0.13.4",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.10.0"
|
||||
"fetchSpec": "^0.13.4"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/babel-plugin-transform-regenerator"
|
||||
"/@babel/plugin-transform-regenerator"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.10.1.tgz",
|
||||
"_shasum": "1e4996837231da8b7f3cf4114d71b5691a0680dd",
|
||||
"_spec": "regenerator-transform@^0.10.0",
|
||||
"_where": "C:\\xampp\\htdocs\\w4rpservices\\node_modules\\babel-plugin-transform-regenerator",
|
||||
"_resolved": "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.13.4.tgz",
|
||||
"_shasum": "18f6763cf1382c69c36df76c6ce122cc694284fb",
|
||||
"_spec": "regenerator-transform@^0.13.4",
|
||||
"_where": "C:\\xampp\\htdocs\\w4rpservices\\node_modules\\@babel\\plugin-transform-regenerator",
|
||||
"author": {
|
||||
"name": "Ben Newman",
|
||||
"email": "bn@cs.stanford.edu"
|
||||
@@ -29,28 +29,23 @@
|
||||
"babel": {
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"loose": true
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": [
|
||||
"transform-runtime"
|
||||
]
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.18.0",
|
||||
"babel-types": "^6.19.0",
|
||||
"private": "^0.1.6"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Explode async and generator functions into a state machine.",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.9.0",
|
||||
"babel-plugin-transform-runtime": "^6.9.0",
|
||||
"babel-preset-env": "^1.2.2"
|
||||
"@babel/cli": "^7.1.5",
|
||||
"@babel/core": "^7.1.6",
|
||||
"@babel/preset-env": "^7.1.6"
|
||||
},
|
||||
"keywords": [
|
||||
"regenerator",
|
||||
@@ -58,7 +53,7 @@
|
||||
"generator",
|
||||
"async"
|
||||
],
|
||||
"license": "BSD",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"name": "regenerator-transform",
|
||||
"repository": {
|
||||
@@ -68,5 +63,5 @@
|
||||
"scripts": {
|
||||
"prepublish": "babel src/ --out-dir lib/"
|
||||
},
|
||||
"version": "0.10.1"
|
||||
"version": "0.13.4"
|
||||
}
|
||||
|
||||
+132
-62
@@ -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");
|
||||
|
||||
+11
-9
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+6
-7
@@ -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
|
||||
|
||||
+15
-10
@@ -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;
|
||||
|
||||
+9
-9
@@ -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))
|
||||
|
||||
+9
-1
@@ -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.");
|
||||
}
|
||||
|
||||
+21
-7
@@ -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),
|
||||
|
||||
+67
-45
@@ -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