mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-04 04:40:05 +02:00
add some babel stuff
This commit is contained in:
202
node_modules/@babel/traverse/lib/path/ancestry.js
generated
vendored
Normal file
202
node_modules/@babel/traverse/lib/path/ancestry.js
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.findParent = findParent;
|
||||
exports.find = find;
|
||||
exports.getFunctionParent = getFunctionParent;
|
||||
exports.getStatementParent = getStatementParent;
|
||||
exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
|
||||
exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
|
||||
exports.getAncestry = getAncestry;
|
||||
exports.isAncestor = isAncestor;
|
||||
exports.isDescendant = isDescendant;
|
||||
exports.inType = inType;
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _index = _interopRequireDefault(require("./index"));
|
||||
|
||||
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; } }
|
||||
|
||||
function findParent(callback) {
|
||||
var path = this;
|
||||
|
||||
while (path = path.parentPath) {
|
||||
if (callback(path)) return path;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function find(callback) {
|
||||
var path = this;
|
||||
|
||||
do {
|
||||
if (callback(path)) return path;
|
||||
} while (path = path.parentPath);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getFunctionParent() {
|
||||
return this.findParent(function (p) {
|
||||
return p.isFunction();
|
||||
});
|
||||
}
|
||||
|
||||
function getStatementParent() {
|
||||
var path = this;
|
||||
|
||||
do {
|
||||
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
||||
break;
|
||||
} else {
|
||||
path = path.parentPath;
|
||||
}
|
||||
} while (path);
|
||||
|
||||
if (path && (path.isProgram() || path.isFile())) {
|
||||
throw new Error("File/Program node, we can't possibly find a statement parent to this");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
function getEarliestCommonAncestorFrom(paths) {
|
||||
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
|
||||
var earliest;
|
||||
var keys = t().VISITOR_KEYS[deepest.type];
|
||||
var _arr = ancestries;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var ancestry = _arr[_i];
|
||||
var path = ancestry[i + 1];
|
||||
|
||||
if (!earliest) {
|
||||
earliest = path;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (path.listKey && earliest.listKey === path.listKey) {
|
||||
if (path.key < earliest.key) {
|
||||
earliest = path;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var earliestKeyIndex = keys.indexOf(earliest.parentKey);
|
||||
var currentKeyIndex = keys.indexOf(path.parentKey);
|
||||
|
||||
if (earliestKeyIndex > currentKeyIndex) {
|
||||
earliest = path;
|
||||
}
|
||||
}
|
||||
|
||||
return earliest;
|
||||
});
|
||||
}
|
||||
|
||||
function getDeepestCommonAncestorFrom(paths, filter) {
|
||||
var _this = this;
|
||||
|
||||
if (!paths.length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (paths.length === 1) {
|
||||
return paths[0];
|
||||
}
|
||||
|
||||
var minDepth = Infinity;
|
||||
var lastCommonIndex, lastCommon;
|
||||
var ancestries = paths.map(function (path) {
|
||||
var ancestry = [];
|
||||
|
||||
do {
|
||||
ancestry.unshift(path);
|
||||
} while ((path = path.parentPath) && path !== _this);
|
||||
|
||||
if (ancestry.length < minDepth) {
|
||||
minDepth = ancestry.length;
|
||||
}
|
||||
|
||||
return ancestry;
|
||||
});
|
||||
var first = ancestries[0];
|
||||
|
||||
depthLoop: for (var i = 0; i < minDepth; i++) {
|
||||
var shouldMatch = first[i];
|
||||
var _arr2 = ancestries;
|
||||
|
||||
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
|
||||
var ancestry = _arr2[_i2];
|
||||
|
||||
if (ancestry[i] !== shouldMatch) {
|
||||
break depthLoop;
|
||||
}
|
||||
}
|
||||
|
||||
lastCommonIndex = i;
|
||||
lastCommon = shouldMatch;
|
||||
}
|
||||
|
||||
if (lastCommon) {
|
||||
if (filter) {
|
||||
return filter(lastCommon, lastCommonIndex, ancestries);
|
||||
} else {
|
||||
return lastCommon;
|
||||
}
|
||||
} else {
|
||||
throw new Error("Couldn't find intersection");
|
||||
}
|
||||
}
|
||||
|
||||
function getAncestry() {
|
||||
var path = this;
|
||||
var paths = [];
|
||||
|
||||
do {
|
||||
paths.push(path);
|
||||
} while (path = path.parentPath);
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function isAncestor(maybeDescendant) {
|
||||
return maybeDescendant.isDescendant(this);
|
||||
}
|
||||
|
||||
function isDescendant(maybeAncestor) {
|
||||
return !!this.findParent(function (parent) {
|
||||
return parent === maybeAncestor;
|
||||
});
|
||||
}
|
||||
|
||||
function inType() {
|
||||
var path = this;
|
||||
|
||||
while (path) {
|
||||
var _arr3 = arguments;
|
||||
|
||||
for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
|
||||
var type = _arr3[_i3];
|
||||
if (path.node.type === type) return true;
|
||||
}
|
||||
|
||||
path = path.parentPath;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
47
node_modules/@babel/traverse/lib/path/comments.js
generated
vendored
Normal file
47
node_modules/@babel/traverse/lib/path/comments.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
|
||||
exports.addComment = addComment;
|
||||
exports.addComments = addComments;
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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 shareCommentsWithSiblings() {
|
||||
if (typeof this.key === "string") return;
|
||||
var node = this.node;
|
||||
if (!node) return;
|
||||
var trailing = node.trailingComments;
|
||||
var leading = node.leadingComments;
|
||||
if (!trailing && !leading) return;
|
||||
var prev = this.getSibling(this.key - 1);
|
||||
var next = this.getSibling(this.key + 1);
|
||||
var hasPrev = Boolean(prev.node);
|
||||
var hasNext = Boolean(next.node);
|
||||
|
||||
if (hasPrev && hasNext) {} else if (hasPrev) {
|
||||
prev.addComments("trailing", trailing);
|
||||
} else if (hasNext) {
|
||||
next.addComments("leading", leading);
|
||||
}
|
||||
}
|
||||
|
||||
function addComment(type, content, line) {
|
||||
t().addComment(this.node, type, content, line);
|
||||
}
|
||||
|
||||
function addComments(type, comments) {
|
||||
t().addComments(this.node, type, comments);
|
||||
}
|
273
node_modules/@babel/traverse/lib/path/context.js
generated
vendored
Normal file
273
node_modules/@babel/traverse/lib/path/context.js
generated
vendored
Normal file
@@ -0,0 +1,273 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.call = call;
|
||||
exports._call = _call;
|
||||
exports.isBlacklisted = isBlacklisted;
|
||||
exports.visit = visit;
|
||||
exports.skip = skip;
|
||||
exports.skipKey = skipKey;
|
||||
exports.stop = stop;
|
||||
exports.setScope = setScope;
|
||||
exports.setContext = setContext;
|
||||
exports.resync = resync;
|
||||
exports._resyncParent = _resyncParent;
|
||||
exports._resyncKey = _resyncKey;
|
||||
exports._resyncList = _resyncList;
|
||||
exports._resyncRemoved = _resyncRemoved;
|
||||
exports.popContext = popContext;
|
||||
exports.pushContext = pushContext;
|
||||
exports.setup = setup;
|
||||
exports.setKey = setKey;
|
||||
exports.requeue = requeue;
|
||||
exports._getQueueContexts = _getQueueContexts;
|
||||
|
||||
var _index = _interopRequireDefault(require("../index"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function call(key) {
|
||||
var opts = this.opts;
|
||||
this.debug(key);
|
||||
|
||||
if (this.node) {
|
||||
if (this._call(opts[key])) return true;
|
||||
}
|
||||
|
||||
if (this.node) {
|
||||
return this._call(opts[this.node.type] && opts[this.node.type][key]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function _call(fns) {
|
||||
if (!fns) return false;
|
||||
|
||||
for (var _iterator = fns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var fn = _ref;
|
||||
if (!fn) continue;
|
||||
var node = this.node;
|
||||
if (!node) return true;
|
||||
var ret = fn.call(this.state, this, this.state);
|
||||
|
||||
if (ret && typeof ret === "object" && typeof ret.then === "function") {
|
||||
throw new Error("You appear to be using a plugin with an async traversal visitor, " + "which your current version of Babel does not support." + "If you're using a published plugin, you may need to upgrade " + "your @babel/core version.");
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
throw new Error("Unexpected return value from visitor method " + fn);
|
||||
}
|
||||
|
||||
if (this.node !== node) return true;
|
||||
if (this.shouldStop || this.shouldSkip || this.removed) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isBlacklisted() {
|
||||
var blacklist = this.opts.blacklist;
|
||||
return blacklist && blacklist.indexOf(this.node.type) > -1;
|
||||
}
|
||||
|
||||
function visit() {
|
||||
if (!this.node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isBlacklisted()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.opts.shouldSkip && this.opts.shouldSkip(this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.call("enter") || this.shouldSkip) {
|
||||
this.debug("Skip...");
|
||||
return this.shouldStop;
|
||||
}
|
||||
|
||||
this.debug("Recursing into...");
|
||||
|
||||
_index.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
|
||||
|
||||
this.call("exit");
|
||||
return this.shouldStop;
|
||||
}
|
||||
|
||||
function skip() {
|
||||
this.shouldSkip = true;
|
||||
}
|
||||
|
||||
function skipKey(key) {
|
||||
this.skipKeys[key] = true;
|
||||
}
|
||||
|
||||
function stop() {
|
||||
this.shouldStop = true;
|
||||
this.shouldSkip = true;
|
||||
}
|
||||
|
||||
function setScope() {
|
||||
if (this.opts && this.opts.noScope) return;
|
||||
var path = this.parentPath;
|
||||
var target;
|
||||
|
||||
while (path && !target) {
|
||||
if (path.opts && path.opts.noScope) return;
|
||||
target = path.scope;
|
||||
path = path.parentPath;
|
||||
}
|
||||
|
||||
this.scope = this.getScope(target);
|
||||
if (this.scope) this.scope.init();
|
||||
}
|
||||
|
||||
function setContext(context) {
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
this.removed = false;
|
||||
this.skipKeys = {};
|
||||
|
||||
if (context) {
|
||||
this.context = context;
|
||||
this.state = context.state;
|
||||
this.opts = context.opts;
|
||||
}
|
||||
|
||||
this.setScope();
|
||||
return this;
|
||||
}
|
||||
|
||||
function resync() {
|
||||
if (this.removed) return;
|
||||
|
||||
this._resyncParent();
|
||||
|
||||
this._resyncList();
|
||||
|
||||
this._resyncKey();
|
||||
}
|
||||
|
||||
function _resyncParent() {
|
||||
if (this.parentPath) {
|
||||
this.parent = this.parentPath.node;
|
||||
}
|
||||
}
|
||||
|
||||
function _resyncKey() {
|
||||
if (!this.container) return;
|
||||
if (this.node === this.container[this.key]) return;
|
||||
|
||||
if (Array.isArray(this.container)) {
|
||||
for (var i = 0; i < this.container.length; i++) {
|
||||
if (this.container[i] === this.node) {
|
||||
return this.setKey(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var key in this.container) {
|
||||
if (this.container[key] === this.node) {
|
||||
return this.setKey(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.key = null;
|
||||
}
|
||||
|
||||
function _resyncList() {
|
||||
if (!this.parent || !this.inList) return;
|
||||
var newContainer = this.parent[this.listKey];
|
||||
if (this.container === newContainer) return;
|
||||
this.container = newContainer || null;
|
||||
}
|
||||
|
||||
function _resyncRemoved() {
|
||||
if (this.key == null || !this.container || this.container[this.key] !== this.node) {
|
||||
this._markRemoved();
|
||||
}
|
||||
}
|
||||
|
||||
function popContext() {
|
||||
this.contexts.pop();
|
||||
|
||||
if (this.contexts.length > 0) {
|
||||
this.setContext(this.contexts[this.contexts.length - 1]);
|
||||
} else {
|
||||
this.setContext(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
function pushContext(context) {
|
||||
this.contexts.push(context);
|
||||
this.setContext(context);
|
||||
}
|
||||
|
||||
function setup(parentPath, container, listKey, key) {
|
||||
this.inList = !!listKey;
|
||||
this.listKey = listKey;
|
||||
this.parentKey = listKey || key;
|
||||
this.container = container;
|
||||
this.parentPath = parentPath || this.parentPath;
|
||||
this.setKey(key);
|
||||
}
|
||||
|
||||
function setKey(key) {
|
||||
this.key = key;
|
||||
this.node = this.container[this.key];
|
||||
this.type = this.node && this.node.type;
|
||||
}
|
||||
|
||||
function requeue(pathToQueue) {
|
||||
if (pathToQueue === void 0) {
|
||||
pathToQueue = this;
|
||||
}
|
||||
|
||||
if (pathToQueue.removed) return;
|
||||
var contexts = this.contexts;
|
||||
|
||||
for (var _iterator2 = contexts, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var context = _ref2;
|
||||
context.maybeQueue(pathToQueue);
|
||||
}
|
||||
}
|
||||
|
||||
function _getQueueContexts() {
|
||||
var path = this;
|
||||
var contexts = this.contexts;
|
||||
|
||||
while (!contexts.length) {
|
||||
path = path.parentPath;
|
||||
if (!path) break;
|
||||
contexts = path.contexts;
|
||||
}
|
||||
|
||||
return contexts;
|
||||
}
|
472
node_modules/@babel/traverse/lib/path/conversion.js
generated
vendored
Normal file
472
node_modules/@babel/traverse/lib/path/conversion.js
generated
vendored
Normal file
@@ -0,0 +1,472 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.toComputedKey = toComputedKey;
|
||||
exports.ensureBlock = ensureBlock;
|
||||
exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
|
||||
exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
|
||||
exports.arrowFunctionToExpression = arrowFunctionToExpression;
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _helperFunctionName() {
|
||||
var data = _interopRequireDefault(require("@babel/helper-function-name"));
|
||||
|
||||
_helperFunctionName = function _helperFunctionName() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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; } }
|
||||
|
||||
function toComputedKey() {
|
||||
var node = this.node;
|
||||
var key;
|
||||
|
||||
if (this.isMemberExpression()) {
|
||||
key = node.property;
|
||||
} else if (this.isProperty() || this.isMethod()) {
|
||||
key = node.key;
|
||||
} else {
|
||||
throw new ReferenceError("todo");
|
||||
}
|
||||
|
||||
if (!node.computed) {
|
||||
if (t().isIdentifier(key)) key = t().stringLiteral(key.name);
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
function ensureBlock() {
|
||||
var body = this.get("body");
|
||||
var bodyNode = body.node;
|
||||
|
||||
if (Array.isArray(body)) {
|
||||
throw new Error("Can't convert array path to a block statement");
|
||||
}
|
||||
|
||||
if (!bodyNode) {
|
||||
throw new Error("Can't convert node without a body");
|
||||
}
|
||||
|
||||
if (body.isBlockStatement()) {
|
||||
return bodyNode;
|
||||
}
|
||||
|
||||
var statements = [];
|
||||
var stringPath = "body";
|
||||
var key;
|
||||
var listKey;
|
||||
|
||||
if (body.isStatement()) {
|
||||
listKey = "body";
|
||||
key = 0;
|
||||
statements.push(body.node);
|
||||
} else {
|
||||
stringPath += ".body.0";
|
||||
|
||||
if (this.isFunction()) {
|
||||
key = "argument";
|
||||
statements.push(t().returnStatement(body.node));
|
||||
} else {
|
||||
key = "expression";
|
||||
statements.push(t().expressionStatement(body.node));
|
||||
}
|
||||
}
|
||||
|
||||
this.node.body = t().blockStatement(statements);
|
||||
var parentPath = this.get(stringPath);
|
||||
body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
|
||||
return this.node;
|
||||
}
|
||||
|
||||
function arrowFunctionToShadowed() {
|
||||
if (!this.isArrowFunctionExpression()) return;
|
||||
this.arrowFunctionToExpression();
|
||||
}
|
||||
|
||||
function unwrapFunctionEnvironment() {
|
||||
if (!this.isArrowFunctionExpression() && !this.isFunctionExpression() && !this.isFunctionDeclaration()) {
|
||||
throw this.buildCodeFrameError("Can only unwrap the environment of a function.");
|
||||
}
|
||||
|
||||
hoistFunctionEnvironment(this);
|
||||
}
|
||||
|
||||
function arrowFunctionToExpression(_temp) {
|
||||
var _ref = _temp === void 0 ? {} : _temp,
|
||||
_ref$allowInsertArrow = _ref.allowInsertArrow,
|
||||
allowInsertArrow = _ref$allowInsertArrow === void 0 ? true : _ref$allowInsertArrow,
|
||||
_ref$specCompliant = _ref.specCompliant,
|
||||
specCompliant = _ref$specCompliant === void 0 ? false : _ref$specCompliant;
|
||||
|
||||
if (!this.isArrowFunctionExpression()) {
|
||||
throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
|
||||
}
|
||||
|
||||
var thisBinding = hoistFunctionEnvironment(this, specCompliant, allowInsertArrow);
|
||||
this.ensureBlock();
|
||||
this.node.type = "FunctionExpression";
|
||||
|
||||
if (specCompliant) {
|
||||
var checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId");
|
||||
|
||||
if (checkBinding) {
|
||||
this.parentPath.scope.push({
|
||||
id: checkBinding,
|
||||
init: t().objectExpression([])
|
||||
});
|
||||
}
|
||||
|
||||
this.get("body").unshiftContainer("body", t().expressionStatement(t().callExpression(this.hub.file.addHelper("newArrowCheck"), [t().thisExpression(), checkBinding ? t().identifier(checkBinding.name) : t().identifier(thisBinding)])));
|
||||
this.replaceWith(t().callExpression(t().memberExpression((0, _helperFunctionName().default)(this, true) || this.node, t().identifier("bind")), [checkBinding ? t().identifier(checkBinding.name) : t().thisExpression()]));
|
||||
}
|
||||
}
|
||||
|
||||
function hoistFunctionEnvironment(fnPath, specCompliant, allowInsertArrow) {
|
||||
if (specCompliant === void 0) {
|
||||
specCompliant = false;
|
||||
}
|
||||
|
||||
if (allowInsertArrow === void 0) {
|
||||
allowInsertArrow = true;
|
||||
}
|
||||
|
||||
var thisEnvFn = fnPath.findParent(function (p) {
|
||||
return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
|
||||
static: false
|
||||
});
|
||||
});
|
||||
var inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor";
|
||||
|
||||
if (thisEnvFn.isClassProperty()) {
|
||||
throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
|
||||
}
|
||||
|
||||
var _getScopeInformation = getScopeInformation(fnPath),
|
||||
thisPaths = _getScopeInformation.thisPaths,
|
||||
argumentsPaths = _getScopeInformation.argumentsPaths,
|
||||
newTargetPaths = _getScopeInformation.newTargetPaths,
|
||||
superProps = _getScopeInformation.superProps,
|
||||
superCalls = _getScopeInformation.superCalls;
|
||||
|
||||
if (inConstructor && superCalls.length > 0) {
|
||||
if (!allowInsertArrow) {
|
||||
throw superCalls[0].buildCodeFrameError("Unable to handle nested super() usage in arrow");
|
||||
}
|
||||
|
||||
var allSuperCalls = [];
|
||||
thisEnvFn.traverse({
|
||||
Function: function Function(child) {
|
||||
if (child.isArrowFunctionExpression()) return;
|
||||
child.skip();
|
||||
},
|
||||
ClassProperty: function ClassProperty(child) {
|
||||
if (child.node.static) return;
|
||||
child.skip();
|
||||
},
|
||||
CallExpression: function CallExpression(child) {
|
||||
if (!child.get("callee").isSuper()) return;
|
||||
allSuperCalls.push(child);
|
||||
}
|
||||
});
|
||||
var superBinding = getSuperBinding(thisEnvFn);
|
||||
allSuperCalls.forEach(function (superCall) {
|
||||
var callee = t().identifier(superBinding);
|
||||
callee.loc = superCall.node.callee.loc;
|
||||
superCall.get("callee").replaceWith(callee);
|
||||
});
|
||||
}
|
||||
|
||||
var thisBinding;
|
||||
|
||||
if (thisPaths.length > 0 || specCompliant) {
|
||||
thisBinding = getThisBinding(thisEnvFn, inConstructor);
|
||||
|
||||
if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) {
|
||||
thisPaths.forEach(function (thisChild) {
|
||||
var thisRef = thisChild.isJSX() ? t().jsxIdentifier(thisBinding) : t().identifier(thisBinding);
|
||||
thisRef.loc = thisChild.node.loc;
|
||||
thisChild.replaceWith(thisRef);
|
||||
});
|
||||
if (specCompliant) thisBinding = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (argumentsPaths.length > 0) {
|
||||
var argumentsBinding = getBinding(thisEnvFn, "arguments", function () {
|
||||
return t().identifier("arguments");
|
||||
});
|
||||
argumentsPaths.forEach(function (argumentsChild) {
|
||||
var argsRef = t().identifier(argumentsBinding);
|
||||
argsRef.loc = argumentsChild.node.loc;
|
||||
argumentsChild.replaceWith(argsRef);
|
||||
});
|
||||
}
|
||||
|
||||
if (newTargetPaths.length > 0) {
|
||||
var newTargetBinding = getBinding(thisEnvFn, "newtarget", function () {
|
||||
return t().metaProperty(t().identifier("new"), t().identifier("target"));
|
||||
});
|
||||
newTargetPaths.forEach(function (targetChild) {
|
||||
var targetRef = t().identifier(newTargetBinding);
|
||||
targetRef.loc = targetChild.node.loc;
|
||||
targetChild.replaceWith(targetRef);
|
||||
});
|
||||
}
|
||||
|
||||
if (superProps.length > 0) {
|
||||
if (!allowInsertArrow) {
|
||||
throw superProps[0].buildCodeFrameError("Unable to handle nested super.prop usage");
|
||||
}
|
||||
|
||||
var flatSuperProps = superProps.reduce(function (acc, superProp) {
|
||||
return acc.concat(standardizeSuperProperty(superProp));
|
||||
}, []);
|
||||
flatSuperProps.forEach(function (superProp) {
|
||||
var key = superProp.node.computed ? "" : superProp.get("property").node.name;
|
||||
|
||||
if (superProp.parentPath.isCallExpression({
|
||||
callee: superProp.node
|
||||
})) {
|
||||
var _superBinding = getSuperPropCallBinding(thisEnvFn, key);
|
||||
|
||||
if (superProp.node.computed) {
|
||||
var prop = superProp.get("property").node;
|
||||
superProp.replaceWith(t().identifier(_superBinding));
|
||||
superProp.parentPath.node.arguments.unshift(prop);
|
||||
} else {
|
||||
superProp.replaceWith(t().identifier(_superBinding));
|
||||
}
|
||||
} else {
|
||||
var isAssignment = superProp.parentPath.isAssignmentExpression({
|
||||
left: superProp.node
|
||||
});
|
||||
|
||||
var _superBinding2 = getSuperPropBinding(thisEnvFn, isAssignment, key);
|
||||
|
||||
var args = [];
|
||||
|
||||
if (superProp.node.computed) {
|
||||
args.push(superProp.get("property").node);
|
||||
}
|
||||
|
||||
if (isAssignment) {
|
||||
var value = superProp.parentPath.node.right;
|
||||
args.push(value);
|
||||
superProp.parentPath.replaceWith(t().callExpression(t().identifier(_superBinding2), args));
|
||||
} else {
|
||||
superProp.replaceWith(t().callExpression(t().identifier(_superBinding2), args));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return thisBinding;
|
||||
}
|
||||
|
||||
function standardizeSuperProperty(superProp) {
|
||||
if (superProp.parentPath.isAssignmentExpression() && superProp.parentPath.node.operator !== "=") {
|
||||
var assignmentPath = superProp.parentPath;
|
||||
var op = assignmentPath.node.operator.slice(0, -1);
|
||||
var value = assignmentPath.node.right;
|
||||
assignmentPath.node.operator = "=";
|
||||
|
||||
if (superProp.node.computed) {
|
||||
var tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
||||
assignmentPath.get("left").replaceWith(t().memberExpression(superProp.node.object, t().assignmentExpression("=", tmp, superProp.node.property), true));
|
||||
assignmentPath.get("right").replaceWith(t().binaryExpression(op, t().memberExpression(superProp.node.object, t().identifier(tmp.name), true), value));
|
||||
} else {
|
||||
assignmentPath.get("left").replaceWith(t().memberExpression(superProp.node.object, superProp.node.property));
|
||||
assignmentPath.get("right").replaceWith(t().binaryExpression(op, t().memberExpression(superProp.node.object, t().identifier(superProp.node.property.name)), value));
|
||||
}
|
||||
|
||||
return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
|
||||
} else if (superProp.parentPath.isUpdateExpression()) {
|
||||
var updateExpr = superProp.parentPath;
|
||||
|
||||
var _tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
||||
|
||||
var computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
|
||||
var parts = [t().assignmentExpression("=", _tmp, t().memberExpression(superProp.node.object, computedKey ? t().assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), t().assignmentExpression("=", t().memberExpression(superProp.node.object, computedKey ? t().identifier(computedKey.name) : superProp.node.property, superProp.node.computed), t().binaryExpression("+", t().identifier(_tmp.name), t().numericLiteral(1)))];
|
||||
|
||||
if (!superProp.parentPath.node.prefix) {
|
||||
parts.push(t().identifier(_tmp.name));
|
||||
}
|
||||
|
||||
updateExpr.replaceWith(t().sequenceExpression(parts));
|
||||
var left = updateExpr.get("expressions.0.right");
|
||||
var right = updateExpr.get("expressions.1.left");
|
||||
return [left, right];
|
||||
}
|
||||
|
||||
return [superProp];
|
||||
}
|
||||
|
||||
function hasSuperClass(thisEnvFn) {
|
||||
return thisEnvFn.isClassMethod() && !!thisEnvFn.parentPath.parentPath.node.superClass;
|
||||
}
|
||||
|
||||
function getThisBinding(thisEnvFn, inConstructor) {
|
||||
return getBinding(thisEnvFn, "this", function (thisBinding) {
|
||||
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t().thisExpression();
|
||||
var supers = new WeakSet();
|
||||
thisEnvFn.traverse({
|
||||
Function: function Function(child) {
|
||||
if (child.isArrowFunctionExpression()) return;
|
||||
child.skip();
|
||||
},
|
||||
ClassProperty: function ClassProperty(child) {
|
||||
if (child.node.static) return;
|
||||
child.skip();
|
||||
},
|
||||
CallExpression: function CallExpression(child) {
|
||||
if (!child.get("callee").isSuper()) return;
|
||||
if (supers.has(child.node)) return;
|
||||
supers.add(child.node);
|
||||
child.replaceWith(t().assignmentExpression("=", t().identifier(thisBinding), child.node));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getSuperBinding(thisEnvFn) {
|
||||
return getBinding(thisEnvFn, "supercall", function () {
|
||||
var argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
|
||||
return t().arrowFunctionExpression([t().restElement(argsBinding)], t().callExpression(t().super(), [t().spreadElement(t().identifier(argsBinding.name))]));
|
||||
});
|
||||
}
|
||||
|
||||
function getSuperPropCallBinding(thisEnvFn, propName) {
|
||||
return getBinding(thisEnvFn, "superprop_call:" + (propName || ""), function () {
|
||||
var argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
|
||||
var argsList = [t().restElement(argsBinding)];
|
||||
var fnBody;
|
||||
|
||||
if (propName) {
|
||||
fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(propName)), [t().spreadElement(t().identifier(argsBinding.name))]);
|
||||
} else {
|
||||
var method = thisEnvFn.scope.generateUidIdentifier("prop");
|
||||
argsList.unshift(method);
|
||||
fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(method.name), true), [t().spreadElement(t().identifier(argsBinding.name))]);
|
||||
}
|
||||
|
||||
return t().arrowFunctionExpression(argsList, fnBody);
|
||||
});
|
||||
}
|
||||
|
||||
function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
|
||||
var op = isAssignment ? "set" : "get";
|
||||
return getBinding(thisEnvFn, "superprop_" + op + ":" + (propName || ""), function () {
|
||||
var argsList = [];
|
||||
var fnBody;
|
||||
|
||||
if (propName) {
|
||||
fnBody = t().memberExpression(t().super(), t().identifier(propName));
|
||||
} else {
|
||||
var method = thisEnvFn.scope.generateUidIdentifier("prop");
|
||||
argsList.unshift(method);
|
||||
fnBody = t().memberExpression(t().super(), t().identifier(method.name), true);
|
||||
}
|
||||
|
||||
if (isAssignment) {
|
||||
var valueIdent = thisEnvFn.scope.generateUidIdentifier("value");
|
||||
argsList.push(valueIdent);
|
||||
fnBody = t().assignmentExpression("=", fnBody, t().identifier(valueIdent.name));
|
||||
}
|
||||
|
||||
return t().arrowFunctionExpression(argsList, fnBody);
|
||||
});
|
||||
}
|
||||
|
||||
function getBinding(thisEnvFn, key, init) {
|
||||
var cacheKey = "binding:" + key;
|
||||
var data = thisEnvFn.getData(cacheKey);
|
||||
|
||||
if (!data) {
|
||||
var id = thisEnvFn.scope.generateUidIdentifier(key);
|
||||
data = id.name;
|
||||
thisEnvFn.setData(cacheKey, data);
|
||||
thisEnvFn.scope.push({
|
||||
id: id,
|
||||
init: init(data)
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function getScopeInformation(fnPath) {
|
||||
var thisPaths = [];
|
||||
var argumentsPaths = [];
|
||||
var newTargetPaths = [];
|
||||
var superProps = [];
|
||||
var superCalls = [];
|
||||
fnPath.traverse({
|
||||
ClassProperty: function ClassProperty(child) {
|
||||
if (child.node.static) return;
|
||||
child.skip();
|
||||
},
|
||||
Function: function Function(child) {
|
||||
if (child.isArrowFunctionExpression()) return;
|
||||
child.skip();
|
||||
},
|
||||
ThisExpression: function ThisExpression(child) {
|
||||
thisPaths.push(child);
|
||||
},
|
||||
JSXIdentifier: function JSXIdentifier(child) {
|
||||
if (child.node.name !== "this") return;
|
||||
|
||||
if (!child.parentPath.isJSXMemberExpression({
|
||||
object: child.node
|
||||
}) && !child.parentPath.isJSXOpeningElement({
|
||||
name: child.node
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
|
||||
thisPaths.push(child);
|
||||
},
|
||||
CallExpression: function CallExpression(child) {
|
||||
if (child.get("callee").isSuper()) superCalls.push(child);
|
||||
},
|
||||
MemberExpression: function MemberExpression(child) {
|
||||
if (child.get("object").isSuper()) superProps.push(child);
|
||||
},
|
||||
ReferencedIdentifier: function ReferencedIdentifier(child) {
|
||||
if (child.node.name !== "arguments") return;
|
||||
argumentsPaths.push(child);
|
||||
},
|
||||
MetaProperty: function MetaProperty(child) {
|
||||
if (!child.get("meta").isIdentifier({
|
||||
name: "new"
|
||||
})) return;
|
||||
if (!child.get("property").isIdentifier({
|
||||
name: "target"
|
||||
})) return;
|
||||
newTargetPaths.push(child);
|
||||
}
|
||||
});
|
||||
return {
|
||||
thisPaths: thisPaths,
|
||||
argumentsPaths: argumentsPaths,
|
||||
newTargetPaths: newTargetPaths,
|
||||
superProps: superProps,
|
||||
superCalls: superCalls
|
||||
};
|
||||
}
|
451
node_modules/@babel/traverse/lib/path/evaluation.js
generated
vendored
Normal file
451
node_modules/@babel/traverse/lib/path/evaluation.js
generated
vendored
Normal file
@@ -0,0 +1,451 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.evaluateTruthy = evaluateTruthy;
|
||||
exports.evaluate = evaluate;
|
||||
var VALID_CALLEES = ["String", "Number", "Math"];
|
||||
var INVALID_METHODS = ["random"];
|
||||
|
||||
function evaluateTruthy() {
|
||||
var res = this.evaluate();
|
||||
if (res.confident) return !!res.value;
|
||||
}
|
||||
|
||||
function deopt(path, state) {
|
||||
if (!state.confident) return;
|
||||
state.deoptPath = path;
|
||||
state.confident = false;
|
||||
}
|
||||
|
||||
function evaluateCached(path, state) {
|
||||
var node = path.node;
|
||||
var seen = state.seen;
|
||||
|
||||
if (seen.has(node)) {
|
||||
var existing = seen.get(node);
|
||||
|
||||
if (existing.resolved) {
|
||||
return existing.value;
|
||||
} else {
|
||||
deopt(path, state);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
var item = {
|
||||
resolved: false
|
||||
};
|
||||
seen.set(node, item);
|
||||
|
||||
var val = _evaluate(path, state);
|
||||
|
||||
if (state.confident) {
|
||||
item.resolved = true;
|
||||
item.value = val;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
function _evaluate(path, state) {
|
||||
if (!state.confident) return;
|
||||
var node = path.node;
|
||||
|
||||
if (path.isSequenceExpression()) {
|
||||
var exprs = path.get("expressions");
|
||||
return evaluateCached(exprs[exprs.length - 1], state);
|
||||
}
|
||||
|
||||
if (path.isStringLiteral() || path.isNumericLiteral() || path.isBooleanLiteral()) {
|
||||
return node.value;
|
||||
}
|
||||
|
||||
if (path.isNullLiteral()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (path.isTemplateLiteral()) {
|
||||
return evaluateQuasis(path, node.quasis, state);
|
||||
}
|
||||
|
||||
if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) {
|
||||
var object = path.get("tag.object");
|
||||
var name = object.node.name;
|
||||
var property = path.get("tag.property");
|
||||
|
||||
if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name, true) && property.isIdentifier && property.node.name === "raw") {
|
||||
return evaluateQuasis(path, node.quasi.quasis, state, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isConditionalExpression()) {
|
||||
var testResult = evaluateCached(path.get("test"), state);
|
||||
if (!state.confident) return;
|
||||
|
||||
if (testResult) {
|
||||
return evaluateCached(path.get("consequent"), state);
|
||||
} else {
|
||||
return evaluateCached(path.get("alternate"), state);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isExpressionWrapper()) {
|
||||
return evaluateCached(path.get("expression"), state);
|
||||
}
|
||||
|
||||
if (path.isMemberExpression() && !path.parentPath.isCallExpression({
|
||||
callee: node
|
||||
})) {
|
||||
var _property = path.get("property");
|
||||
|
||||
var _object = path.get("object");
|
||||
|
||||
if (_object.isLiteral() && _property.isIdentifier()) {
|
||||
var value = _object.node.value;
|
||||
var type = typeof value;
|
||||
|
||||
if (type === "number" || type === "string") {
|
||||
return value[_property.node.name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isReferencedIdentifier()) {
|
||||
var binding = path.scope.getBinding(node.name);
|
||||
|
||||
if (binding && binding.constantViolations.length > 0) {
|
||||
return deopt(binding.path, state);
|
||||
}
|
||||
|
||||
if (binding && path.node.start < binding.path.node.end) {
|
||||
return deopt(binding.path, state);
|
||||
}
|
||||
|
||||
if (binding && binding.hasValue) {
|
||||
return binding.value;
|
||||
} else {
|
||||
if (node.name === "undefined") {
|
||||
return binding ? deopt(binding.path, state) : undefined;
|
||||
} else if (node.name === "Infinity") {
|
||||
return binding ? deopt(binding.path, state) : Infinity;
|
||||
} else if (node.name === "NaN") {
|
||||
return binding ? deopt(binding.path, state) : NaN;
|
||||
}
|
||||
|
||||
var resolved = path.resolve();
|
||||
|
||||
if (resolved === path) {
|
||||
return deopt(path, state);
|
||||
} else {
|
||||
return evaluateCached(resolved, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isUnaryExpression({
|
||||
prefix: true
|
||||
})) {
|
||||
if (node.operator === "void") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var argument = path.get("argument");
|
||||
|
||||
if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) {
|
||||
return "function";
|
||||
}
|
||||
|
||||
var arg = evaluateCached(argument, state);
|
||||
if (!state.confident) return;
|
||||
|
||||
switch (node.operator) {
|
||||
case "!":
|
||||
return !arg;
|
||||
|
||||
case "+":
|
||||
return +arg;
|
||||
|
||||
case "-":
|
||||
return -arg;
|
||||
|
||||
case "~":
|
||||
return ~arg;
|
||||
|
||||
case "typeof":
|
||||
return typeof arg;
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isArrayExpression()) {
|
||||
var arr = [];
|
||||
var elems = path.get("elements");
|
||||
|
||||
for (var _iterator = elems, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var elem = _ref;
|
||||
var elemValue = elem.evaluate();
|
||||
|
||||
if (elemValue.confident) {
|
||||
arr.push(elemValue.value);
|
||||
} else {
|
||||
return deopt(elem, state);
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
if (path.isObjectExpression()) {
|
||||
var obj = {};
|
||||
var props = path.get("properties");
|
||||
|
||||
for (var _iterator2 = props, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var prop = _ref2;
|
||||
|
||||
if (prop.isObjectMethod() || prop.isSpreadElement()) {
|
||||
return deopt(prop, state);
|
||||
}
|
||||
|
||||
var keyPath = prop.get("key");
|
||||
var key = keyPath;
|
||||
|
||||
if (prop.node.computed) {
|
||||
key = key.evaluate();
|
||||
|
||||
if (!key.confident) {
|
||||
return deopt(keyPath, state);
|
||||
}
|
||||
|
||||
key = key.value;
|
||||
} else if (key.isIdentifier()) {
|
||||
key = key.node.name;
|
||||
} else {
|
||||
key = key.node.value;
|
||||
}
|
||||
|
||||
var valuePath = prop.get("value");
|
||||
|
||||
var _value = valuePath.evaluate();
|
||||
|
||||
if (!_value.confident) {
|
||||
return deopt(valuePath, state);
|
||||
}
|
||||
|
||||
_value = _value.value;
|
||||
obj[key] = _value;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (path.isLogicalExpression()) {
|
||||
var wasConfident = state.confident;
|
||||
var left = evaluateCached(path.get("left"), state);
|
||||
var leftConfident = state.confident;
|
||||
state.confident = wasConfident;
|
||||
var right = evaluateCached(path.get("right"), state);
|
||||
var rightConfident = state.confident;
|
||||
state.confident = leftConfident && rightConfident;
|
||||
|
||||
switch (node.operator) {
|
||||
case "||":
|
||||
if (left && leftConfident) {
|
||||
state.confident = true;
|
||||
return left;
|
||||
}
|
||||
|
||||
if (!state.confident) return;
|
||||
return left || right;
|
||||
|
||||
case "&&":
|
||||
if (!left && leftConfident || !right && rightConfident) {
|
||||
state.confident = true;
|
||||
}
|
||||
|
||||
if (!state.confident) return;
|
||||
return left && right;
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isBinaryExpression()) {
|
||||
var _left = evaluateCached(path.get("left"), state);
|
||||
|
||||
if (!state.confident) return;
|
||||
|
||||
var _right = evaluateCached(path.get("right"), state);
|
||||
|
||||
if (!state.confident) return;
|
||||
|
||||
switch (node.operator) {
|
||||
case "-":
|
||||
return _left - _right;
|
||||
|
||||
case "+":
|
||||
return _left + _right;
|
||||
|
||||
case "/":
|
||||
return _left / _right;
|
||||
|
||||
case "*":
|
||||
return _left * _right;
|
||||
|
||||
case "%":
|
||||
return _left % _right;
|
||||
|
||||
case "**":
|
||||
return Math.pow(_left, _right);
|
||||
|
||||
case "<":
|
||||
return _left < _right;
|
||||
|
||||
case ">":
|
||||
return _left > _right;
|
||||
|
||||
case "<=":
|
||||
return _left <= _right;
|
||||
|
||||
case ">=":
|
||||
return _left >= _right;
|
||||
|
||||
case "==":
|
||||
return _left == _right;
|
||||
|
||||
case "!=":
|
||||
return _left != _right;
|
||||
|
||||
case "===":
|
||||
return _left === _right;
|
||||
|
||||
case "!==":
|
||||
return _left !== _right;
|
||||
|
||||
case "|":
|
||||
return _left | _right;
|
||||
|
||||
case "&":
|
||||
return _left & _right;
|
||||
|
||||
case "^":
|
||||
return _left ^ _right;
|
||||
|
||||
case "<<":
|
||||
return _left << _right;
|
||||
|
||||
case ">>":
|
||||
return _left >> _right;
|
||||
|
||||
case ">>>":
|
||||
return _left >>> _right;
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isCallExpression()) {
|
||||
var callee = path.get("callee");
|
||||
var context;
|
||||
var func;
|
||||
|
||||
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
|
||||
func = global[node.callee.name];
|
||||
}
|
||||
|
||||
if (callee.isMemberExpression()) {
|
||||
var _object2 = callee.get("object");
|
||||
|
||||
var _property2 = callee.get("property");
|
||||
|
||||
if (_object2.isIdentifier() && _property2.isIdentifier() && VALID_CALLEES.indexOf(_object2.node.name) >= 0 && INVALID_METHODS.indexOf(_property2.node.name) < 0) {
|
||||
context = global[_object2.node.name];
|
||||
func = context[_property2.node.name];
|
||||
}
|
||||
|
||||
if (_object2.isLiteral() && _property2.isIdentifier()) {
|
||||
var _type = typeof _object2.node.value;
|
||||
|
||||
if (_type === "string" || _type === "number") {
|
||||
context = _object2.node.value;
|
||||
func = context[_property2.node.name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (func) {
|
||||
var args = path.get("arguments").map(function (arg) {
|
||||
return evaluateCached(arg, state);
|
||||
});
|
||||
if (!state.confident) return;
|
||||
return func.apply(context, args);
|
||||
}
|
||||
}
|
||||
|
||||
deopt(path, state);
|
||||
}
|
||||
|
||||
function evaluateQuasis(path, quasis, state, raw) {
|
||||
if (raw === void 0) {
|
||||
raw = false;
|
||||
}
|
||||
|
||||
var str = "";
|
||||
var i = 0;
|
||||
var exprs = path.get("expressions");
|
||||
|
||||
for (var _iterator3 = quasis, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
if (_isArray3) {
|
||||
if (_i3 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i3 = _iterator3.next();
|
||||
if (_i3.done) break;
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
var elem = _ref3;
|
||||
if (!state.confident) break;
|
||||
str += raw ? elem.value.raw : elem.value.cooked;
|
||||
var expr = exprs[i++];
|
||||
if (expr) str += String(evaluateCached(expr, state));
|
||||
}
|
||||
|
||||
if (!state.confident) return;
|
||||
return str;
|
||||
}
|
||||
|
||||
function evaluate() {
|
||||
var state = {
|
||||
confident: true,
|
||||
deoptPath: null,
|
||||
seen: new Map()
|
||||
};
|
||||
var value = evaluateCached(this, state);
|
||||
if (!state.confident) value = undefined;
|
||||
return {
|
||||
confident: state.confident,
|
||||
deopt: state.deoptPath,
|
||||
value: value
|
||||
};
|
||||
}
|
254
node_modules/@babel/traverse/lib/path/family.js
generated
vendored
Normal file
254
node_modules/@babel/traverse/lib/path/family.js
generated
vendored
Normal file
@@ -0,0 +1,254 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getOpposite = getOpposite;
|
||||
exports.getCompletionRecords = getCompletionRecords;
|
||||
exports.getSibling = getSibling;
|
||||
exports.getPrevSibling = getPrevSibling;
|
||||
exports.getNextSibling = getNextSibling;
|
||||
exports.getAllNextSiblings = getAllNextSiblings;
|
||||
exports.getAllPrevSiblings = getAllPrevSiblings;
|
||||
exports.get = get;
|
||||
exports._getKey = _getKey;
|
||||
exports._getPattern = _getPattern;
|
||||
exports.getBindingIdentifiers = getBindingIdentifiers;
|
||||
exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
|
||||
exports.getBindingIdentifierPaths = getBindingIdentifierPaths;
|
||||
exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
|
||||
|
||||
var _index = _interopRequireDefault(require("./index"));
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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 }; }
|
||||
|
||||
function getOpposite() {
|
||||
if (this.key === "left") {
|
||||
return this.getSibling("right");
|
||||
} else if (this.key === "right") {
|
||||
return this.getSibling("left");
|
||||
}
|
||||
}
|
||||
|
||||
function addCompletionRecords(path, paths) {
|
||||
if (path) return paths.concat(path.getCompletionRecords());
|
||||
return paths;
|
||||
}
|
||||
|
||||
function getCompletionRecords() {
|
||||
var paths = [];
|
||||
|
||||
if (this.isIfStatement()) {
|
||||
paths = addCompletionRecords(this.get("consequent"), paths);
|
||||
paths = addCompletionRecords(this.get("alternate"), paths);
|
||||
} else if (this.isDoExpression() || this.isFor() || this.isWhile()) {
|
||||
paths = addCompletionRecords(this.get("body"), paths);
|
||||
} else if (this.isProgram() || this.isBlockStatement()) {
|
||||
paths = addCompletionRecords(this.get("body").pop(), paths);
|
||||
} else if (this.isFunction()) {
|
||||
return this.get("body").getCompletionRecords();
|
||||
} else if (this.isTryStatement()) {
|
||||
paths = addCompletionRecords(this.get("block"), paths);
|
||||
paths = addCompletionRecords(this.get("handler"), paths);
|
||||
paths = addCompletionRecords(this.get("finalizer"), paths);
|
||||
} else if (this.isCatchClause()) {
|
||||
paths = addCompletionRecords(this.get("body"), paths);
|
||||
} else {
|
||||
paths.push(this);
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function getSibling(key) {
|
||||
return _index.default.get({
|
||||
parentPath: this.parentPath,
|
||||
parent: this.parent,
|
||||
container: this.container,
|
||||
listKey: this.listKey,
|
||||
key: key
|
||||
});
|
||||
}
|
||||
|
||||
function getPrevSibling() {
|
||||
return this.getSibling(this.key - 1);
|
||||
}
|
||||
|
||||
function getNextSibling() {
|
||||
return this.getSibling(this.key + 1);
|
||||
}
|
||||
|
||||
function getAllNextSiblings() {
|
||||
var _key = this.key;
|
||||
var sibling = this.getSibling(++_key);
|
||||
var siblings = [];
|
||||
|
||||
while (sibling.node) {
|
||||
siblings.push(sibling);
|
||||
sibling = this.getSibling(++_key);
|
||||
}
|
||||
|
||||
return siblings;
|
||||
}
|
||||
|
||||
function getAllPrevSiblings() {
|
||||
var _key = this.key;
|
||||
var sibling = this.getSibling(--_key);
|
||||
var siblings = [];
|
||||
|
||||
while (sibling.node) {
|
||||
siblings.push(sibling);
|
||||
sibling = this.getSibling(--_key);
|
||||
}
|
||||
|
||||
return siblings;
|
||||
}
|
||||
|
||||
function get(key, context) {
|
||||
if (context === true) context = this.context;
|
||||
var parts = key.split(".");
|
||||
|
||||
if (parts.length === 1) {
|
||||
return this._getKey(key, context);
|
||||
} else {
|
||||
return this._getPattern(parts, context);
|
||||
}
|
||||
}
|
||||
|
||||
function _getKey(key, context) {
|
||||
var _this = this;
|
||||
|
||||
var node = this.node;
|
||||
var container = node[key];
|
||||
|
||||
if (Array.isArray(container)) {
|
||||
return container.map(function (_, i) {
|
||||
return _index.default.get({
|
||||
listKey: key,
|
||||
parentPath: _this,
|
||||
parent: node,
|
||||
container: container,
|
||||
key: i
|
||||
}).setContext(context);
|
||||
});
|
||||
} else {
|
||||
return _index.default.get({
|
||||
parentPath: this,
|
||||
parent: node,
|
||||
container: node,
|
||||
key: key
|
||||
}).setContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
function _getPattern(parts, context) {
|
||||
var path = this;
|
||||
var _arr = parts;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var part = _arr[_i];
|
||||
|
||||
if (part === ".") {
|
||||
path = path.parentPath;
|
||||
} else {
|
||||
if (Array.isArray(path)) {
|
||||
path = path[part];
|
||||
} else {
|
||||
path = path.get(part, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
function getBindingIdentifiers(duplicates) {
|
||||
return t().getBindingIdentifiers(this.node, duplicates);
|
||||
}
|
||||
|
||||
function getOuterBindingIdentifiers(duplicates) {
|
||||
return t().getOuterBindingIdentifiers(this.node, duplicates);
|
||||
}
|
||||
|
||||
function getBindingIdentifierPaths(duplicates, outerOnly) {
|
||||
if (duplicates === void 0) {
|
||||
duplicates = false;
|
||||
}
|
||||
|
||||
if (outerOnly === void 0) {
|
||||
outerOnly = false;
|
||||
}
|
||||
|
||||
var path = this;
|
||||
var search = [].concat(path);
|
||||
var ids = Object.create(null);
|
||||
|
||||
while (search.length) {
|
||||
var id = search.shift();
|
||||
if (!id) continue;
|
||||
if (!id.node) continue;
|
||||
var keys = t().getBindingIdentifiers.keys[id.node.type];
|
||||
|
||||
if (id.isIdentifier()) {
|
||||
if (duplicates) {
|
||||
var _ids = ids[id.node.name] = ids[id.node.name] || [];
|
||||
|
||||
_ids.push(id);
|
||||
} else {
|
||||
ids[id.node.name] = id;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (id.isExportDeclaration()) {
|
||||
var declaration = id.get("declaration");
|
||||
|
||||
if (declaration.isDeclaration()) {
|
||||
search.push(declaration);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (outerOnly) {
|
||||
if (id.isFunctionDeclaration()) {
|
||||
search.push(id.get("id"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (id.isFunctionExpression()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (keys) {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
var child = id.get(key);
|
||||
|
||||
if (Array.isArray(child) || child.node) {
|
||||
search = search.concat(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
function getOuterBindingIdentifierPaths(duplicates) {
|
||||
return this.getBindingIdentifierPaths(duplicates, true);
|
||||
}
|
246
node_modules/@babel/traverse/lib/path/index.js
generated
vendored
Normal file
246
node_modules/@babel/traverse/lib/path/index.js
generated
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var virtualTypes = _interopRequireWildcard(require("./lib/virtual-types"));
|
||||
|
||||
function _debug2() {
|
||||
var data = _interopRequireDefault(require("debug"));
|
||||
|
||||
_debug2 = function _debug2() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _invariant() {
|
||||
var data = _interopRequireDefault(require("invariant"));
|
||||
|
||||
_invariant = function _invariant() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _index = _interopRequireDefault(require("../index"));
|
||||
|
||||
var _scope = _interopRequireDefault(require("../scope"));
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _cache = require("../cache");
|
||||
|
||||
function _generator() {
|
||||
var data = _interopRequireDefault(require("@babel/generator"));
|
||||
|
||||
_generator = function _generator() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var NodePath_ancestry = _interopRequireWildcard(require("./ancestry"));
|
||||
|
||||
var NodePath_inference = _interopRequireWildcard(require("./inference"));
|
||||
|
||||
var NodePath_replacement = _interopRequireWildcard(require("./replacement"));
|
||||
|
||||
var NodePath_evaluation = _interopRequireWildcard(require("./evaluation"));
|
||||
|
||||
var NodePath_conversion = _interopRequireWildcard(require("./conversion"));
|
||||
|
||||
var NodePath_introspection = _interopRequireWildcard(require("./introspection"));
|
||||
|
||||
var NodePath_context = _interopRequireWildcard(require("./context"));
|
||||
|
||||
var NodePath_removal = _interopRequireWildcard(require("./removal"));
|
||||
|
||||
var NodePath_modification = _interopRequireWildcard(require("./modification"));
|
||||
|
||||
var NodePath_family = _interopRequireWildcard(require("./family"));
|
||||
|
||||
var NodePath_comments = _interopRequireWildcard(require("./comments"));
|
||||
|
||||
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; } }
|
||||
|
||||
var _debug = (0, _debug2().default)("babel");
|
||||
|
||||
var NodePath = function () {
|
||||
function NodePath(hub, parent) {
|
||||
this.parent = parent;
|
||||
this.hub = hub;
|
||||
this.contexts = [];
|
||||
this.data = {};
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
this.removed = false;
|
||||
this.state = null;
|
||||
this.opts = null;
|
||||
this.skipKeys = null;
|
||||
this.parentPath = null;
|
||||
this.context = null;
|
||||
this.container = null;
|
||||
this.listKey = null;
|
||||
this.inList = false;
|
||||
this.parentKey = null;
|
||||
this.key = null;
|
||||
this.node = null;
|
||||
this.scope = null;
|
||||
this.type = null;
|
||||
this.typeAnnotation = null;
|
||||
}
|
||||
|
||||
NodePath.get = function get(_ref) {
|
||||
var hub = _ref.hub,
|
||||
parentPath = _ref.parentPath,
|
||||
parent = _ref.parent,
|
||||
container = _ref.container,
|
||||
listKey = _ref.listKey,
|
||||
key = _ref.key;
|
||||
|
||||
if (!hub && parentPath) {
|
||||
hub = parentPath.hub;
|
||||
}
|
||||
|
||||
(0, _invariant().default)(parent, "To get a node path the parent needs to exist");
|
||||
var targetNode = container[key];
|
||||
var paths = _cache.path.get(parent) || [];
|
||||
|
||||
if (!_cache.path.has(parent)) {
|
||||
_cache.path.set(parent, paths);
|
||||
}
|
||||
|
||||
var path;
|
||||
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
var pathCheck = paths[i];
|
||||
|
||||
if (pathCheck.node === targetNode) {
|
||||
path = pathCheck;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
path = new NodePath(hub, parent);
|
||||
paths.push(path);
|
||||
}
|
||||
|
||||
path.setup(parentPath, container, listKey, key);
|
||||
return path;
|
||||
};
|
||||
|
||||
var _proto = NodePath.prototype;
|
||||
|
||||
_proto.getScope = function getScope(scope) {
|
||||
return this.isScope() ? new _scope.default(this) : scope;
|
||||
};
|
||||
|
||||
_proto.setData = function setData(key, val) {
|
||||
return this.data[key] = val;
|
||||
};
|
||||
|
||||
_proto.getData = function getData(key, def) {
|
||||
var val = this.data[key];
|
||||
if (!val && def) val = this.data[key] = def;
|
||||
return val;
|
||||
};
|
||||
|
||||
_proto.buildCodeFrameError = function buildCodeFrameError(msg, Error) {
|
||||
if (Error === void 0) {
|
||||
Error = SyntaxError;
|
||||
}
|
||||
|
||||
return this.hub.file.buildCodeFrameError(this.node, msg, Error);
|
||||
};
|
||||
|
||||
_proto.traverse = function traverse(visitor, state) {
|
||||
(0, _index.default)(this.node, visitor, this.scope, state, this);
|
||||
};
|
||||
|
||||
_proto.set = function set(key, node) {
|
||||
t().validate(this.node, key, node);
|
||||
this.node[key] = node;
|
||||
};
|
||||
|
||||
_proto.getPathLocation = function getPathLocation() {
|
||||
var parts = [];
|
||||
var path = this;
|
||||
|
||||
do {
|
||||
var key = path.key;
|
||||
if (path.inList) key = path.listKey + "[" + key + "]";
|
||||
parts.unshift(key);
|
||||
} while (path = path.parentPath);
|
||||
|
||||
return parts.join(".");
|
||||
};
|
||||
|
||||
_proto.debug = function debug(message) {
|
||||
if (!_debug.enabled) return;
|
||||
|
||||
_debug(this.getPathLocation() + " " + this.type + ": " + message);
|
||||
};
|
||||
|
||||
_proto.toString = function toString() {
|
||||
return (0, _generator().default)(this.node).code;
|
||||
};
|
||||
|
||||
return NodePath;
|
||||
}();
|
||||
|
||||
exports.default = NodePath;
|
||||
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
|
||||
var _arr = t().TYPES;
|
||||
|
||||
var _loop2 = function _loop2() {
|
||||
var type = _arr[_i];
|
||||
var typeKey = "is" + type;
|
||||
var fn = t()[typeKey];
|
||||
|
||||
NodePath.prototype[typeKey] = function (opts) {
|
||||
return fn(this.node, opts);
|
||||
};
|
||||
|
||||
NodePath.prototype["assert" + type] = function (opts) {
|
||||
if (!fn(this.node, opts)) {
|
||||
throw new TypeError("Expected node path of type " + type);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
_loop2();
|
||||
}
|
||||
|
||||
var _loop = function _loop(type) {
|
||||
if (type[0] === "_") return "continue";
|
||||
if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type);
|
||||
var virtualType = virtualTypes[type];
|
||||
|
||||
NodePath.prototype["is" + type] = function (opts) {
|
||||
return virtualType.checkPath(this, opts);
|
||||
};
|
||||
};
|
||||
|
||||
for (var type in virtualTypes) {
|
||||
var _ret = _loop(type);
|
||||
|
||||
if (_ret === "continue") continue;
|
||||
}
|
136
node_modules/@babel/traverse/lib/path/inference/index.js
generated
vendored
Normal file
136
node_modules/@babel/traverse/lib/path/inference/index.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getTypeAnnotation = getTypeAnnotation;
|
||||
exports._getTypeAnnotation = _getTypeAnnotation;
|
||||
exports.isBaseType = isBaseType;
|
||||
exports.couldBeBaseType = couldBeBaseType;
|
||||
exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
|
||||
exports.isGenericType = isGenericType;
|
||||
|
||||
var inferers = _interopRequireWildcard(require("./inferers"));
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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 getTypeAnnotation() {
|
||||
if (this.typeAnnotation) return this.typeAnnotation;
|
||||
var type = this._getTypeAnnotation() || t().anyTypeAnnotation();
|
||||
if (t().isTypeAnnotation(type)) type = type.typeAnnotation;
|
||||
return this.typeAnnotation = type;
|
||||
}
|
||||
|
||||
function _getTypeAnnotation() {
|
||||
var node = this.node;
|
||||
|
||||
if (!node) {
|
||||
if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
|
||||
var declar = this.parentPath.parentPath;
|
||||
var declarParent = declar.parentPath;
|
||||
|
||||
if (declar.key === "left" && declarParent.isForInStatement()) {
|
||||
return t().stringTypeAnnotation();
|
||||
}
|
||||
|
||||
if (declar.key === "left" && declarParent.isForOfStatement()) {
|
||||
return t().anyTypeAnnotation();
|
||||
}
|
||||
|
||||
return t().voidTypeAnnotation();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.typeAnnotation) {
|
||||
return node.typeAnnotation;
|
||||
}
|
||||
|
||||
var inferer = inferers[node.type];
|
||||
|
||||
if (inferer) {
|
||||
return inferer.call(this, node);
|
||||
}
|
||||
|
||||
inferer = inferers[this.parentPath.type];
|
||||
|
||||
if (inferer && inferer.validParent) {
|
||||
return this.parentPath.getTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
function isBaseType(baseName, soft) {
|
||||
return _isBaseType(baseName, this.getTypeAnnotation(), soft);
|
||||
}
|
||||
|
||||
function _isBaseType(baseName, type, soft) {
|
||||
if (baseName === "string") {
|
||||
return t().isStringTypeAnnotation(type);
|
||||
} else if (baseName === "number") {
|
||||
return t().isNumberTypeAnnotation(type);
|
||||
} else if (baseName === "boolean") {
|
||||
return t().isBooleanTypeAnnotation(type);
|
||||
} else if (baseName === "any") {
|
||||
return t().isAnyTypeAnnotation(type);
|
||||
} else if (baseName === "mixed") {
|
||||
return t().isMixedTypeAnnotation(type);
|
||||
} else if (baseName === "empty") {
|
||||
return t().isEmptyTypeAnnotation(type);
|
||||
} else if (baseName === "void") {
|
||||
return t().isVoidTypeAnnotation(type);
|
||||
} else {
|
||||
if (soft) {
|
||||
return false;
|
||||
} else {
|
||||
throw new Error("Unknown base type " + baseName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function couldBeBaseType(name) {
|
||||
var type = this.getTypeAnnotation();
|
||||
if (t().isAnyTypeAnnotation(type)) return true;
|
||||
|
||||
if (t().isUnionTypeAnnotation(type)) {
|
||||
var _arr = type.types;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var type2 = _arr[_i];
|
||||
|
||||
if (t().isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return _isBaseType(name, type, true);
|
||||
}
|
||||
}
|
||||
|
||||
function baseTypeStrictlyMatches(right) {
|
||||
var left = this.getTypeAnnotation();
|
||||
right = right.getTypeAnnotation();
|
||||
|
||||
if (!t().isAnyTypeAnnotation(left) && t().isFlowBaseAnnotation(left)) {
|
||||
return right.type === left.type;
|
||||
}
|
||||
}
|
||||
|
||||
function isGenericType(genericName) {
|
||||
var type = this.getTypeAnnotation();
|
||||
return t().isGenericTypeAnnotation(type) && t().isIdentifier(type.id, {
|
||||
name: genericName
|
||||
});
|
||||
}
|
185
node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
generated
vendored
Normal file
185
node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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 _default(node) {
|
||||
if (!this.isReferenced()) return;
|
||||
var binding = this.scope.getBinding(node.name);
|
||||
|
||||
if (binding) {
|
||||
if (binding.identifier.typeAnnotation) {
|
||||
return binding.identifier.typeAnnotation;
|
||||
} else {
|
||||
return getTypeAnnotationBindingConstantViolations(binding, this, node.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.name === "undefined") {
|
||||
return t().voidTypeAnnotation();
|
||||
} else if (node.name === "NaN" || node.name === "Infinity") {
|
||||
return t().numberTypeAnnotation();
|
||||
} else if (node.name === "arguments") {}
|
||||
}
|
||||
|
||||
function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
||||
var types = [];
|
||||
var functionConstantViolations = [];
|
||||
var constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations);
|
||||
var testType = getConditionalAnnotation(binding, path, name);
|
||||
|
||||
if (testType) {
|
||||
var testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
|
||||
constantViolations = constantViolations.filter(function (path) {
|
||||
return testConstantViolations.indexOf(path) < 0;
|
||||
});
|
||||
types.push(testType.typeAnnotation);
|
||||
}
|
||||
|
||||
if (constantViolations.length) {
|
||||
constantViolations = constantViolations.concat(functionConstantViolations);
|
||||
var _arr = constantViolations;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var violation = _arr[_i];
|
||||
types.push(violation.getTypeAnnotation());
|
||||
}
|
||||
}
|
||||
|
||||
if (types.length) {
|
||||
return t().createUnionTypeAnnotation(types);
|
||||
}
|
||||
}
|
||||
|
||||
function getConstantViolationsBefore(binding, path, functions) {
|
||||
var violations = binding.constantViolations.slice();
|
||||
violations.unshift(binding.path);
|
||||
return violations.filter(function (violation) {
|
||||
violation = violation.resolve();
|
||||
|
||||
var status = violation._guessExecutionStatusRelativeTo(path);
|
||||
|
||||
if (functions && status === "function") functions.push(violation);
|
||||
return status === "before";
|
||||
});
|
||||
}
|
||||
|
||||
function inferAnnotationFromBinaryExpression(name, path) {
|
||||
var operator = path.node.operator;
|
||||
var right = path.get("right").resolve();
|
||||
var left = path.get("left").resolve();
|
||||
var target;
|
||||
|
||||
if (left.isIdentifier({
|
||||
name: name
|
||||
})) {
|
||||
target = right;
|
||||
} else if (right.isIdentifier({
|
||||
name: name
|
||||
})) {
|
||||
target = left;
|
||||
}
|
||||
|
||||
if (target) {
|
||||
if (operator === "===") {
|
||||
return target.getTypeAnnotation();
|
||||
}
|
||||
|
||||
if (t().BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().numberTypeAnnotation();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (operator !== "===" && operator !== "==") return;
|
||||
var typeofPath;
|
||||
var typePath;
|
||||
|
||||
if (left.isUnaryExpression({
|
||||
operator: "typeof"
|
||||
})) {
|
||||
typeofPath = left;
|
||||
typePath = right;
|
||||
} else if (right.isUnaryExpression({
|
||||
operator: "typeof"
|
||||
})) {
|
||||
typeofPath = right;
|
||||
typePath = left;
|
||||
}
|
||||
|
||||
if (!typeofPath) return;
|
||||
if (!typeofPath.get("argument").isIdentifier({
|
||||
name: name
|
||||
})) return;
|
||||
typePath = typePath.resolve();
|
||||
if (!typePath.isLiteral()) return;
|
||||
var typeValue = typePath.node.value;
|
||||
if (typeof typeValue !== "string") return;
|
||||
return t().createTypeAnnotationBasedOnTypeof(typeValue);
|
||||
}
|
||||
|
||||
function getParentConditionalPath(binding, path, name) {
|
||||
var parentPath;
|
||||
|
||||
while (parentPath = path.parentPath) {
|
||||
if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {
|
||||
if (path.key === "test") {
|
||||
return;
|
||||
}
|
||||
|
||||
return parentPath;
|
||||
}
|
||||
|
||||
if (parentPath.isFunction()) {
|
||||
if (parentPath.parentPath.scope.getBinding(name) !== binding) return;
|
||||
}
|
||||
|
||||
path = parentPath;
|
||||
}
|
||||
}
|
||||
|
||||
function getConditionalAnnotation(binding, path, name) {
|
||||
var ifStatement = getParentConditionalPath(binding, path, name);
|
||||
if (!ifStatement) return;
|
||||
var test = ifStatement.get("test");
|
||||
var paths = [test];
|
||||
var types = [];
|
||||
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
var _path = paths[i];
|
||||
|
||||
if (_path.isLogicalExpression()) {
|
||||
if (_path.node.operator === "&&") {
|
||||
paths.push(_path.get("left"));
|
||||
paths.push(_path.get("right"));
|
||||
}
|
||||
} else if (_path.isBinaryExpression()) {
|
||||
var type = inferAnnotationFromBinaryExpression(name, _path);
|
||||
if (type) types.push(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (types.length) {
|
||||
return {
|
||||
typeAnnotation: t().createUnionTypeAnnotation(types),
|
||||
ifStatement: ifStatement
|
||||
};
|
||||
}
|
||||
|
||||
return getConditionalAnnotation(ifStatement, name);
|
||||
}
|
220
node_modules/@babel/traverse/lib/path/inference/inferers.js
generated
vendored
Normal file
220
node_modules/@babel/traverse/lib/path/inference/inferers.js
generated
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.VariableDeclarator = VariableDeclarator;
|
||||
exports.TypeCastExpression = TypeCastExpression;
|
||||
exports.NewExpression = NewExpression;
|
||||
exports.TemplateLiteral = TemplateLiteral;
|
||||
exports.UnaryExpression = UnaryExpression;
|
||||
exports.BinaryExpression = BinaryExpression;
|
||||
exports.LogicalExpression = LogicalExpression;
|
||||
exports.ConditionalExpression = ConditionalExpression;
|
||||
exports.SequenceExpression = SequenceExpression;
|
||||
exports.AssignmentExpression = AssignmentExpression;
|
||||
exports.UpdateExpression = UpdateExpression;
|
||||
exports.StringLiteral = StringLiteral;
|
||||
exports.NumericLiteral = NumericLiteral;
|
||||
exports.BooleanLiteral = BooleanLiteral;
|
||||
exports.NullLiteral = NullLiteral;
|
||||
exports.RegExpLiteral = RegExpLiteral;
|
||||
exports.ObjectExpression = ObjectExpression;
|
||||
exports.ArrayExpression = ArrayExpression;
|
||||
exports.RestElement = RestElement;
|
||||
exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
|
||||
exports.CallExpression = CallExpression;
|
||||
exports.TaggedTemplateExpression = TaggedTemplateExpression;
|
||||
Object.defineProperty(exports, "Identifier", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _infererReference.default;
|
||||
}
|
||||
});
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _infererReference = _interopRequireDefault(require("./inferer-reference"));
|
||||
|
||||
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; } }
|
||||
|
||||
function VariableDeclarator() {
|
||||
var id = this.get("id");
|
||||
if (!id.isIdentifier()) return;
|
||||
var init = this.get("init");
|
||||
var type = init.getTypeAnnotation();
|
||||
|
||||
if (type && type.type === "AnyTypeAnnotation") {
|
||||
if (init.isCallExpression() && init.get("callee").isIdentifier({
|
||||
name: "Array"
|
||||
}) && !init.scope.hasBinding("Array", true)) {
|
||||
type = ArrayExpression();
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function TypeCastExpression(node) {
|
||||
return node.typeAnnotation;
|
||||
}
|
||||
|
||||
TypeCastExpression.validParent = true;
|
||||
|
||||
function NewExpression(node) {
|
||||
if (this.get("callee").isIdentifier()) {
|
||||
return t().genericTypeAnnotation(node.callee);
|
||||
}
|
||||
}
|
||||
|
||||
function TemplateLiteral() {
|
||||
return t().stringTypeAnnotation();
|
||||
}
|
||||
|
||||
function UnaryExpression(node) {
|
||||
var operator = node.operator;
|
||||
|
||||
if (operator === "void") {
|
||||
return t().voidTypeAnnotation();
|
||||
} else if (t().NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().numberTypeAnnotation();
|
||||
} else if (t().STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().stringTypeAnnotation();
|
||||
} else if (t().BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().booleanTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
function BinaryExpression(node) {
|
||||
var operator = node.operator;
|
||||
|
||||
if (t().NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().numberTypeAnnotation();
|
||||
} else if (t().BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
||||
return t().booleanTypeAnnotation();
|
||||
} else if (operator === "+") {
|
||||
var right = this.get("right");
|
||||
var left = this.get("left");
|
||||
|
||||
if (left.isBaseType("number") && right.isBaseType("number")) {
|
||||
return t().numberTypeAnnotation();
|
||||
} else if (left.isBaseType("string") || right.isBaseType("string")) {
|
||||
return t().stringTypeAnnotation();
|
||||
}
|
||||
|
||||
return t().unionTypeAnnotation([t().stringTypeAnnotation(), t().numberTypeAnnotation()]);
|
||||
}
|
||||
}
|
||||
|
||||
function LogicalExpression() {
|
||||
return t().createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]);
|
||||
}
|
||||
|
||||
function ConditionalExpression() {
|
||||
return t().createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]);
|
||||
}
|
||||
|
||||
function SequenceExpression() {
|
||||
return this.get("expressions").pop().getTypeAnnotation();
|
||||
}
|
||||
|
||||
function AssignmentExpression() {
|
||||
return this.get("right").getTypeAnnotation();
|
||||
}
|
||||
|
||||
function UpdateExpression(node) {
|
||||
var operator = node.operator;
|
||||
|
||||
if (operator === "++" || operator === "--") {
|
||||
return t().numberTypeAnnotation();
|
||||
}
|
||||
}
|
||||
|
||||
function StringLiteral() {
|
||||
return t().stringTypeAnnotation();
|
||||
}
|
||||
|
||||
function NumericLiteral() {
|
||||
return t().numberTypeAnnotation();
|
||||
}
|
||||
|
||||
function BooleanLiteral() {
|
||||
return t().booleanTypeAnnotation();
|
||||
}
|
||||
|
||||
function NullLiteral() {
|
||||
return t().nullLiteralTypeAnnotation();
|
||||
}
|
||||
|
||||
function RegExpLiteral() {
|
||||
return t().genericTypeAnnotation(t().identifier("RegExp"));
|
||||
}
|
||||
|
||||
function ObjectExpression() {
|
||||
return t().genericTypeAnnotation(t().identifier("Object"));
|
||||
}
|
||||
|
||||
function ArrayExpression() {
|
||||
return t().genericTypeAnnotation(t().identifier("Array"));
|
||||
}
|
||||
|
||||
function RestElement() {
|
||||
return ArrayExpression();
|
||||
}
|
||||
|
||||
RestElement.validParent = true;
|
||||
|
||||
function Func() {
|
||||
return t().genericTypeAnnotation(t().identifier("Function"));
|
||||
}
|
||||
|
||||
var isArrayFrom = t().buildMatchMemberExpression("Array.from");
|
||||
var isObjectKeys = t().buildMatchMemberExpression("Object.keys");
|
||||
var isObjectValues = t().buildMatchMemberExpression("Object.values");
|
||||
var isObjectEntries = t().buildMatchMemberExpression("Object.entries");
|
||||
|
||||
function CallExpression() {
|
||||
var callee = this.node.callee;
|
||||
|
||||
if (isObjectKeys(callee)) {
|
||||
return t().arrayTypeAnnotation(t().stringTypeAnnotation());
|
||||
} else if (isArrayFrom(callee) || isObjectValues(callee)) {
|
||||
return t().arrayTypeAnnotation(t().anyTypeAnnotation());
|
||||
} else if (isObjectEntries(callee)) {
|
||||
return t().arrayTypeAnnotation(t().tupleTypeAnnotation([t().stringTypeAnnotation(), t().anyTypeAnnotation()]));
|
||||
}
|
||||
|
||||
return resolveCall(this.get("callee"));
|
||||
}
|
||||
|
||||
function TaggedTemplateExpression() {
|
||||
return resolveCall(this.get("tag"));
|
||||
}
|
||||
|
||||
function resolveCall(callee) {
|
||||
callee = callee.resolve();
|
||||
|
||||
if (callee.isFunction()) {
|
||||
if (callee.is("async")) {
|
||||
if (callee.is("generator")) {
|
||||
return t().genericTypeAnnotation(t().identifier("AsyncIterator"));
|
||||
} else {
|
||||
return t().genericTypeAnnotation(t().identifier("Promise"));
|
||||
}
|
||||
} else {
|
||||
if (callee.node.returnType) {
|
||||
return callee.node.returnType;
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
}
|
418
node_modules/@babel/traverse/lib/path/introspection.js
generated
vendored
Normal file
418
node_modules/@babel/traverse/lib/path/introspection.js
generated
vendored
Normal file
@@ -0,0 +1,418 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.matchesPattern = matchesPattern;
|
||||
exports.has = has;
|
||||
exports.isStatic = isStatic;
|
||||
exports.isnt = isnt;
|
||||
exports.equals = equals;
|
||||
exports.isNodeType = isNodeType;
|
||||
exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
|
||||
exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
|
||||
exports.isCompletionRecord = isCompletionRecord;
|
||||
exports.isStatementOrBlock = isStatementOrBlock;
|
||||
exports.referencesImport = referencesImport;
|
||||
exports.getSource = getSource;
|
||||
exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
|
||||
exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
|
||||
exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatusRelativeToDifferentFunctions;
|
||||
exports.resolve = resolve;
|
||||
exports._resolve = _resolve;
|
||||
exports.isConstantExpression = isConstantExpression;
|
||||
exports.isInStrictMode = isInStrictMode;
|
||||
exports.is = void 0;
|
||||
|
||||
function _includes() {
|
||||
var data = _interopRequireDefault(require("lodash/includes"));
|
||||
|
||||
_includes = function _includes() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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 }; }
|
||||
|
||||
function matchesPattern(pattern, allowPartial) {
|
||||
return t().matchesPattern(this.node, pattern, allowPartial);
|
||||
}
|
||||
|
||||
function has(key) {
|
||||
var val = this.node && this.node[key];
|
||||
|
||||
if (val && Array.isArray(val)) {
|
||||
return !!val.length;
|
||||
} else {
|
||||
return !!val;
|
||||
}
|
||||
}
|
||||
|
||||
function isStatic() {
|
||||
return this.scope.isStatic(this.node);
|
||||
}
|
||||
|
||||
var is = has;
|
||||
exports.is = is;
|
||||
|
||||
function isnt(key) {
|
||||
return !this.has(key);
|
||||
}
|
||||
|
||||
function equals(key, value) {
|
||||
return this.node[key] === value;
|
||||
}
|
||||
|
||||
function isNodeType(type) {
|
||||
return t().isType(this.type, type);
|
||||
}
|
||||
|
||||
function canHaveVariableDeclarationOrExpression() {
|
||||
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
|
||||
}
|
||||
|
||||
function canSwapBetweenExpressionAndStatement(replacement) {
|
||||
if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isExpression()) {
|
||||
return t().isBlockStatement(replacement);
|
||||
} else if (this.isBlockStatement()) {
|
||||
return t().isExpression(replacement);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isCompletionRecord(allowInsideFunction) {
|
||||
var path = this;
|
||||
var first = true;
|
||||
|
||||
do {
|
||||
var container = path.container;
|
||||
|
||||
if (path.isFunction() && !first) {
|
||||
return !!allowInsideFunction;
|
||||
}
|
||||
|
||||
first = false;
|
||||
|
||||
if (Array.isArray(container) && path.key !== container.length - 1) {
|
||||
return false;
|
||||
}
|
||||
} while ((path = path.parentPath) && !path.isProgram());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function isStatementOrBlock() {
|
||||
if (this.parentPath.isLabeledStatement() || t().isBlockStatement(this.container)) {
|
||||
return false;
|
||||
} else {
|
||||
return (0, _includes().default)(t().STATEMENT_OR_BLOCK_KEYS, this.key);
|
||||
}
|
||||
}
|
||||
|
||||
function referencesImport(moduleSource, importName) {
|
||||
if (!this.isReferencedIdentifier()) return false;
|
||||
var binding = this.scope.getBinding(this.node.name);
|
||||
if (!binding || binding.kind !== "module") return false;
|
||||
var path = binding.path;
|
||||
var parent = path.parentPath;
|
||||
if (!parent.isImportDeclaration()) return false;
|
||||
|
||||
if (parent.node.source.value === moduleSource) {
|
||||
if (!importName) return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (path.isImportDefaultSpecifier() && importName === "default") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (path.isImportNamespaceSpecifier() && importName === "*") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (path.isImportSpecifier() && path.node.imported.name === importName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getSource() {
|
||||
var node = this.node;
|
||||
|
||||
if (node.end) {
|
||||
return this.hub.file.code.slice(node.start, node.end);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function willIMaybeExecuteBefore(target) {
|
||||
return this._guessExecutionStatusRelativeTo(target) !== "after";
|
||||
}
|
||||
|
||||
function _guessExecutionStatusRelativeTo(target) {
|
||||
var targetFuncParent = target.scope.getFunctionParent() || target.scope.getProgramParent();
|
||||
var selfFuncParent = this.scope.getFunctionParent() || target.scope.getProgramParent();
|
||||
|
||||
if (targetFuncParent.node !== selfFuncParent.node) {
|
||||
var status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent);
|
||||
|
||||
if (status) {
|
||||
return status;
|
||||
} else {
|
||||
target = targetFuncParent.path;
|
||||
}
|
||||
}
|
||||
|
||||
var targetPaths = target.getAncestry();
|
||||
if (targetPaths.indexOf(this) >= 0) return "after";
|
||||
var selfPaths = this.getAncestry();
|
||||
var commonPath;
|
||||
var targetIndex;
|
||||
var selfIndex;
|
||||
|
||||
for (selfIndex = 0; selfIndex < selfPaths.length; selfIndex++) {
|
||||
var selfPath = selfPaths[selfIndex];
|
||||
targetIndex = targetPaths.indexOf(selfPath);
|
||||
|
||||
if (targetIndex >= 0) {
|
||||
commonPath = selfPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!commonPath) {
|
||||
return "before";
|
||||
}
|
||||
|
||||
var targetRelationship = targetPaths[targetIndex - 1];
|
||||
var selfRelationship = selfPaths[selfIndex - 1];
|
||||
|
||||
if (!targetRelationship || !selfRelationship) {
|
||||
return "before";
|
||||
}
|
||||
|
||||
if (targetRelationship.listKey && targetRelationship.container === selfRelationship.container) {
|
||||
return targetRelationship.key > selfRelationship.key ? "before" : "after";
|
||||
}
|
||||
|
||||
var keys = t().VISITOR_KEYS[commonPath.type];
|
||||
var targetKeyPosition = keys.indexOf(targetRelationship.key);
|
||||
var selfKeyPosition = keys.indexOf(selfRelationship.key);
|
||||
return targetKeyPosition > selfKeyPosition ? "before" : "after";
|
||||
}
|
||||
|
||||
function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent) {
|
||||
var targetFuncPath = targetFuncParent.path;
|
||||
if (!targetFuncPath.isFunctionDeclaration()) return;
|
||||
var binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name);
|
||||
if (!binding.references) return "before";
|
||||
var referencePaths = binding.referencePaths;
|
||||
|
||||
for (var _iterator = referencePaths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var path = _ref;
|
||||
|
||||
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var allStatus;
|
||||
|
||||
for (var _iterator2 = referencePaths, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var _path = _ref2;
|
||||
var childOfFunction = !!_path.find(function (path) {
|
||||
return path.node === targetFuncPath.node;
|
||||
});
|
||||
if (childOfFunction) continue;
|
||||
|
||||
var status = this._guessExecutionStatusRelativeTo(_path);
|
||||
|
||||
if (allStatus) {
|
||||
if (allStatus !== status) return;
|
||||
} else {
|
||||
allStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
return allStatus;
|
||||
}
|
||||
|
||||
function resolve(dangerous, resolved) {
|
||||
return this._resolve(dangerous, resolved) || this;
|
||||
}
|
||||
|
||||
function _resolve(dangerous, resolved) {
|
||||
if (resolved && resolved.indexOf(this) >= 0) return;
|
||||
resolved = resolved || [];
|
||||
resolved.push(this);
|
||||
|
||||
if (this.isVariableDeclarator()) {
|
||||
if (this.get("id").isIdentifier()) {
|
||||
return this.get("init").resolve(dangerous, resolved);
|
||||
} else {}
|
||||
} else if (this.isReferencedIdentifier()) {
|
||||
var binding = this.scope.getBinding(this.node.name);
|
||||
if (!binding) return;
|
||||
if (!binding.constant) return;
|
||||
if (binding.kind === "module") return;
|
||||
|
||||
if (binding.path !== this) {
|
||||
var ret = binding.path.resolve(dangerous, resolved);
|
||||
if (this.find(function (parent) {
|
||||
return parent.node === ret.node;
|
||||
})) return;
|
||||
return ret;
|
||||
}
|
||||
} else if (this.isTypeCastExpression()) {
|
||||
return this.get("expression").resolve(dangerous, resolved);
|
||||
} else if (dangerous && this.isMemberExpression()) {
|
||||
var targetKey = this.toComputedKey();
|
||||
if (!t().isLiteral(targetKey)) return;
|
||||
var targetName = targetKey.value;
|
||||
var target = this.get("object").resolve(dangerous, resolved);
|
||||
|
||||
if (target.isObjectExpression()) {
|
||||
var props = target.get("properties");
|
||||
var _arr = props;
|
||||
|
||||
for (var _i3 = 0; _i3 < _arr.length; _i3++) {
|
||||
var prop = _arr[_i3];
|
||||
if (!prop.isProperty()) continue;
|
||||
var key = prop.get("key");
|
||||
var match = prop.isnt("computed") && key.isIdentifier({
|
||||
name: targetName
|
||||
});
|
||||
match = match || key.isLiteral({
|
||||
value: targetName
|
||||
});
|
||||
if (match) return prop.get("value").resolve(dangerous, resolved);
|
||||
}
|
||||
} else if (target.isArrayExpression() && !isNaN(+targetName)) {
|
||||
var elems = target.get("elements");
|
||||
var elem = elems[targetName];
|
||||
if (elem) return elem.resolve(dangerous, resolved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isConstantExpression() {
|
||||
if (this.isIdentifier()) {
|
||||
var binding = this.scope.getBinding(this.node.name);
|
||||
|
||||
if (!binding) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return binding.constant && binding.path.get("init").isConstantExpression();
|
||||
}
|
||||
|
||||
if (this.isLiteral()) {
|
||||
if (this.isRegExpLiteral()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isTemplateLiteral()) {
|
||||
return this.get("expressions").every(function (expression) {
|
||||
return expression.isConstantExpression();
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.isUnaryExpression()) {
|
||||
if (this.get("operator").node !== "void") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.get("argument").isConstantExpression();
|
||||
}
|
||||
|
||||
if (this.isBinaryExpression()) {
|
||||
return this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isInStrictMode() {
|
||||
var start = this.isProgram() ? this : this.parentPath;
|
||||
var strictParent = start.find(function (path) {
|
||||
if (path.isProgram({
|
||||
sourceType: "module"
|
||||
})) return true;
|
||||
if (path.isClass()) return true;
|
||||
if (!path.isProgram() && !path.isFunction()) return false;
|
||||
|
||||
if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var node = path.node;
|
||||
if (path.isFunction()) node = node.body;
|
||||
|
||||
for (var _iterator3 = node.directives, _isArray3 = Array.isArray(_iterator3), _i4 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
if (_isArray3) {
|
||||
if (_i4 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i4++];
|
||||
} else {
|
||||
_i4 = _iterator3.next();
|
||||
if (_i4.done) break;
|
||||
_ref3 = _i4.value;
|
||||
}
|
||||
|
||||
var directive = _ref3;
|
||||
|
||||
if (directive.value.value === "use strict") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return !!strictParent;
|
||||
}
|
196
node_modules/@babel/traverse/lib/path/lib/hoister.js
generated
vendored
Normal file
196
node_modules/@babel/traverse/lib/path/lib/hoister.js
generated
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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; } }
|
||||
|
||||
var referenceVisitor = {
|
||||
ReferencedIdentifier: function ReferencedIdentifier(path, state) {
|
||||
if (path.isJSXIdentifier() && t().react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (path.node.name === "this") {
|
||||
var scope = path.scope;
|
||||
|
||||
do {
|
||||
if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
|
||||
break;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
|
||||
if (scope) state.breakOnScopePaths.push(scope.path);
|
||||
}
|
||||
|
||||
var binding = path.scope.getBinding(path.node.name);
|
||||
if (!binding) return;
|
||||
if (binding !== state.scope.getBinding(path.node.name)) return;
|
||||
state.bindings[path.node.name] = binding;
|
||||
}
|
||||
};
|
||||
|
||||
var PathHoister = function () {
|
||||
function PathHoister(path, scope) {
|
||||
this.breakOnScopePaths = [];
|
||||
this.bindings = {};
|
||||
this.scopes = [];
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
this.attachAfter = false;
|
||||
}
|
||||
|
||||
var _proto = PathHoister.prototype;
|
||||
|
||||
_proto.isCompatibleScope = function isCompatibleScope(scope) {
|
||||
for (var key in this.bindings) {
|
||||
var binding = this.bindings[key];
|
||||
|
||||
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
_proto.getCompatibleScopes = function getCompatibleScopes() {
|
||||
var scope = this.path.scope;
|
||||
|
||||
do {
|
||||
if (this.isCompatibleScope(scope)) {
|
||||
this.scopes.push(scope);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
|
||||
break;
|
||||
}
|
||||
} while (scope = scope.parent);
|
||||
};
|
||||
|
||||
_proto.getAttachmentPath = function getAttachmentPath() {
|
||||
var path = this._getAttachmentPath();
|
||||
|
||||
if (!path) return;
|
||||
var targetScope = path.scope;
|
||||
|
||||
if (targetScope.path === path) {
|
||||
targetScope = path.scope.parent;
|
||||
}
|
||||
|
||||
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
|
||||
for (var name in this.bindings) {
|
||||
if (!targetScope.hasOwnBinding(name)) continue;
|
||||
var binding = this.bindings[name];
|
||||
|
||||
if (binding.kind === "param" || binding.path.parentKey === "params") {
|
||||
continue;
|
||||
}
|
||||
|
||||
var bindingParentPath = this.getAttachmentParentForPath(binding.path);
|
||||
|
||||
if (bindingParentPath.key >= path.key) {
|
||||
this.attachAfter = true;
|
||||
path = binding.path;
|
||||
var _arr = binding.constantViolations;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var violationPath = _arr[_i];
|
||||
|
||||
if (this.getAttachmentParentForPath(violationPath).key > path.key) {
|
||||
path = violationPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
};
|
||||
|
||||
_proto._getAttachmentPath = function _getAttachmentPath() {
|
||||
var scopes = this.scopes;
|
||||
var scope = scopes.pop();
|
||||
if (!scope) return;
|
||||
|
||||
if (scope.path.isFunction()) {
|
||||
if (this.hasOwnParamBindings(scope)) {
|
||||
if (this.scope === scope) return;
|
||||
var bodies = scope.path.get("body").get("body");
|
||||
|
||||
for (var i = 0; i < bodies.length; i++) {
|
||||
if (bodies[i].node._blockHoist) continue;
|
||||
return bodies[i];
|
||||
}
|
||||
} else {
|
||||
return this.getNextScopeAttachmentParent();
|
||||
}
|
||||
} else if (scope.path.isProgram()) {
|
||||
return this.getNextScopeAttachmentParent();
|
||||
}
|
||||
};
|
||||
|
||||
_proto.getNextScopeAttachmentParent = function getNextScopeAttachmentParent() {
|
||||
var scope = this.scopes.pop();
|
||||
if (scope) return this.getAttachmentParentForPath(scope.path);
|
||||
};
|
||||
|
||||
_proto.getAttachmentParentForPath = function getAttachmentParentForPath(path) {
|
||||
do {
|
||||
if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
|
||||
return path;
|
||||
}
|
||||
} while (path = path.parentPath);
|
||||
};
|
||||
|
||||
_proto.hasOwnParamBindings = function hasOwnParamBindings(scope) {
|
||||
for (var name in this.bindings) {
|
||||
if (!scope.hasOwnBinding(name)) continue;
|
||||
var binding = this.bindings[name];
|
||||
if (binding.kind === "param" && binding.constant) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
_proto.run = function run() {
|
||||
this.path.traverse(referenceVisitor, this);
|
||||
this.getCompatibleScopes();
|
||||
var attachTo = this.getAttachmentPath();
|
||||
if (!attachTo) return;
|
||||
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
|
||||
var uid = attachTo.scope.generateUidIdentifier("ref");
|
||||
var declarator = t().variableDeclarator(uid, this.path.node);
|
||||
var insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
|
||||
|
||||
var _attachTo$insertFn = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t().variableDeclaration("var", [declarator])]),
|
||||
attached = _attachTo$insertFn[0];
|
||||
|
||||
var parent = this.path.parentPath;
|
||||
|
||||
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
||||
uid = t().JSXExpressionContainer(uid);
|
||||
}
|
||||
|
||||
this.path.replaceWith(t().cloneNode(uid));
|
||||
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
|
||||
};
|
||||
|
||||
return PathHoister;
|
||||
}();
|
||||
|
||||
exports.default = PathHoister;
|
38
node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
generated
vendored
Normal file
38
node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.hooks = void 0;
|
||||
var hooks = [function (self, parent) {
|
||||
var removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
|
||||
|
||||
if (removeParent) {
|
||||
parent.remove();
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
|
||||
parent.replaceWith(parent.node.expressions[0]);
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isBinary()) {
|
||||
if (self.key === "left") {
|
||||
parent.replaceWith(parent.node.right);
|
||||
} else {
|
||||
parent.replaceWith(parent.node.left);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}, function (self, parent) {
|
||||
if (parent.isIfStatement() && (self.key === "consequent" || self.key === "alternate") || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
|
||||
self.replaceWith({
|
||||
type: "BlockStatement",
|
||||
body: []
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}];
|
||||
exports.hooks = hooks;
|
182
node_modules/@babel/traverse/lib/path/lib/virtual-types.js
generated
vendored
Normal file
182
node_modules/@babel/traverse/lib/path/lib/virtual-types.js
generated
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0;
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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; } }
|
||||
|
||||
var ReferencedIdentifier = {
|
||||
types: ["Identifier", "JSXIdentifier"],
|
||||
checkPath: function checkPath(_ref, opts) {
|
||||
var node = _ref.node,
|
||||
parent = _ref.parent;
|
||||
|
||||
if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) {
|
||||
if (t().isJSXIdentifier(node, opts)) {
|
||||
if (t().react.isCompatTag(node.name)) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return t().isReferenced(node, parent);
|
||||
}
|
||||
};
|
||||
exports.ReferencedIdentifier = ReferencedIdentifier;
|
||||
var ReferencedMemberExpression = {
|
||||
types: ["MemberExpression"],
|
||||
checkPath: function checkPath(_ref2) {
|
||||
var node = _ref2.node,
|
||||
parent = _ref2.parent;
|
||||
return t().isMemberExpression(node) && t().isReferenced(node, parent);
|
||||
}
|
||||
};
|
||||
exports.ReferencedMemberExpression = ReferencedMemberExpression;
|
||||
var BindingIdentifier = {
|
||||
types: ["Identifier"],
|
||||
checkPath: function checkPath(_ref3) {
|
||||
var node = _ref3.node,
|
||||
parent = _ref3.parent;
|
||||
return t().isIdentifier(node) && t().isBinding(node, parent);
|
||||
}
|
||||
};
|
||||
exports.BindingIdentifier = BindingIdentifier;
|
||||
var Statement = {
|
||||
types: ["Statement"],
|
||||
checkPath: function checkPath(_ref4) {
|
||||
var node = _ref4.node,
|
||||
parent = _ref4.parent;
|
||||
|
||||
if (t().isStatement(node)) {
|
||||
if (t().isVariableDeclaration(node)) {
|
||||
if (t().isForXStatement(parent, {
|
||||
left: node
|
||||
})) return false;
|
||||
if (t().isForStatement(parent, {
|
||||
init: node
|
||||
})) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.Statement = Statement;
|
||||
var Expression = {
|
||||
types: ["Expression"],
|
||||
checkPath: function checkPath(path) {
|
||||
if (path.isIdentifier()) {
|
||||
return path.isReferencedIdentifier();
|
||||
} else {
|
||||
return t().isExpression(path.node);
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.Expression = Expression;
|
||||
var Scope = {
|
||||
types: ["Scopable"],
|
||||
checkPath: function checkPath(path) {
|
||||
return t().isScope(path.node, path.parent);
|
||||
}
|
||||
};
|
||||
exports.Scope = Scope;
|
||||
var Referenced = {
|
||||
checkPath: function checkPath(path) {
|
||||
return t().isReferenced(path.node, path.parent);
|
||||
}
|
||||
};
|
||||
exports.Referenced = Referenced;
|
||||
var BlockScoped = {
|
||||
checkPath: function checkPath(path) {
|
||||
return t().isBlockScoped(path.node);
|
||||
}
|
||||
};
|
||||
exports.BlockScoped = BlockScoped;
|
||||
var Var = {
|
||||
types: ["VariableDeclaration"],
|
||||
checkPath: function checkPath(path) {
|
||||
return t().isVar(path.node);
|
||||
}
|
||||
};
|
||||
exports.Var = Var;
|
||||
var User = {
|
||||
checkPath: function checkPath(path) {
|
||||
return path.node && !!path.node.loc;
|
||||
}
|
||||
};
|
||||
exports.User = User;
|
||||
var Generated = {
|
||||
checkPath: function checkPath(path) {
|
||||
return !path.isUser();
|
||||
}
|
||||
};
|
||||
exports.Generated = Generated;
|
||||
var Pure = {
|
||||
checkPath: function checkPath(path, opts) {
|
||||
return path.scope.isPure(path.node, opts);
|
||||
}
|
||||
};
|
||||
exports.Pure = Pure;
|
||||
var Flow = {
|
||||
types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
|
||||
checkPath: function checkPath(_ref5) {
|
||||
var node = _ref5.node;
|
||||
|
||||
if (t().isFlow(node)) {
|
||||
return true;
|
||||
} else if (t().isImportDeclaration(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else if (t().isExportDeclaration(node)) {
|
||||
return node.exportKind === "type";
|
||||
} else if (t().isImportSpecifier(node)) {
|
||||
return node.importKind === "type" || node.importKind === "typeof";
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.Flow = Flow;
|
||||
var RestProperty = {
|
||||
types: ["RestElement"],
|
||||
checkPath: function checkPath(path) {
|
||||
return path.parentPath && path.parentPath.isObjectPattern();
|
||||
}
|
||||
};
|
||||
exports.RestProperty = RestProperty;
|
||||
var SpreadProperty = {
|
||||
types: ["RestElement"],
|
||||
checkPath: function checkPath(path) {
|
||||
return path.parentPath && path.parentPath.isObjectExpression();
|
||||
}
|
||||
};
|
||||
exports.SpreadProperty = SpreadProperty;
|
||||
var ExistentialTypeParam = {
|
||||
types: ["ExistsTypeAnnotation"]
|
||||
};
|
||||
exports.ExistentialTypeParam = ExistentialTypeParam;
|
||||
var NumericLiteralTypeAnnotation = {
|
||||
types: ["NumberLiteralTypeAnnotation"]
|
||||
};
|
||||
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
|
||||
var ForAwaitStatement = {
|
||||
types: ["ForOfStatement"],
|
||||
checkPath: function checkPath(_ref6) {
|
||||
var node = _ref6.node;
|
||||
return node.await === true;
|
||||
}
|
||||
};
|
||||
exports.ForAwaitStatement = ForAwaitStatement;
|
236
node_modules/@babel/traverse/lib/path/modification.js
generated
vendored
Normal file
236
node_modules/@babel/traverse/lib/path/modification.js
generated
vendored
Normal file
@@ -0,0 +1,236 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.insertBefore = insertBefore;
|
||||
exports._containerInsert = _containerInsert;
|
||||
exports._containerInsertBefore = _containerInsertBefore;
|
||||
exports._containerInsertAfter = _containerInsertAfter;
|
||||
exports.insertAfter = insertAfter;
|
||||
exports.updateSiblingKeys = updateSiblingKeys;
|
||||
exports._verifyNodeList = _verifyNodeList;
|
||||
exports.unshiftContainer = unshiftContainer;
|
||||
exports.pushContainer = pushContainer;
|
||||
exports.hoist = hoist;
|
||||
|
||||
var _cache = require("../cache");
|
||||
|
||||
var _hoister = _interopRequireDefault(require("./lib/hoister"));
|
||||
|
||||
var _index = _interopRequireDefault(require("./index"));
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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 }; }
|
||||
|
||||
function insertBefore(nodes) {
|
||||
this._assertUnremoved();
|
||||
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
var parentPath = this.parentPath;
|
||||
|
||||
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
||||
return parentPath.insertBefore(nodes);
|
||||
} else if (this.isNodeType("Expression") && this.listKey !== "params" && this.listKey !== "arguments" || parentPath.isForStatement() && this.key === "init") {
|
||||
if (this.node) nodes.push(this.node);
|
||||
return this.replaceExpressionWithStatements(nodes);
|
||||
} else if (Array.isArray(this.container)) {
|
||||
return this._containerInsertBefore(nodes);
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
var shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
|
||||
this.replaceWith(t().blockStatement(shouldInsertCurrentNode ? [this.node] : []));
|
||||
return this.unshiftContainer("body", nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
}
|
||||
|
||||
function _containerInsert(from, nodes) {
|
||||
var _container;
|
||||
|
||||
this.updateSiblingKeys(from, nodes.length);
|
||||
var paths = [];
|
||||
|
||||
(_container = this.container).splice.apply(_container, [from, 0].concat(nodes));
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var to = from + i;
|
||||
var path = this.getSibling(to);
|
||||
paths.push(path);
|
||||
|
||||
if (this.context && this.context.queue) {
|
||||
path.pushContext(this.context);
|
||||
}
|
||||
}
|
||||
|
||||
var contexts = this._getQueueContexts();
|
||||
|
||||
for (var _i = 0; _i < paths.length; _i++) {
|
||||
var _path = paths[_i];
|
||||
|
||||
_path.setScope();
|
||||
|
||||
_path.debug("Inserted.");
|
||||
|
||||
for (var _iterator = contexts, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i2 >= _iterator.length) break;
|
||||
_ref = _iterator[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator.next();
|
||||
if (_i2.done) break;
|
||||
_ref = _i2.value;
|
||||
}
|
||||
|
||||
var context = _ref;
|
||||
context.maybeQueue(_path, true);
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function _containerInsertBefore(nodes) {
|
||||
return this._containerInsert(this.key, nodes);
|
||||
}
|
||||
|
||||
function _containerInsertAfter(nodes) {
|
||||
return this._containerInsert(this.key + 1, nodes);
|
||||
}
|
||||
|
||||
function insertAfter(nodes) {
|
||||
this._assertUnremoved();
|
||||
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
var parentPath = this.parentPath;
|
||||
|
||||
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
||||
return parentPath.insertAfter(nodes);
|
||||
} else if (this.isNodeType("Expression") || parentPath.isForStatement() && this.key === "init") {
|
||||
if (this.node) {
|
||||
var scope = this.scope;
|
||||
|
||||
if (parentPath.isMethod({
|
||||
computed: true,
|
||||
key: this.node
|
||||
})) {
|
||||
scope = scope.parent;
|
||||
}
|
||||
|
||||
var temp = scope.generateDeclaredUidIdentifier();
|
||||
nodes.unshift(t().expressionStatement(t().assignmentExpression("=", t().cloneNode(temp), this.node)));
|
||||
nodes.push(t().expressionStatement(t().cloneNode(temp)));
|
||||
}
|
||||
|
||||
return this.replaceExpressionWithStatements(nodes);
|
||||
} else if (Array.isArray(this.container)) {
|
||||
return this._containerInsertAfter(nodes);
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
var shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null);
|
||||
this.replaceWith(t().blockStatement(shouldInsertCurrentNode ? [this.node] : []));
|
||||
return this.pushContainer("body", nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. " + "We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
}
|
||||
|
||||
function updateSiblingKeys(fromIndex, incrementBy) {
|
||||
if (!this.parent) return;
|
||||
|
||||
var paths = _cache.path.get(this.parent);
|
||||
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
var path = paths[i];
|
||||
|
||||
if (path.key >= fromIndex) {
|
||||
path.key += incrementBy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _verifyNodeList(nodes) {
|
||||
if (!nodes) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (nodes.constructor !== Array) {
|
||||
nodes = [nodes];
|
||||
}
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
var msg = void 0;
|
||||
|
||||
if (!node) {
|
||||
msg = "has falsy node";
|
||||
} else if (typeof node !== "object") {
|
||||
msg = "contains a non-object node";
|
||||
} else if (!node.type) {
|
||||
msg = "without a type";
|
||||
} else if (node instanceof _index.default) {
|
||||
msg = "has a NodePath when it expected a raw object";
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
var type = Array.isArray(node) ? "array" : typeof node;
|
||||
throw new Error("Node list " + msg + " with the index of " + i + " and type of " + type);
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function unshiftContainer(listKey, nodes) {
|
||||
this._assertUnremoved();
|
||||
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
|
||||
var path = _index.default.get({
|
||||
parentPath: this,
|
||||
parent: this.node,
|
||||
container: this.node[listKey],
|
||||
listKey: listKey,
|
||||
key: 0
|
||||
});
|
||||
|
||||
return path.insertBefore(nodes);
|
||||
}
|
||||
|
||||
function pushContainer(listKey, nodes) {
|
||||
this._assertUnremoved();
|
||||
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
var container = this.node[listKey];
|
||||
|
||||
var path = _index.default.get({
|
||||
parentPath: this,
|
||||
parent: this.node,
|
||||
container: container,
|
||||
listKey: listKey,
|
||||
key: container.length
|
||||
});
|
||||
|
||||
return path.replaceWithMultiple(nodes);
|
||||
}
|
||||
|
||||
function hoist(scope) {
|
||||
if (scope === void 0) {
|
||||
scope = this.scope;
|
||||
}
|
||||
|
||||
var hoister = new _hoister.default(this, scope);
|
||||
return hoister.run();
|
||||
}
|
72
node_modules/@babel/traverse/lib/path/removal.js
generated
vendored
Normal file
72
node_modules/@babel/traverse/lib/path/removal.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.remove = remove;
|
||||
exports._removeFromScope = _removeFromScope;
|
||||
exports._callRemovalHooks = _callRemovalHooks;
|
||||
exports._remove = _remove;
|
||||
exports._markRemoved = _markRemoved;
|
||||
exports._assertUnremoved = _assertUnremoved;
|
||||
|
||||
var _removalHooks = require("./lib/removal-hooks");
|
||||
|
||||
function remove() {
|
||||
this._assertUnremoved();
|
||||
|
||||
this.resync();
|
||||
|
||||
this._removeFromScope();
|
||||
|
||||
if (this._callRemovalHooks()) {
|
||||
this._markRemoved();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.shareCommentsWithSiblings();
|
||||
|
||||
this._remove();
|
||||
|
||||
this._markRemoved();
|
||||
}
|
||||
|
||||
function _removeFromScope() {
|
||||
var _this = this;
|
||||
|
||||
var bindings = this.getBindingIdentifiers();
|
||||
Object.keys(bindings).forEach(function (name) {
|
||||
return _this.scope.removeBinding(name);
|
||||
});
|
||||
}
|
||||
|
||||
function _callRemovalHooks() {
|
||||
var _arr = _removalHooks.hooks;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var fn = _arr[_i];
|
||||
if (fn(this, this.parentPath)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
function _remove() {
|
||||
if (Array.isArray(this.container)) {
|
||||
this.container.splice(this.key, 1);
|
||||
this.updateSiblingKeys(this.key, -1);
|
||||
} else {
|
||||
this._replaceWith(null);
|
||||
}
|
||||
}
|
||||
|
||||
function _markRemoved() {
|
||||
this.shouldSkip = true;
|
||||
this.removed = true;
|
||||
this.node = null;
|
||||
}
|
||||
|
||||
function _assertUnremoved() {
|
||||
if (this.removed) {
|
||||
throw this.buildCodeFrameError("NodePath has been removed so is read-only.");
|
||||
}
|
||||
}
|
276
node_modules/@babel/traverse/lib/path/replacement.js
generated
vendored
Normal file
276
node_modules/@babel/traverse/lib/path/replacement.js
generated
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.replaceWithMultiple = replaceWithMultiple;
|
||||
exports.replaceWithSourceString = replaceWithSourceString;
|
||||
exports.replaceWith = replaceWith;
|
||||
exports._replaceWith = _replaceWith;
|
||||
exports.replaceExpressionWithStatements = replaceExpressionWithStatements;
|
||||
exports.replaceInline = replaceInline;
|
||||
|
||||
function _codeFrame() {
|
||||
var data = require("@babel/code-frame");
|
||||
|
||||
_codeFrame = function _codeFrame() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
var _index = _interopRequireDefault(require("../index"));
|
||||
|
||||
var _index2 = _interopRequireDefault(require("./index"));
|
||||
|
||||
function _babylon() {
|
||||
var data = require("babylon");
|
||||
|
||||
_babylon = function _babylon() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function t() {
|
||||
var data = _interopRequireWildcard(require("@babel/types"));
|
||||
|
||||
t = function t() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
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 }; }
|
||||
|
||||
var hoistVariablesVisitor = {
|
||||
Function: function Function(path) {
|
||||
path.skip();
|
||||
},
|
||||
VariableDeclaration: function VariableDeclaration(path) {
|
||||
if (path.node.kind !== "var") return;
|
||||
var bindings = path.getBindingIdentifiers();
|
||||
|
||||
for (var key in bindings) {
|
||||
path.scope.push({
|
||||
id: bindings[key]
|
||||
});
|
||||
}
|
||||
|
||||
var exprs = [];
|
||||
var _arr = path.node.declarations;
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var declar = _arr[_i];
|
||||
|
||||
if (declar.init) {
|
||||
exprs.push(t().expressionStatement(t().assignmentExpression("=", declar.id, declar.init)));
|
||||
}
|
||||
}
|
||||
|
||||
path.replaceWithMultiple(exprs);
|
||||
}
|
||||
};
|
||||
|
||||
function replaceWithMultiple(nodes) {
|
||||
this.resync();
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
t().inheritLeadingComments(nodes[0], this.node);
|
||||
t().inheritTrailingComments(nodes[nodes.length - 1], this.node);
|
||||
this.node = this.container[this.key] = null;
|
||||
var paths = this.insertAfter(nodes);
|
||||
|
||||
if (this.node) {
|
||||
this.requeue();
|
||||
} else {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function replaceWithSourceString(replacement) {
|
||||
this.resync();
|
||||
|
||||
try {
|
||||
replacement = "(" + replacement + ")";
|
||||
replacement = (0, _babylon().parse)(replacement);
|
||||
} catch (err) {
|
||||
var loc = err.loc;
|
||||
|
||||
if (loc) {
|
||||
err.message += " - make sure this is an expression.\n" + (0, _codeFrame().codeFrameColumns)(replacement, {
|
||||
start: {
|
||||
line: loc.line,
|
||||
column: loc.column + 1
|
||||
}
|
||||
});
|
||||
err.code = "BABEL_REPLACE_SOURCE_ERROR";
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
replacement = replacement.program.body[0].expression;
|
||||
|
||||
_index.default.removeProperties(replacement);
|
||||
|
||||
return this.replaceWith(replacement);
|
||||
}
|
||||
|
||||
function replaceWith(replacement) {
|
||||
this.resync();
|
||||
|
||||
if (this.removed) {
|
||||
throw new Error("You can't replace this node, we've already removed it");
|
||||
}
|
||||
|
||||
if (replacement instanceof _index2.default) {
|
||||
replacement = replacement.node;
|
||||
}
|
||||
|
||||
if (!replacement) {
|
||||
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
||||
}
|
||||
|
||||
if (this.node === replacement) {
|
||||
return [this];
|
||||
}
|
||||
|
||||
if (this.isProgram() && !t().isProgram(replacement)) {
|
||||
throw new Error("You can only replace a Program root node with another Program node");
|
||||
}
|
||||
|
||||
if (Array.isArray(replacement)) {
|
||||
throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`");
|
||||
}
|
||||
|
||||
if (typeof replacement === "string") {
|
||||
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
|
||||
}
|
||||
|
||||
var nodePath = "";
|
||||
|
||||
if (this.isNodeType("Statement") && t().isExpression(replacement)) {
|
||||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) {
|
||||
replacement = t().expressionStatement(replacement);
|
||||
nodePath = "expression";
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isNodeType("Expression") && t().isStatement(replacement)) {
|
||||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
|
||||
return this.replaceExpressionWithStatements([replacement]);
|
||||
}
|
||||
}
|
||||
|
||||
var oldNode = this.node;
|
||||
|
||||
if (oldNode) {
|
||||
t().inheritsComments(replacement, oldNode);
|
||||
t().removeComments(oldNode);
|
||||
}
|
||||
|
||||
this._replaceWith(replacement);
|
||||
|
||||
this.type = replacement.type;
|
||||
this.setScope();
|
||||
this.requeue();
|
||||
return [nodePath ? this.get(nodePath) : this];
|
||||
}
|
||||
|
||||
function _replaceWith(node) {
|
||||
if (!this.container) {
|
||||
throw new ReferenceError("Container is falsy");
|
||||
}
|
||||
|
||||
if (this.inList) {
|
||||
t().validate(this.parent, this.key, [node]);
|
||||
} else {
|
||||
t().validate(this.parent, this.key, node);
|
||||
}
|
||||
|
||||
this.debug("Replace with " + (node && node.type));
|
||||
this.node = this.container[this.key] = node;
|
||||
}
|
||||
|
||||
function replaceExpressionWithStatements(nodes) {
|
||||
this.resync();
|
||||
var toSequenceExpression = t().toSequenceExpression(nodes, this.scope);
|
||||
|
||||
if (toSequenceExpression) {
|
||||
return this.replaceWith(toSequenceExpression)[0].get("expressions");
|
||||
}
|
||||
|
||||
var container = t().arrowFunctionExpression([], t().blockStatement(nodes));
|
||||
this.replaceWith(t().callExpression(container, []));
|
||||
this.traverse(hoistVariablesVisitor);
|
||||
var completionRecords = this.get("callee").getCompletionRecords();
|
||||
|
||||
for (var _iterator = completionRecords, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i2 >= _iterator.length) break;
|
||||
_ref = _iterator[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator.next();
|
||||
if (_i2.done) break;
|
||||
_ref = _i2.value;
|
||||
}
|
||||
|
||||
var path = _ref;
|
||||
if (!path.isExpressionStatement()) continue;
|
||||
var loop = path.findParent(function (path) {
|
||||
return path.isLoop();
|
||||
});
|
||||
|
||||
if (loop) {
|
||||
var uid = loop.getData("expressionReplacementReturnUid");
|
||||
|
||||
if (!uid) {
|
||||
var _callee = this.get("callee");
|
||||
|
||||
uid = _callee.scope.generateDeclaredUidIdentifier("ret");
|
||||
|
||||
_callee.get("body").pushContainer("body", t().returnStatement(t().cloneNode(uid)));
|
||||
|
||||
loop.setData("expressionReplacementReturnUid", uid);
|
||||
} else {
|
||||
uid = t().identifier(uid.name);
|
||||
}
|
||||
|
||||
path.get("expression").replaceWith(t().assignmentExpression("=", t().cloneNode(uid), path.node.expression));
|
||||
} else {
|
||||
path.replaceWith(t().returnStatement(path.node.expression));
|
||||
}
|
||||
}
|
||||
|
||||
var callee = this.get("callee");
|
||||
callee.arrowFunctionToExpression();
|
||||
return callee.get("body.body");
|
||||
}
|
||||
|
||||
function replaceInline(nodes) {
|
||||
this.resync();
|
||||
|
||||
if (Array.isArray(nodes)) {
|
||||
if (Array.isArray(this.container)) {
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
|
||||
var paths = this._containerInsertAfter(nodes);
|
||||
|
||||
this.remove();
|
||||
return paths;
|
||||
} else {
|
||||
return this.replaceWithMultiple(nodes);
|
||||
}
|
||||
} else {
|
||||
return this.replaceWith(nodes);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user