@babel/traverse
Advanced tools
Comparing version 7.0.0-beta.42 to 7.0.0-beta.43
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.clear = clear; | ||
@@ -8,5 +10,5 @@ exports.clearPath = clearPath; | ||
exports.scope = exports.path = void 0; | ||
var path = new WeakMap(); | ||
let path = new WeakMap(); | ||
exports.path = path; | ||
var scope = new WeakMap(); | ||
let scope = new WeakMap(); | ||
exports.scope = scope; | ||
@@ -13,0 +15,0 @@ |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _path4 = _interopRequireDefault(require("./path")); | ||
var _path = _interopRequireDefault(require("./path")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -14,6 +24,6 @@ | ||
var testing = process.env.NODE_ENV === "test"; | ||
const testing = process.env.NODE_ENV === "test"; | ||
var TraversalContext = function () { | ||
function TraversalContext(scope, opts, state, parentPath) { | ||
class TraversalContext { | ||
constructor(scope, opts, state, parentPath) { | ||
this.queue = null; | ||
@@ -26,32 +36,18 @@ this.parentPath = parentPath; | ||
var _proto = TraversalContext.prototype; | ||
_proto.shouldVisit = function shouldVisit(node) { | ||
var opts = this.opts; | ||
shouldVisit(node) { | ||
const opts = this.opts; | ||
if (opts.enter || opts.exit) return true; | ||
if (opts[node.type]) return true; | ||
var keys = t.VISITOR_KEYS[node.type]; | ||
const keys = t().VISITOR_KEYS[node.type]; | ||
if (!keys || !keys.length) return false; | ||
for (var _iterator = keys, _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 _key = _ref; | ||
if (node[_key]) return true; | ||
for (const key of keys) { | ||
if (node[key]) return true; | ||
} | ||
return false; | ||
}; | ||
} | ||
_proto.create = function create(node, obj, key, listKey) { | ||
return _path4.default.get({ | ||
create(node, obj, key, listKey) { | ||
return _path.default.get({ | ||
parentPath: this.parentPath, | ||
@@ -61,7 +57,7 @@ parent: node, | ||
key: key, | ||
listKey: listKey | ||
listKey | ||
}); | ||
}; | ||
} | ||
_proto.maybeQueue = function maybeQueue(path, notPriority) { | ||
maybeQueue(path, notPriority) { | ||
if (this.trap) { | ||
@@ -78,10 +74,10 @@ throw new Error("Infinite cycle detected"); | ||
} | ||
}; | ||
} | ||
_proto.visitMultiple = function visitMultiple(container, parent, listKey) { | ||
visitMultiple(container, parent, listKey) { | ||
if (container.length === 0) return false; | ||
var queue = []; | ||
const queue = []; | ||
for (var key = 0; key < container.length; key++) { | ||
var node = container[key]; | ||
for (let key = 0; key < container.length; key++) { | ||
const node = container[key]; | ||
@@ -94,5 +90,5 @@ if (node && this.shouldVisit(node)) { | ||
return this.visitQueue(queue); | ||
}; | ||
} | ||
_proto.visitSingle = function visitSingle(node, key) { | ||
visitSingle(node, key) { | ||
if (this.shouldVisit(node[key])) { | ||
@@ -103,32 +99,19 @@ return this.visitQueue([this.create(node, node, key)]); | ||
} | ||
}; | ||
} | ||
_proto.visitQueue = function visitQueue(queue) { | ||
visitQueue(queue) { | ||
this.queue = queue; | ||
this.priorityQueue = []; | ||
var visited = []; | ||
var stop = false; | ||
const visited = []; | ||
let stop = false; | ||
for (var _iterator2 = queue, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (const path of queue) { | ||
path.resync(); | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) { | ||
path.pushContext(this); | ||
} | ||
var _path2 = _ref2; | ||
if (path.key === null) continue; | ||
_path2.resync(); | ||
if (_path2.contexts.length === 0 || _path2.contexts[_path2.contexts.length - 1] !== this) { | ||
_path2.pushContext(this); | ||
} | ||
if (_path2.key === null) continue; | ||
if (testing && queue.length >= 10000) { | ||
@@ -138,6 +121,6 @@ this.trap = true; | ||
if (visited.indexOf(_path2.node) >= 0) continue; | ||
visited.push(_path2.node); | ||
if (visited.indexOf(path.node) >= 0) continue; | ||
visited.push(path.node); | ||
if (_path2.visit()) { | ||
if (path.visit()) { | ||
stop = true; | ||
@@ -155,17 +138,4 @@ break; | ||
for (var _iterator3 = queue, _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 _path3 = _ref3; | ||
_path3.popContext(); | ||
for (const path of queue) { | ||
path.popContext(); | ||
} | ||
@@ -175,6 +145,6 @@ | ||
return stop; | ||
}; | ||
} | ||
_proto.visit = function visit(node, key) { | ||
var nodes = node[key]; | ||
visit(node, key) { | ||
const nodes = node[key]; | ||
if (!nodes) return false; | ||
@@ -187,7 +157,6 @@ | ||
} | ||
}; | ||
} | ||
return TraversalContext; | ||
}(); | ||
} | ||
exports.default = TraversalContext; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var Hub = function Hub(file) { | ||
this.file = file; | ||
}; | ||
class Hub { | ||
constructor(file) { | ||
this.file = file; | ||
} | ||
} | ||
exports.default = Hub; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = traverse; | ||
exports.visitors = exports.Hub = exports.Scope = exports.NodePath = void 0; | ||
Object.defineProperty(exports, "NodePath", { | ||
enumerable: true, | ||
get: function () { | ||
return _path.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Scope", { | ||
enumerable: true, | ||
get: function () { | ||
return _scope.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Hub", { | ||
enumerable: true, | ||
get: function () { | ||
return _hub.default; | ||
} | ||
}); | ||
exports.visitors = void 0; | ||
@@ -13,6 +33,22 @@ var _context = _interopRequireDefault(require("./context")); | ||
var _includes = _interopRequireDefault(require("lodash/includes")); | ||
function _includes() { | ||
const data = _interopRequireDefault(require("lodash/includes")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
_includes = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var cache = _interopRequireWildcard(require("./cache")); | ||
@@ -22,12 +58,6 @@ | ||
exports.NodePath = _path.default; | ||
var _scope = _interopRequireDefault(require("./scope")); | ||
exports.Scope = _scope.default; | ||
var _hub = _interopRequireDefault(require("./hub")); | ||
exports.Hub = _hub.default; | ||
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; } } | ||
@@ -43,3 +73,3 @@ | ||
if (parent.type !== "Program" && parent.type !== "File") { | ||
throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + ("Instead of that you tried to traverse a " + parent.type + " node without ") + "passing scope and parentPath."); | ||
throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + `Instead of that you tried to traverse a ${parent.type} node without ` + "passing scope and parentPath."); | ||
} | ||
@@ -57,25 +87,13 @@ } | ||
traverse.cheap = function (node, enter) { | ||
return t.traverseFast(node, enter); | ||
return t().traverseFast(node, enter); | ||
}; | ||
traverse.node = function (node, opts, scope, state, parentPath, skipKeys) { | ||
var keys = t.VISITOR_KEYS[node.type]; | ||
const keys = t().VISITOR_KEYS[node.type]; | ||
if (!keys) return; | ||
var context = new _context.default(scope, opts, state, parentPath); | ||
const context = new _context.default(scope, opts, state, parentPath); | ||
for (var _iterator = keys, _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 _key = _ref; | ||
if (skipKeys && skipKeys[_key]) continue; | ||
if (context.visit(node, _key)) return; | ||
for (const key of keys) { | ||
if (skipKeys && skipKeys[key]) continue; | ||
if (context.visit(node, key)) return; | ||
} | ||
@@ -85,3 +103,3 @@ }; | ||
traverse.clearNode = function (node, opts) { | ||
t.removeProperties(node, opts); | ||
t().removeProperties(node, opts); | ||
cache.path.delete(node); | ||
@@ -91,3 +109,3 @@ }; | ||
traverse.removeProperties = function (tree, opts) { | ||
t.traverseFast(tree, traverse.clearNode, opts); | ||
t().traverseFast(tree, traverse.clearNode, opts); | ||
return tree; | ||
@@ -104,5 +122,5 @@ }; | ||
traverse.hasType = function (tree, type, blacklistTypes) { | ||
if ((0, _includes.default)(blacklistTypes, tree.type)) return false; | ||
if ((0, _includes().default)(blacklistTypes, tree.type)) return false; | ||
if (tree.type === type) return true; | ||
var state = { | ||
const state = { | ||
has: false, | ||
@@ -109,0 +127,0 @@ type: type |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.findParent = findParent; | ||
@@ -15,4 +17,12 @@ exports.find = find; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _index = _interopRequireDefault(require("./index")); | ||
@@ -25,3 +35,3 @@ | ||
function findParent(callback) { | ||
var path = this; | ||
let path = this; | ||
@@ -36,3 +46,3 @@ while (path = path.parentPath) { | ||
function find(callback) { | ||
var path = this; | ||
let path = this; | ||
@@ -47,9 +57,7 @@ do { | ||
function getFunctionParent() { | ||
return this.findParent(function (p) { | ||
return p.isFunction(); | ||
}); | ||
return this.findParent(p => p.isFunction()); | ||
} | ||
function getStatementParent() { | ||
var path = this; | ||
let path = this; | ||
@@ -73,9 +81,7 @@ do { | ||
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) { | ||
var earliest; | ||
var keys = t.VISITOR_KEYS[deepest.type]; | ||
var _arr = ancestries; | ||
let earliest; | ||
const keys = t().VISITOR_KEYS[deepest.type]; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var ancestry = _arr[_i]; | ||
var path = ancestry[i + 1]; | ||
for (const ancestry of ancestries) { | ||
const path = ancestry[i + 1]; | ||
@@ -94,4 +100,4 @@ if (!earliest) { | ||
var earliestKeyIndex = keys.indexOf(earliest.parentKey); | ||
var currentKeyIndex = keys.indexOf(path.parentKey); | ||
const earliestKeyIndex = keys.indexOf(earliest.parentKey); | ||
const currentKeyIndex = keys.indexOf(path.parentKey); | ||
@@ -108,4 +114,2 @@ if (earliestKeyIndex > currentKeyIndex) { | ||
function getDeepestCommonAncestorFrom(paths, filter) { | ||
var _this = this; | ||
if (!paths.length) { | ||
@@ -119,10 +123,10 @@ return this; | ||
var minDepth = Infinity; | ||
var lastCommonIndex, lastCommon; | ||
var ancestries = paths.map(function (path) { | ||
var ancestry = []; | ||
let minDepth = Infinity; | ||
let lastCommonIndex, lastCommon; | ||
const ancestries = paths.map(path => { | ||
const ancestry = []; | ||
do { | ||
ancestry.unshift(path); | ||
} while ((path = path.parentPath) && path !== _this); | ||
} while ((path = path.parentPath) && path !== this); | ||
@@ -135,11 +139,8 @@ if (ancestry.length < minDepth) { | ||
}); | ||
var first = ancestries[0]; | ||
const first = ancestries[0]; | ||
depthLoop: for (var i = 0; i < minDepth; i++) { | ||
var shouldMatch = first[i]; | ||
var _arr2 = ancestries; | ||
depthLoop: for (let i = 0; i < minDepth; i++) { | ||
const shouldMatch = first[i]; | ||
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | ||
var ancestry = _arr2[_i2]; | ||
for (const ancestry of ancestries) { | ||
if (ancestry[i] !== shouldMatch) { | ||
@@ -166,4 +167,4 @@ break depthLoop; | ||
function getAncestry() { | ||
var path = this; | ||
var paths = []; | ||
let path = this; | ||
const paths = []; | ||
@@ -182,15 +183,10 @@ do { | ||
function isDescendant(maybeAncestor) { | ||
return !!this.findParent(function (parent) { | ||
return parent === maybeAncestor; | ||
}); | ||
return !!this.findParent(parent => parent === maybeAncestor); | ||
} | ||
function inType() { | ||
var path = this; | ||
let path = this; | ||
while (path) { | ||
var _arr3 = arguments; | ||
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | ||
var type = _arr3[_i3]; | ||
for (const type of arguments) { | ||
if (path.node.type === type) return true; | ||
@@ -197,0 +193,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.shareCommentsWithSiblings = shareCommentsWithSiblings; | ||
@@ -8,4 +10,12 @@ exports.addComment = addComment; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -15,11 +25,11 @@ | ||
if (typeof this.key === "string") return; | ||
var node = this.node; | ||
const node = this.node; | ||
if (!node) return; | ||
var trailing = node.trailingComments; | ||
var leading = node.leadingComments; | ||
const trailing = node.trailingComments; | ||
const 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); | ||
const prev = this.getSibling(this.key - 1); | ||
const next = this.getSibling(this.key + 1); | ||
const hasPrev = Boolean(prev.node); | ||
const hasNext = Boolean(next.node); | ||
@@ -34,7 +44,7 @@ if (hasPrev && hasNext) {} else if (hasPrev) { | ||
function addComment(type, content, line) { | ||
t.addComment(this.node, type, content, line); | ||
t().addComment(this.node, type, content, line); | ||
} | ||
function addComments(type, comments) { | ||
t.addComments(this.node, type, comments); | ||
t().addComments(this.node, type, comments); | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.call = call; | ||
@@ -30,3 +32,3 @@ exports._call = _call; | ||
function call(key) { | ||
var opts = this.opts; | ||
const opts = this.opts; | ||
this.debug(key); | ||
@@ -48,27 +50,14 @@ | ||
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; | ||
for (const fn of fns) { | ||
if (!fn) continue; | ||
const node = this.node; | ||
if (!node) return true; | ||
const ret = fn.call(this.state, this, this.state); | ||
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."); | ||
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); | ||
throw new Error(`Unexpected return value from visitor method ${fn}`); | ||
} | ||
@@ -84,3 +73,3 @@ | ||
function isBlacklisted() { | ||
var blacklist = this.opts.blacklist; | ||
const blacklist = this.opts.blacklist; | ||
return blacklist && blacklist.indexOf(this.node.type) > -1; | ||
@@ -130,4 +119,4 @@ } | ||
if (this.opts && this.opts.noScope) return; | ||
var path = this.parentPath; | ||
var target; | ||
let path = this.parentPath; | ||
let target; | ||
@@ -181,3 +170,3 @@ while (path && !target) { | ||
if (Array.isArray(this.container)) { | ||
for (var i = 0; i < this.container.length; i++) { | ||
for (let i = 0; i < this.container.length; i++) { | ||
if (this.container[i] === this.node) { | ||
@@ -188,3 +177,3 @@ return this.setKey(i); | ||
} else { | ||
for (var key in this.container) { | ||
for (const key in this.container) { | ||
if (this.container[key] === this.node) { | ||
@@ -201,3 +190,3 @@ return this.setKey(key); | ||
if (!this.parent || !this.inList) return; | ||
var newContainer = this.parent[this.listKey]; | ||
const newContainer = this.parent[this.listKey]; | ||
if (this.container === newContainer) return; | ||
@@ -243,25 +232,8 @@ this.container = newContainer || null; | ||
function requeue(pathToQueue) { | ||
if (pathToQueue === void 0) { | ||
pathToQueue = this; | ||
} | ||
function requeue(pathToQueue = this) { | ||
if (pathToQueue.removed) return; | ||
var contexts = this.contexts; | ||
const 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); | ||
for (const context of contexts) { | ||
context.maybeQueue(pathToQueue); | ||
} | ||
@@ -271,4 +243,4 @@ } | ||
function _getQueueContexts() { | ||
var path = this; | ||
var contexts = this.contexts; | ||
let path = this; | ||
let contexts = this.contexts; | ||
@@ -275,0 +247,0 @@ while (!contexts.length) { |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.toComputedKey = toComputedKey; | ||
@@ -10,6 +12,22 @@ exports.ensureBlock = ensureBlock; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _helperFunctionName() { | ||
const data = _interopRequireDefault(require("@babel/helper-function-name")); | ||
_helperFunctionName = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -20,4 +38,4 @@ | ||
function toComputedKey() { | ||
var node = this.node; | ||
var key; | ||
const node = this.node; | ||
let key; | ||
@@ -33,3 +51,3 @@ if (this.isMemberExpression()) { | ||
if (!node.computed) { | ||
if (t.isIdentifier(key)) key = t.stringLiteral(key.name); | ||
if (t().isIdentifier(key)) key = t().stringLiteral(key.name); | ||
} | ||
@@ -41,4 +59,4 @@ | ||
function ensureBlock() { | ||
var body = this.get("body"); | ||
var bodyNode = body.node; | ||
const body = this.get("body"); | ||
const bodyNode = body.node; | ||
@@ -57,6 +75,6 @@ if (Array.isArray(body)) { | ||
var statements = []; | ||
var stringPath = "body"; | ||
var key; | ||
var listKey; | ||
const statements = []; | ||
let stringPath = "body"; | ||
let key; | ||
let listKey; | ||
@@ -72,11 +90,11 @@ if (body.isStatement()) { | ||
key = "argument"; | ||
statements.push(t.returnStatement(body.node)); | ||
statements.push(t().returnStatement(body.node)); | ||
} else { | ||
key = "expression"; | ||
statements.push(t.expressionStatement(body.node)); | ||
statements.push(t().expressionStatement(body.node)); | ||
} | ||
} | ||
this.node.body = t.blockStatement(statements); | ||
var parentPath = this.get(stringPath); | ||
this.node.body = t().blockStatement(statements); | ||
const parentPath = this.get(stringPath); | ||
body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key); | ||
@@ -99,9 +117,6 @@ return this.node; | ||
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; | ||
function arrowFunctionToExpression({ | ||
allowInsertArrow = true, | ||
specCompliant = false | ||
} = {}) { | ||
if (!this.isArrowFunctionExpression()) { | ||
@@ -111,3 +126,3 @@ throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression."); | ||
var thisBinding = hoistFunctionEnvironment(this, specCompliant, allowInsertArrow); | ||
const thisBinding = hoistFunctionEnvironment(this, specCompliant, allowInsertArrow); | ||
this.ensureBlock(); | ||
@@ -117,3 +132,3 @@ this.node.type = "FunctionExpression"; | ||
if (specCompliant) { | ||
var checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId"); | ||
const checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId"); | ||
@@ -123,27 +138,17 @@ if (checkBinding) { | ||
id: checkBinding, | ||
init: t.objectExpression([]) | ||
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()])); | ||
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; | ||
} | ||
function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArrow = true) { | ||
const thisEnvFn = fnPath.findParent(p => p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({ | ||
static: false | ||
})); | ||
const inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor"; | ||
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()) { | ||
@@ -153,8 +158,9 @@ 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; | ||
const { | ||
thisPaths, | ||
argumentsPaths, | ||
newTargetPaths, | ||
superProps, | ||
superCalls | ||
} = getScopeInformation(fnPath); | ||
@@ -166,20 +172,23 @@ if (inConstructor && superCalls.length > 0) { | ||
var allSuperCalls = []; | ||
const allSuperCalls = []; | ||
thisEnvFn.traverse({ | ||
Function: function Function(child) { | ||
Function(child) { | ||
if (child.isArrowFunctionExpression()) return; | ||
child.skip(); | ||
}, | ||
ClassProperty: function ClassProperty(child) { | ||
ClassProperty(child) { | ||
if (child.node.static) return; | ||
child.skip(); | ||
}, | ||
CallExpression: function CallExpression(child) { | ||
CallExpression(child) { | ||
if (!child.get("callee").isSuper()) return; | ||
allSuperCalls.push(child); | ||
} | ||
}); | ||
var superBinding = getSuperBinding(thisEnvFn); | ||
allSuperCalls.forEach(function (superCall) { | ||
var callee = t.identifier(superBinding); | ||
const superBinding = getSuperBinding(thisEnvFn); | ||
allSuperCalls.forEach(superCall => { | ||
const callee = t().identifier(superBinding); | ||
callee.loc = superCall.node.callee.loc; | ||
@@ -190,3 +199,3 @@ superCall.get("callee").replaceWith(callee); | ||
var thisBinding; | ||
let thisBinding; | ||
@@ -197,4 +206,4 @@ if (thisPaths.length > 0 || specCompliant) { | ||
if (!specCompliant || inConstructor && hasSuperClass(thisEnvFn)) { | ||
thisPaths.forEach(function (thisChild) { | ||
var thisRef = thisChild.isJSX() ? t.jsxIdentifier(thisBinding) : t.identifier(thisBinding); | ||
thisPaths.forEach(thisChild => { | ||
const thisRef = thisChild.isJSX() ? t().jsxIdentifier(thisBinding) : t().identifier(thisBinding); | ||
thisRef.loc = thisChild.node.loc; | ||
@@ -208,7 +217,5 @@ thisChild.replaceWith(thisRef); | ||
if (argumentsPaths.length > 0) { | ||
var argumentsBinding = getBinding(thisEnvFn, "arguments", function () { | ||
return t.identifier("arguments"); | ||
}); | ||
argumentsPaths.forEach(function (argumentsChild) { | ||
var argsRef = t.identifier(argumentsBinding); | ||
const argumentsBinding = getBinding(thisEnvFn, "arguments", () => t().identifier("arguments")); | ||
argumentsPaths.forEach(argumentsChild => { | ||
const argsRef = t().identifier(argumentsBinding); | ||
argsRef.loc = argumentsChild.node.loc; | ||
@@ -220,7 +227,5 @@ 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); | ||
const newTargetBinding = getBinding(thisEnvFn, "newtarget", () => t().metaProperty(t().identifier("new"), t().identifier("target"))); | ||
newTargetPaths.forEach(targetChild => { | ||
const targetRef = t().identifier(newTargetBinding); | ||
targetRef.loc = targetChild.node.loc; | ||
@@ -236,7 +241,5 @@ targetChild.replaceWith(targetRef); | ||
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; | ||
const flatSuperProps = superProps.reduce((acc, superProp) => acc.concat(standardizeSuperProperty(superProp)), []); | ||
flatSuperProps.forEach(superProp => { | ||
const key = superProp.node.computed ? "" : superProp.get("property").node.name; | ||
@@ -246,20 +249,18 @@ if (superProp.parentPath.isCallExpression({ | ||
})) { | ||
var _superBinding = getSuperPropCallBinding(thisEnvFn, key); | ||
const superBinding = getSuperPropCallBinding(thisEnvFn, key); | ||
if (superProp.node.computed) { | ||
var prop = superProp.get("property").node; | ||
superProp.replaceWith(t.identifier(_superBinding)); | ||
const prop = superProp.get("property").node; | ||
superProp.replaceWith(t().identifier(superBinding)); | ||
superProp.parentPath.node.arguments.unshift(prop); | ||
} else { | ||
superProp.replaceWith(t.identifier(_superBinding)); | ||
superProp.replaceWith(t().identifier(superBinding)); | ||
} | ||
} else { | ||
var isAssignment = superProp.parentPath.isAssignmentExpression({ | ||
const isAssignment = superProp.parentPath.isAssignmentExpression({ | ||
left: superProp.node | ||
}); | ||
const superBinding = getSuperPropBinding(thisEnvFn, isAssignment, key); | ||
const args = []; | ||
var _superBinding2 = getSuperPropBinding(thisEnvFn, isAssignment, key); | ||
var args = []; | ||
if (superProp.node.computed) { | ||
@@ -270,7 +271,7 @@ args.push(superProp.get("property").node); | ||
if (isAssignment) { | ||
var value = superProp.parentPath.node.right; | ||
const value = superProp.parentPath.node.right; | ||
args.push(value); | ||
superProp.parentPath.replaceWith(t.callExpression(t.identifier(_superBinding2), args)); | ||
superProp.parentPath.replaceWith(t().callExpression(t().identifier(superBinding), args)); | ||
} else { | ||
superProp.replaceWith(t.callExpression(t.identifier(_superBinding2), args)); | ||
superProp.replaceWith(t().callExpression(t().identifier(superBinding), args)); | ||
} | ||
@@ -286,14 +287,14 @@ } | ||
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; | ||
const assignmentPath = superProp.parentPath; | ||
const op = assignmentPath.node.operator.slice(0, -1); | ||
const 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)); | ||
const 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)); | ||
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)); | ||
} | ||
@@ -303,16 +304,14 @@ | ||
} else if (superProp.parentPath.isUpdateExpression()) { | ||
var updateExpr = superProp.parentPath; | ||
const updateExpr = superProp.parentPath; | ||
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp"); | ||
const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null; | ||
const 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)))]; | ||
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)); | ||
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"); | ||
updateExpr.replaceWith(t().sequenceExpression(parts)); | ||
const left = updateExpr.get("expressions.0.right"); | ||
const right = updateExpr.get("expressions.1.left"); | ||
return [left, right]; | ||
@@ -329,20 +328,23 @@ } | ||
function getThisBinding(thisEnvFn, inConstructor) { | ||
return getBinding(thisEnvFn, "this", function (thisBinding) { | ||
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t.thisExpression(); | ||
var supers = new WeakSet(); | ||
return getBinding(thisEnvFn, "this", thisBinding => { | ||
if (!inConstructor || !hasSuperClass(thisEnvFn)) return t().thisExpression(); | ||
const supers = new WeakSet(); | ||
thisEnvFn.traverse({ | ||
Function: function Function(child) { | ||
Function(child) { | ||
if (child.isArrowFunctionExpression()) return; | ||
child.skip(); | ||
}, | ||
ClassProperty: function ClassProperty(child) { | ||
ClassProperty(child) { | ||
if (child.node.static) return; | ||
child.skip(); | ||
}, | ||
CallExpression: function CallExpression(child) { | ||
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)); | ||
child.replaceWith(t().assignmentExpression("=", t().identifier(thisBinding), child.node)); | ||
} | ||
}); | ||
@@ -353,5 +355,5 @@ }); | ||
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))])); | ||
return getBinding(thisEnvFn, "supercall", () => { | ||
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args"); | ||
return t().arrowFunctionExpression([t().restElement(argsBinding)], t().callExpression(t().super(), [t().spreadElement(t().identifier(argsBinding.name))])); | ||
}); | ||
@@ -361,16 +363,16 @@ } | ||
function getSuperPropCallBinding(thisEnvFn, propName) { | ||
return getBinding(thisEnvFn, "superprop_call:" + (propName || ""), function () { | ||
var argsBinding = thisEnvFn.scope.generateUidIdentifier("args"); | ||
var argsList = [t.restElement(argsBinding)]; | ||
var fnBody; | ||
return getBinding(thisEnvFn, `superprop_call:${propName || ""}`, () => { | ||
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args"); | ||
const argsList = [t().restElement(argsBinding)]; | ||
let fnBody; | ||
if (propName) { | ||
fnBody = t.callExpression(t.memberExpression(t.super(), t.identifier(propName)), [t.spreadElement(t.identifier(argsBinding.name))]); | ||
fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(propName)), [t().spreadElement(t().identifier(argsBinding.name))]); | ||
} else { | ||
var method = thisEnvFn.scope.generateUidIdentifier("prop"); | ||
const 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))]); | ||
fnBody = t().callExpression(t().memberExpression(t().super(), t().identifier(method.name), true), [t().spreadElement(t().identifier(argsBinding.name))]); | ||
} | ||
return t.arrowFunctionExpression(argsList, fnBody); | ||
return t().arrowFunctionExpression(argsList, fnBody); | ||
}); | ||
@@ -380,22 +382,22 @@ } | ||
function getSuperPropBinding(thisEnvFn, isAssignment, propName) { | ||
var op = isAssignment ? "set" : "get"; | ||
return getBinding(thisEnvFn, "superprop_" + op + ":" + (propName || ""), function () { | ||
var argsList = []; | ||
var fnBody; | ||
const op = isAssignment ? "set" : "get"; | ||
return getBinding(thisEnvFn, `superprop_${op}:${propName || ""}`, () => { | ||
const argsList = []; | ||
let fnBody; | ||
if (propName) { | ||
fnBody = t.memberExpression(t.super(), t.identifier(propName)); | ||
fnBody = t().memberExpression(t().super(), t().identifier(propName)); | ||
} else { | ||
var method = thisEnvFn.scope.generateUidIdentifier("prop"); | ||
const method = thisEnvFn.scope.generateUidIdentifier("prop"); | ||
argsList.unshift(method); | ||
fnBody = t.memberExpression(t.super(), t.identifier(method.name), true); | ||
fnBody = t().memberExpression(t().super(), t().identifier(method.name), true); | ||
} | ||
if (isAssignment) { | ||
var valueIdent = thisEnvFn.scope.generateUidIdentifier("value"); | ||
const valueIdent = thisEnvFn.scope.generateUidIdentifier("value"); | ||
argsList.push(valueIdent); | ||
fnBody = t.assignmentExpression("=", fnBody, t.identifier(valueIdent.name)); | ||
fnBody = t().assignmentExpression("=", fnBody, t().identifier(valueIdent.name)); | ||
} | ||
return t.arrowFunctionExpression(argsList, fnBody); | ||
return t().arrowFunctionExpression(argsList, fnBody); | ||
}); | ||
@@ -405,7 +407,7 @@ } | ||
function getBinding(thisEnvFn, key, init) { | ||
var cacheKey = "binding:" + key; | ||
var data = thisEnvFn.getData(cacheKey); | ||
const cacheKey = "binding:" + key; | ||
let data = thisEnvFn.getData(cacheKey); | ||
if (!data) { | ||
var id = thisEnvFn.scope.generateUidIdentifier(key); | ||
const id = thisEnvFn.scope.generateUidIdentifier(key); | ||
data = id.name; | ||
@@ -423,20 +425,23 @@ thisEnvFn.setData(cacheKey, data); | ||
function getScopeInformation(fnPath) { | ||
var thisPaths = []; | ||
var argumentsPaths = []; | ||
var newTargetPaths = []; | ||
var superProps = []; | ||
var superCalls = []; | ||
const thisPaths = []; | ||
const argumentsPaths = []; | ||
const newTargetPaths = []; | ||
const superProps = []; | ||
const superCalls = []; | ||
fnPath.traverse({ | ||
ClassProperty: function ClassProperty(child) { | ||
ClassProperty(child) { | ||
if (child.node.static) return; | ||
child.skip(); | ||
}, | ||
Function: function Function(child) { | ||
Function(child) { | ||
if (child.isArrowFunctionExpression()) return; | ||
child.skip(); | ||
}, | ||
ThisExpression: function ThisExpression(child) { | ||
ThisExpression(child) { | ||
thisPaths.push(child); | ||
}, | ||
JSXIdentifier: function JSXIdentifier(child) { | ||
JSXIdentifier(child) { | ||
if (child.node.name !== "this") return; | ||
@@ -454,13 +459,17 @@ | ||
}, | ||
CallExpression: function CallExpression(child) { | ||
CallExpression(child) { | ||
if (child.get("callee").isSuper()) superCalls.push(child); | ||
}, | ||
MemberExpression: function MemberExpression(child) { | ||
MemberExpression(child) { | ||
if (child.get("object").isSuper()) superProps.push(child); | ||
}, | ||
ReferencedIdentifier: function ReferencedIdentifier(child) { | ||
ReferencedIdentifier(child) { | ||
if (child.node.name !== "arguments") return; | ||
argumentsPaths.push(child); | ||
}, | ||
MetaProperty: function MetaProperty(child) { | ||
MetaProperty(child) { | ||
if (!child.get("meta").isIdentifier({ | ||
@@ -474,10 +483,11 @@ name: "new" | ||
} | ||
}); | ||
return { | ||
thisPaths: thisPaths, | ||
argumentsPaths: argumentsPaths, | ||
newTargetPaths: newTargetPaths, | ||
superProps: superProps, | ||
superCalls: superCalls | ||
thisPaths, | ||
argumentsPaths, | ||
newTargetPaths, | ||
superProps, | ||
superCalls | ||
}; | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.evaluateTruthy = evaluateTruthy; | ||
exports.evaluate = evaluate; | ||
var VALID_CALLEES = ["String", "Number", "Math"]; | ||
var INVALID_METHODS = ["random"]; | ||
const VALID_CALLEES = ["String", "Number", "Math"]; | ||
const INVALID_METHODS = ["random"]; | ||
function evaluateTruthy() { | ||
var res = this.evaluate(); | ||
const res = this.evaluate(); | ||
if (res.confident) return !!res.value; | ||
@@ -21,7 +23,11 @@ } | ||
function evaluateCached(path, state) { | ||
var node = path.node; | ||
var seen = state.seen; | ||
const { | ||
node | ||
} = path; | ||
const { | ||
seen | ||
} = state; | ||
if (seen.has(node)) { | ||
var existing = seen.get(node); | ||
const existing = seen.get(node); | ||
@@ -35,3 +41,3 @@ if (existing.resolved) { | ||
} else { | ||
var item = { | ||
const item = { | ||
resolved: false | ||
@@ -41,3 +47,3 @@ }; | ||
var val = _evaluate(path, state); | ||
const val = _evaluate(path, state); | ||
@@ -55,6 +61,8 @@ if (state.confident) { | ||
if (!state.confident) return; | ||
var node = path.node; | ||
const { | ||
node | ||
} = path; | ||
if (path.isSequenceExpression()) { | ||
var exprs = path.get("expressions"); | ||
const exprs = path.get("expressions"); | ||
return evaluateCached(exprs[exprs.length - 1], state); | ||
@@ -76,5 +84,9 @@ } | ||
if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) { | ||
var object = path.get("tag.object"); | ||
var name = object.node.name; | ||
var property = path.get("tag.property"); | ||
const object = path.get("tag.object"); | ||
const { | ||
node: { | ||
name | ||
} | ||
} = object; | ||
const property = path.get("tag.property"); | ||
@@ -87,3 +99,3 @@ if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name, true) && property.isIdentifier && property.node.name === "raw") { | ||
if (path.isConditionalExpression()) { | ||
var testResult = evaluateCached(path.get("test"), state); | ||
const testResult = evaluateCached(path.get("test"), state); | ||
if (!state.confident) return; | ||
@@ -105,12 +117,11 @@ | ||
})) { | ||
var _property = path.get("property"); | ||
const property = path.get("property"); | ||
const object = path.get("object"); | ||
var _object = path.get("object"); | ||
if (object.isLiteral() && property.isIdentifier()) { | ||
const value = object.node.value; | ||
const type = typeof value; | ||
if (_object.isLiteral() && _property.isIdentifier()) { | ||
var value = _object.node.value; | ||
var type = typeof value; | ||
if (type === "number" || type === "string") { | ||
return value[_property.node.name]; | ||
return value[property.node.name]; | ||
} | ||
@@ -121,3 +132,3 @@ } | ||
if (path.isReferencedIdentifier()) { | ||
var binding = path.scope.getBinding(node.name); | ||
const binding = path.scope.getBinding(node.name); | ||
@@ -143,3 +154,3 @@ if (binding && binding.constantViolations.length > 0) { | ||
var resolved = path.resolve(); | ||
const resolved = path.resolve(); | ||
@@ -161,3 +172,3 @@ if (resolved === path) { | ||
var argument = path.get("argument"); | ||
const argument = path.get("argument"); | ||
@@ -168,3 +179,3 @@ if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) { | ||
var arg = evaluateCached(argument, state); | ||
const arg = evaluateCached(argument, state); | ||
if (!state.confident) return; | ||
@@ -191,25 +202,12 @@ | ||
if (path.isArrayExpression()) { | ||
var arr = []; | ||
var elems = path.get("elements"); | ||
const arr = []; | ||
const elems = path.get("elements"); | ||
for (var _iterator = elems, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
for (const elem of elems) { | ||
const elemValue = elem.evaluate(); | ||
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 deopt(elem, state); | ||
} | ||
@@ -222,28 +220,14 @@ } | ||
if (path.isObjectExpression()) { | ||
var obj = {}; | ||
var props = path.get("properties"); | ||
const obj = {}; | ||
const 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; | ||
for (const prop of props) { | ||
if (prop.isObjectMethod() || prop.isSpreadElement()) { | ||
return deopt(prop, state); | ||
} | ||
var _prop = _ref2; | ||
const keyPath = prop.get("key"); | ||
let key = keyPath; | ||
if (_prop.isObjectMethod() || _prop.isSpreadElement()) { | ||
return deopt(_prop, state); | ||
} | ||
var keyPath = _prop.get("key"); | ||
var key = keyPath; | ||
if (_prop.node.computed) { | ||
if (prop.node.computed) { | ||
key = key.evaluate(); | ||
@@ -262,12 +246,11 @@ | ||
var valuePath = _prop.get("value"); | ||
const valuePath = prop.get("value"); | ||
let value = valuePath.evaluate(); | ||
var _value2 = valuePath.evaluate(); | ||
if (!_value2.confident) { | ||
if (!value.confident) { | ||
return deopt(valuePath, state); | ||
} | ||
_value2 = _value2.value; | ||
obj[key] = _value2; | ||
value = value.value; | ||
obj[key] = value; | ||
} | ||
@@ -279,8 +262,8 @@ | ||
if (path.isLogicalExpression()) { | ||
var wasConfident = state.confident; | ||
var left = evaluateCached(path.get("left"), state); | ||
var leftConfident = state.confident; | ||
const wasConfident = state.confident; | ||
const left = evaluateCached(path.get("left"), state); | ||
const leftConfident = state.confident; | ||
state.confident = wasConfident; | ||
var right = evaluateCached(path.get("right"), state); | ||
var rightConfident = state.confident; | ||
const right = evaluateCached(path.get("right"), state); | ||
const rightConfident = state.confident; | ||
state.confident = leftConfident && rightConfident; | ||
@@ -309,8 +292,5 @@ | ||
if (path.isBinaryExpression()) { | ||
var _left = evaluateCached(path.get("left"), state); | ||
const left = evaluateCached(path.get("left"), state); | ||
if (!state.confident) return; | ||
var _right = evaluateCached(path.get("right"), state); | ||
const right = evaluateCached(path.get("right"), state); | ||
if (!state.confident) return; | ||
@@ -320,60 +300,60 @@ | ||
case "-": | ||
return _left - _right; | ||
return left - right; | ||
case "+": | ||
return _left + _right; | ||
return left + right; | ||
case "/": | ||
return _left / _right; | ||
return left / right; | ||
case "*": | ||
return _left * _right; | ||
return left * right; | ||
case "%": | ||
return _left % _right; | ||
return left % right; | ||
case "**": | ||
return Math.pow(_left, _right); | ||
return left ** right; | ||
case "<": | ||
return _left < _right; | ||
return left < right; | ||
case ">": | ||
return _left > _right; | ||
return left > right; | ||
case "<=": | ||
return _left <= _right; | ||
return left <= right; | ||
case ">=": | ||
return _left >= _right; | ||
return left >= right; | ||
case "==": | ||
return _left == _right; | ||
return left == right; | ||
case "!=": | ||
return _left != _right; | ||
return left != right; | ||
case "===": | ||
return _left === _right; | ||
return left === right; | ||
case "!==": | ||
return _left !== _right; | ||
return left !== right; | ||
case "|": | ||
return _left | _right; | ||
return left | right; | ||
case "&": | ||
return _left & _right; | ||
return left & right; | ||
case "^": | ||
return _left ^ _right; | ||
return left ^ right; | ||
case "<<": | ||
return _left << _right; | ||
return left << right; | ||
case ">>": | ||
return _left >> _right; | ||
return left >> right; | ||
case ">>>": | ||
return _left >>> _right; | ||
return left >>> right; | ||
} | ||
@@ -383,5 +363,5 @@ } | ||
if (path.isCallExpression()) { | ||
var callee = path.get("callee"); | ||
var context; | ||
var func; | ||
const callee = path.get("callee"); | ||
let context; | ||
let func; | ||
@@ -393,17 +373,16 @@ if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) { | ||
if (callee.isMemberExpression()) { | ||
var _object2 = callee.get("object"); | ||
const object = callee.get("object"); | ||
const property = callee.get("property"); | ||
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 (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) { | ||
context = global[object.node.name]; | ||
func = context[property.node.name]; | ||
} | ||
if (_object2.isLiteral() && _property2.isIdentifier()) { | ||
var _type = typeof _object2.node.value; | ||
if (object.isLiteral() && property.isIdentifier()) { | ||
const type = typeof object.node.value; | ||
if (_type === "string" || _type === "number") { | ||
context = _object2.node.value; | ||
func = context[_property2.node.name]; | ||
if (type === "string" || type === "number") { | ||
context = object.node.value; | ||
func = context[property.node.name]; | ||
} | ||
@@ -414,5 +393,3 @@ } | ||
if (func) { | ||
var args = path.get("arguments").map(function (arg) { | ||
return evaluateCached(arg, state); | ||
}); | ||
const args = path.get("arguments").map(arg => evaluateCached(arg, state)); | ||
if (!state.confident) return; | ||
@@ -426,27 +403,11 @@ return func.apply(context, args); | ||
function evaluateQuasis(path, quasis, state, raw) { | ||
if (raw === void 0) { | ||
raw = false; | ||
} | ||
function evaluateQuasis(path, quasis, state, raw = false) { | ||
let str = ""; | ||
let i = 0; | ||
const exprs = path.get("expressions"); | ||
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 _elem2 = _ref3; | ||
for (const elem of quasis) { | ||
if (!state.confident) break; | ||
str += raw ? _elem2.value.raw : _elem2.value.cooked; | ||
var expr = exprs[i++]; | ||
str += raw ? elem.value.raw : elem.value.cooked; | ||
const expr = exprs[i++]; | ||
if (expr) str += String(evaluateCached(expr, state)); | ||
@@ -460,3 +421,3 @@ } | ||
function evaluate() { | ||
var state = { | ||
const state = { | ||
confident: true, | ||
@@ -466,3 +427,3 @@ deoptPath: null, | ||
}; | ||
var value = evaluateCached(this, state); | ||
let value = evaluateCached(this, state); | ||
if (!state.confident) value = undefined; | ||
@@ -469,0 +430,0 @@ return { |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getOpposite = getOpposite; | ||
@@ -21,4 +23,12 @@ exports.getCompletionRecords = getCompletionRecords; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -42,3 +52,3 @@ | ||
function getCompletionRecords() { | ||
var paths = []; | ||
let paths = []; | ||
@@ -86,5 +96,5 @@ if (this.isIfStatement()) { | ||
function getAllNextSiblings() { | ||
var _key = this.key; | ||
var sibling = this.getSibling(++_key); | ||
var siblings = []; | ||
let _key = this.key; | ||
let sibling = this.getSibling(++_key); | ||
const siblings = []; | ||
@@ -100,5 +110,5 @@ while (sibling.node) { | ||
function getAllPrevSiblings() { | ||
var _key = this.key; | ||
var sibling = this.getSibling(--_key); | ||
var siblings = []; | ||
let _key = this.key; | ||
let sibling = this.getSibling(--_key); | ||
const siblings = []; | ||
@@ -115,3 +125,3 @@ while (sibling.node) { | ||
if (context === true) context = this.context; | ||
var parts = key.split("."); | ||
const parts = key.split("."); | ||
@@ -126,12 +136,10 @@ if (parts.length === 1) { | ||
function _getKey(key, context) { | ||
var _this = this; | ||
const node = this.node; | ||
const container = node[key]; | ||
var node = this.node; | ||
var container = node[key]; | ||
if (Array.isArray(container)) { | ||
return container.map(function (_, i) { | ||
return container.map((_, i) => { | ||
return _index.default.get({ | ||
listKey: key, | ||
parentPath: _this, | ||
parentPath: this, | ||
parent: node, | ||
@@ -153,8 +161,5 @@ container: container, | ||
function _getPattern(parts, context) { | ||
var path = this; | ||
var _arr = parts; | ||
let path = this; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var part = _arr[_i]; | ||
for (const part of parts) { | ||
if (part === ".") { | ||
@@ -175,31 +180,23 @@ path = path.parentPath; | ||
function getBindingIdentifiers(duplicates) { | ||
return t.getBindingIdentifiers(this.node, duplicates); | ||
return t().getBindingIdentifiers(this.node, duplicates); | ||
} | ||
function getOuterBindingIdentifiers(duplicates) { | ||
return t.getOuterBindingIdentifiers(this.node, duplicates); | ||
return t().getOuterBindingIdentifiers(this.node, duplicates); | ||
} | ||
function getBindingIdentifierPaths(duplicates, outerOnly) { | ||
if (duplicates === void 0) { | ||
duplicates = false; | ||
} | ||
function getBindingIdentifierPaths(duplicates = false, outerOnly = false) { | ||
const path = this; | ||
let search = [].concat(path); | ||
const ids = Object.create(null); | ||
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(); | ||
const id = search.shift(); | ||
if (!id) continue; | ||
if (!id.node) continue; | ||
var keys = t.getBindingIdentifiers.keys[id.node.type]; | ||
const keys = t().getBindingIdentifiers.keys[id.node.type]; | ||
if (id.isIdentifier()) { | ||
if (duplicates) { | ||
var _ids = ids[id.node.name] = ids[id.node.name] || []; | ||
const _ids = ids[id.node.name] = ids[id.node.name] || []; | ||
@@ -215,3 +212,3 @@ _ids.push(id); | ||
if (id.isExportDeclaration()) { | ||
var declaration = id.get("declaration"); | ||
const declaration = id.get("declaration"); | ||
@@ -237,5 +234,5 @@ if (declaration.isDeclaration()) { | ||
if (keys) { | ||
for (var i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
var child = id.get(key); | ||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
const child = id.get(key); | ||
@@ -242,0 +239,0 @@ if (Array.isArray(child) || child.node) { |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
@@ -8,6 +10,22 @@ | ||
var _debug2 = _interopRequireDefault(require("debug")); | ||
function _debug() { | ||
const data = _interopRequireDefault(require("debug")); | ||
var _invariant = _interopRequireDefault(require("invariant")); | ||
_debug = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _invariant() { | ||
const data = _interopRequireDefault(require("invariant")); | ||
_invariant = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _index = _interopRequireDefault(require("../index")); | ||
@@ -17,8 +35,24 @@ | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _cache = require("../cache"); | ||
var _generator = _interopRequireDefault(require("@babel/generator")); | ||
function _generator() { | ||
const data = _interopRequireDefault(require("@babel/generator")); | ||
_generator = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var NodePath_ancestry = _interopRequireWildcard(require("./ancestry")); | ||
@@ -50,6 +84,6 @@ | ||
var _debug = (0, _debug2.default)("babel"); | ||
const debug = (0, _debug().default)("babel"); | ||
var NodePath = function () { | ||
function NodePath(hub, parent) { | ||
class NodePath { | ||
constructor(hub, parent) { | ||
this.parent = parent; | ||
@@ -78,10 +112,10 @@ this.hub = hub; | ||
NodePath.get = function get(_ref) { | ||
var hub = _ref.hub, | ||
parentPath = _ref.parentPath, | ||
parent = _ref.parent, | ||
container = _ref.container, | ||
listKey = _ref.listKey, | ||
key = _ref.key; | ||
static get({ | ||
hub, | ||
parentPath, | ||
parent, | ||
container, | ||
listKey, | ||
key | ||
}) { | ||
if (!hub && parentPath) { | ||
@@ -91,5 +125,5 @@ 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) || []; | ||
(0, _invariant().default)(parent, "To get a node path the parent needs to exist"); | ||
const targetNode = container[key]; | ||
const paths = _cache.path.get(parent) || []; | ||
@@ -100,6 +134,6 @@ if (!_cache.path.has(parent)) { | ||
var path; | ||
let path; | ||
for (var i = 0; i < paths.length; i++) { | ||
var pathCheck = paths[i]; | ||
for (let i = 0; i < paths.length; i++) { | ||
const pathCheck = paths[i]; | ||
@@ -119,44 +153,38 @@ if (pathCheck.node === targetNode) { | ||
return path; | ||
}; | ||
} | ||
var _proto = NodePath.prototype; | ||
_proto.getScope = function getScope(scope) { | ||
getScope(scope) { | ||
return this.isScope() ? new _scope.default(this) : scope; | ||
}; | ||
} | ||
_proto.setData = function setData(key, val) { | ||
setData(key, val) { | ||
return this.data[key] = val; | ||
}; | ||
} | ||
_proto.getData = function getData(key, def) { | ||
var val = this.data[key]; | ||
getData(key, def) { | ||
let 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; | ||
} | ||
buildCodeFrameError(msg, Error = SyntaxError) { | ||
return this.hub.file.buildCodeFrameError(this.node, msg, Error); | ||
}; | ||
} | ||
_proto.traverse = function traverse(visitor, state) { | ||
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); | ||
set(key, node) { | ||
t().validate(this.node, key, node); | ||
this.node[key] = node; | ||
}; | ||
} | ||
_proto.getPathLocation = function getPathLocation() { | ||
var parts = []; | ||
var path = this; | ||
getPathLocation() { | ||
const parts = []; | ||
let path = this; | ||
do { | ||
var key = path.key; | ||
if (path.inList) key = path.listKey + "[" + key + "]"; | ||
let key = path.key; | ||
if (path.inList) key = `${path.listKey}[${key}]`; | ||
parts.unshift(key); | ||
@@ -166,56 +194,40 @@ } while (path = path.parentPath); | ||
return parts.join("."); | ||
}; | ||
} | ||
_proto.debug = function debug(message) { | ||
if (!_debug.enabled) return; | ||
debug(message) { | ||
if (!debug.enabled) return; | ||
debug(`${this.getPathLocation()} ${this.type}: ${message}`); | ||
} | ||
_debug(this.getPathLocation() + " " + this.type + ": " + message); | ||
}; | ||
toString() { | ||
return (0, _generator().default)(this.node).code; | ||
} | ||
_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 _loop = function _loop(type) { | ||
var typeKey = "is" + type; | ||
for (const type of t().TYPES) { | ||
const typeKey = `is${type}`; | ||
NodePath.prototype[typeKey] = function (opts) { | ||
return t[typeKey](this.node, opts); | ||
return t()[typeKey](this.node, opts); | ||
}; | ||
NodePath.prototype["assert" + type] = function (opts) { | ||
NodePath.prototype[`assert${type}`] = function (opts) { | ||
if (!this[typeKey](opts)) { | ||
throw new TypeError("Expected node path of type " + type); | ||
throw new TypeError(`Expected node path of type ${type}`); | ||
} | ||
}; | ||
}; | ||
var _arr = t.TYPES; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var type = _arr[_i]; | ||
_loop(type); | ||
} | ||
var _loop2 = function _loop2(type) { | ||
if (type[0] === "_") return "continue"; | ||
if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type); | ||
var virtualType = virtualTypes[type]; | ||
for (const type in virtualTypes) { | ||
if (type[0] === "_") continue; | ||
if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type); | ||
const virtualType = virtualTypes[type]; | ||
NodePath.prototype["is" + type] = function (opts) { | ||
NodePath.prototype[`is${type}`] = function (opts) { | ||
return virtualType.checkPath(this, opts); | ||
}; | ||
}; | ||
for (var type in virtualTypes) { | ||
var _ret = _loop2(type); | ||
if (_ret === "continue") continue; | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.getTypeAnnotation = getTypeAnnotation; | ||
@@ -13,4 +15,12 @@ exports._getTypeAnnotation = _getTypeAnnotation; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -20,4 +30,4 @@ | ||
if (this.typeAnnotation) return this.typeAnnotation; | ||
var type = this._getTypeAnnotation() || t.anyTypeAnnotation(); | ||
if (t.isTypeAnnotation(type)) type = type.typeAnnotation; | ||
let type = this._getTypeAnnotation() || t().anyTypeAnnotation(); | ||
if (t().isTypeAnnotation(type)) type = type.typeAnnotation; | ||
return this.typeAnnotation = type; | ||
@@ -27,18 +37,18 @@ } | ||
function _getTypeAnnotation() { | ||
var node = this.node; | ||
const node = this.node; | ||
if (!node) { | ||
if (this.key === "init" && this.parentPath.isVariableDeclarator()) { | ||
var declar = this.parentPath.parentPath; | ||
var declarParent = declar.parentPath; | ||
const declar = this.parentPath.parentPath; | ||
const declarParent = declar.parentPath; | ||
if (declar.key === "left" && declarParent.isForInStatement()) { | ||
return t.stringTypeAnnotation(); | ||
return t().stringTypeAnnotation(); | ||
} | ||
if (declar.key === "left" && declarParent.isForOfStatement()) { | ||
return t.anyTypeAnnotation(); | ||
return t().anyTypeAnnotation(); | ||
} | ||
return t.voidTypeAnnotation(); | ||
return t().voidTypeAnnotation(); | ||
} else { | ||
@@ -53,3 +63,3 @@ return; | ||
var inferer = inferers[node.type]; | ||
let inferer = inferers[node.type]; | ||
@@ -73,15 +83,15 @@ if (inferer) { | ||
if (baseName === "string") { | ||
return t.isStringTypeAnnotation(type); | ||
return t().isStringTypeAnnotation(type); | ||
} else if (baseName === "number") { | ||
return t.isNumberTypeAnnotation(type); | ||
return t().isNumberTypeAnnotation(type); | ||
} else if (baseName === "boolean") { | ||
return t.isBooleanTypeAnnotation(type); | ||
return t().isBooleanTypeAnnotation(type); | ||
} else if (baseName === "any") { | ||
return t.isAnyTypeAnnotation(type); | ||
return t().isAnyTypeAnnotation(type); | ||
} else if (baseName === "mixed") { | ||
return t.isMixedTypeAnnotation(type); | ||
return t().isMixedTypeAnnotation(type); | ||
} else if (baseName === "empty") { | ||
return t.isEmptyTypeAnnotation(type); | ||
return t().isEmptyTypeAnnotation(type); | ||
} else if (baseName === "void") { | ||
return t.isVoidTypeAnnotation(type); | ||
return t().isVoidTypeAnnotation(type); | ||
} else { | ||
@@ -91,3 +101,3 @@ if (soft) { | ||
} else { | ||
throw new Error("Unknown base type " + baseName); | ||
throw new Error(`Unknown base type ${baseName}`); | ||
} | ||
@@ -98,12 +108,8 @@ } | ||
function couldBeBaseType(name) { | ||
var type = this.getTypeAnnotation(); | ||
if (t.isAnyTypeAnnotation(type)) return true; | ||
const 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)) { | ||
if (t().isUnionTypeAnnotation(type)) { | ||
for (const type2 of type.types) { | ||
if (t().isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) { | ||
return true; | ||
@@ -120,6 +126,6 @@ } | ||
function baseTypeStrictlyMatches(right) { | ||
var left = this.getTypeAnnotation(); | ||
const left = this.getTypeAnnotation(); | ||
right = right.getTypeAnnotation(); | ||
if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) { | ||
if (!t().isAnyTypeAnnotation(left) && t().isFlowBaseAnnotation(left)) { | ||
return right.type === left.type; | ||
@@ -130,6 +136,6 @@ } | ||
function isGenericType(genericName) { | ||
var type = this.getTypeAnnotation(); | ||
return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, { | ||
const type = this.getTypeAnnotation(); | ||
return t().isGenericTypeAnnotation(type) && t().isIdentifier(type.id, { | ||
name: genericName | ||
}); | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -12,3 +22,3 @@ | ||
if (!this.isReferenced()) return; | ||
var binding = this.scope.getBinding(node.name); | ||
const binding = this.scope.getBinding(node.name); | ||
@@ -24,5 +34,5 @@ if (binding) { | ||
if (node.name === "undefined") { | ||
return t.voidTypeAnnotation(); | ||
return t().voidTypeAnnotation(); | ||
} else if (node.name === "NaN" || node.name === "Infinity") { | ||
return t.numberTypeAnnotation(); | ||
return t().numberTypeAnnotation(); | ||
} else if (node.name === "arguments") {} | ||
@@ -32,12 +42,10 @@ } | ||
function getTypeAnnotationBindingConstantViolations(binding, path, name) { | ||
var types = []; | ||
var functionConstantViolations = []; | ||
var constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations); | ||
var testType = getConditionalAnnotation(binding, path, name); | ||
const types = []; | ||
const functionConstantViolations = []; | ||
let constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations); | ||
const testType = getConditionalAnnotation(binding, path, name); | ||
if (testType) { | ||
var testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement); | ||
constantViolations = constantViolations.filter(function (path) { | ||
return testConstantViolations.indexOf(path) < 0; | ||
}); | ||
const testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement); | ||
constantViolations = constantViolations.filter(path => testConstantViolations.indexOf(path) < 0); | ||
types.push(testType.typeAnnotation); | ||
@@ -48,6 +56,4 @@ } | ||
constantViolations = constantViolations.concat(functionConstantViolations); | ||
var _arr = constantViolations; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var violation = _arr[_i]; | ||
for (const violation of constantViolations) { | ||
types.push(violation.getTypeAnnotation()); | ||
@@ -58,3 +64,3 @@ } | ||
if (types.length) { | ||
return t.createUnionTypeAnnotation(types); | ||
return t().createUnionTypeAnnotation(types); | ||
} | ||
@@ -64,8 +70,8 @@ } | ||
function getConstantViolationsBefore(binding, path, functions) { | ||
var violations = binding.constantViolations.slice(); | ||
const violations = binding.constantViolations.slice(); | ||
violations.unshift(binding.path); | ||
return violations.filter(function (violation) { | ||
return violations.filter(violation => { | ||
violation = violation.resolve(); | ||
var status = violation._guessExecutionStatusRelativeTo(path); | ||
const status = violation._guessExecutionStatusRelativeTo(path); | ||
@@ -78,13 +84,13 @@ if (functions && status === "function") functions.push(violation); | ||
function inferAnnotationFromBinaryExpression(name, path) { | ||
var operator = path.node.operator; | ||
var right = path.get("right").resolve(); | ||
var left = path.get("left").resolve(); | ||
var target; | ||
const operator = path.node.operator; | ||
const right = path.get("right").resolve(); | ||
const left = path.get("left").resolve(); | ||
let target; | ||
if (left.isIdentifier({ | ||
name: name | ||
name | ||
})) { | ||
target = right; | ||
} else if (right.isIdentifier({ | ||
name: name | ||
name | ||
})) { | ||
@@ -99,4 +105,4 @@ target = left; | ||
if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t.numberTypeAnnotation(); | ||
if (t().BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) { | ||
return t().numberTypeAnnotation(); | ||
} | ||
@@ -108,4 +114,4 @@ | ||
if (operator !== "===" && operator !== "==") return; | ||
var typeofPath; | ||
var typePath; | ||
let typeofPath; | ||
let typePath; | ||
@@ -126,13 +132,13 @@ if (left.isUnaryExpression({ | ||
if (!typeofPath.get("argument").isIdentifier({ | ||
name: name | ||
name | ||
})) return; | ||
typePath = typePath.resolve(); | ||
if (!typePath.isLiteral()) return; | ||
var typeValue = typePath.node.value; | ||
const typeValue = typePath.node.value; | ||
if (typeof typeValue !== "string") return; | ||
return t.createTypeAnnotationBasedOnTypeof(typeValue); | ||
return t().createTypeAnnotationBasedOnTypeof(typeValue); | ||
} | ||
function getParentConditionalPath(binding, path, name) { | ||
var parentPath; | ||
let parentPath; | ||
@@ -157,18 +163,18 @@ while (parentPath = path.parentPath) { | ||
function getConditionalAnnotation(binding, path, name) { | ||
var ifStatement = getParentConditionalPath(binding, path, name); | ||
const ifStatement = getParentConditionalPath(binding, path, name); | ||
if (!ifStatement) return; | ||
var test = ifStatement.get("test"); | ||
var paths = [test]; | ||
var types = []; | ||
const test = ifStatement.get("test"); | ||
const paths = [test]; | ||
const types = []; | ||
for (var i = 0; i < paths.length; i++) { | ||
var _path = paths[i]; | ||
for (let i = 0; i < paths.length; i++) { | ||
const path = paths[i]; | ||
if (_path.isLogicalExpression()) { | ||
if (_path.node.operator === "&&") { | ||
paths.push(_path.get("left")); | ||
paths.push(_path.get("right")); | ||
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); | ||
} else if (path.isBinaryExpression()) { | ||
const type = inferAnnotationFromBinaryExpression(name, path); | ||
if (type) types.push(type); | ||
@@ -180,4 +186,4 @@ } | ||
return { | ||
typeAnnotation: t.createUnionTypeAnnotation(types), | ||
ifStatement: ifStatement | ||
typeAnnotation: t().createUnionTypeAnnotation(types), | ||
ifStatement | ||
}; | ||
@@ -184,0 +190,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.VariableDeclarator = VariableDeclarator; | ||
@@ -26,10 +28,21 @@ exports.TypeCastExpression = TypeCastExpression; | ||
exports.TaggedTemplateExpression = TaggedTemplateExpression; | ||
exports.Identifier = void 0; | ||
Object.defineProperty(exports, "Identifier", { | ||
enumerable: true, | ||
get: function () { | ||
return _infererReference.default; | ||
} | ||
}); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _infererReference = _interopRequireDefault(require("./inferer-reference")); | ||
exports.Identifier = _infererReference.default; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -40,6 +53,6 @@ | ||
function VariableDeclarator() { | ||
var id = this.get("id"); | ||
const id = this.get("id"); | ||
if (!id.isIdentifier()) return; | ||
var init = this.get("init"); | ||
var type = init.getTypeAnnotation(); | ||
const init = this.get("init"); | ||
let type = init.getTypeAnnotation(); | ||
@@ -65,3 +78,3 @@ if (type && type.type === "AnyTypeAnnotation") { | ||
if (this.get("callee").isIdentifier()) { | ||
return t.genericTypeAnnotation(node.callee); | ||
return t().genericTypeAnnotation(node.callee); | ||
} | ||
@@ -71,16 +84,16 @@ } | ||
function TemplateLiteral() { | ||
return t.stringTypeAnnotation(); | ||
return t().stringTypeAnnotation(); | ||
} | ||
function UnaryExpression(node) { | ||
var operator = node.operator; | ||
const 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(); | ||
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(); | ||
} | ||
@@ -90,19 +103,19 @@ } | ||
function BinaryExpression(node) { | ||
var operator = node.operator; | ||
const 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(); | ||
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"); | ||
const right = this.get("right"); | ||
const left = this.get("left"); | ||
if (left.isBaseType("number") && right.isBaseType("number")) { | ||
return t.numberTypeAnnotation(); | ||
return t().numberTypeAnnotation(); | ||
} else if (left.isBaseType("string") || right.isBaseType("string")) { | ||
return t.stringTypeAnnotation(); | ||
return t().stringTypeAnnotation(); | ||
} | ||
return t.unionTypeAnnotation([t.stringTypeAnnotation(), t.numberTypeAnnotation()]); | ||
return t().unionTypeAnnotation([t().stringTypeAnnotation(), t().numberTypeAnnotation()]); | ||
} | ||
@@ -112,7 +125,7 @@ } | ||
function LogicalExpression() { | ||
return t.createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]); | ||
return t().createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]); | ||
} | ||
function ConditionalExpression() { | ||
return t.createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]); | ||
return t().createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]); | ||
} | ||
@@ -129,6 +142,6 @@ | ||
function UpdateExpression(node) { | ||
var operator = node.operator; | ||
const operator = node.operator; | ||
if (operator === "++" || operator === "--") { | ||
return t.numberTypeAnnotation(); | ||
return t().numberTypeAnnotation(); | ||
} | ||
@@ -138,27 +151,27 @@ } | ||
function StringLiteral() { | ||
return t.stringTypeAnnotation(); | ||
return t().stringTypeAnnotation(); | ||
} | ||
function NumericLiteral() { | ||
return t.numberTypeAnnotation(); | ||
return t().numberTypeAnnotation(); | ||
} | ||
function BooleanLiteral() { | ||
return t.booleanTypeAnnotation(); | ||
return t().booleanTypeAnnotation(); | ||
} | ||
function NullLiteral() { | ||
return t.nullLiteralTypeAnnotation(); | ||
return t().nullLiteralTypeAnnotation(); | ||
} | ||
function RegExpLiteral() { | ||
return t.genericTypeAnnotation(t.identifier("RegExp")); | ||
return t().genericTypeAnnotation(t().identifier("RegExp")); | ||
} | ||
function ObjectExpression() { | ||
return t.genericTypeAnnotation(t.identifier("Object")); | ||
return t().genericTypeAnnotation(t().identifier("Object")); | ||
} | ||
function ArrayExpression() { | ||
return t.genericTypeAnnotation(t.identifier("Array")); | ||
return t().genericTypeAnnotation(t().identifier("Array")); | ||
} | ||
@@ -173,19 +186,21 @@ | ||
function Func() { | ||
return t.genericTypeAnnotation(t.identifier("Function")); | ||
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"); | ||
const isArrayFrom = t().buildMatchMemberExpression("Array.from"); | ||
const isObjectKeys = t().buildMatchMemberExpression("Object.keys"); | ||
const isObjectValues = t().buildMatchMemberExpression("Object.values"); | ||
const isObjectEntries = t().buildMatchMemberExpression("Object.entries"); | ||
function CallExpression() { | ||
var callee = this.node.callee; | ||
const { | ||
callee | ||
} = this.node; | ||
if (isObjectKeys(callee)) { | ||
return t.arrayTypeAnnotation(t.stringTypeAnnotation()); | ||
return t().arrayTypeAnnotation(t().stringTypeAnnotation()); | ||
} else if (isArrayFrom(callee) || isObjectValues(callee)) { | ||
return t.arrayTypeAnnotation(t.anyTypeAnnotation()); | ||
return t().arrayTypeAnnotation(t().anyTypeAnnotation()); | ||
} else if (isObjectEntries(callee)) { | ||
return t.arrayTypeAnnotation(t.tupleTypeAnnotation([t.stringTypeAnnotation(), t.anyTypeAnnotation()])); | ||
return t().arrayTypeAnnotation(t().tupleTypeAnnotation([t().stringTypeAnnotation(), t().anyTypeAnnotation()])); | ||
} | ||
@@ -206,5 +221,5 @@ | ||
if (callee.is("generator")) { | ||
return t.genericTypeAnnotation(t.identifier("AsyncIterator")); | ||
return t().genericTypeAnnotation(t().identifier("AsyncIterator")); | ||
} else { | ||
return t.genericTypeAnnotation(t.identifier("Promise")); | ||
return t().genericTypeAnnotation(t().identifier("Promise")); | ||
} | ||
@@ -211,0 +226,0 @@ } else { |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.matchesPattern = matchesPattern; | ||
@@ -24,6 +26,22 @@ exports.has = has; | ||
var _includes = _interopRequireDefault(require("lodash/includes")); | ||
function _includes() { | ||
const data = _interopRequireDefault(require("lodash/includes")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
_includes = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -34,7 +52,7 @@ | ||
function matchesPattern(pattern, allowPartial) { | ||
return t.matchesPattern(this.node, pattern, allowPartial); | ||
return t().matchesPattern(this.node, pattern, allowPartial); | ||
} | ||
function has(key) { | ||
var val = this.node && this.node[key]; | ||
const val = this.node && this.node[key]; | ||
@@ -52,3 +70,3 @@ if (val && Array.isArray(val)) { | ||
var is = has; | ||
const is = has; | ||
exports.is = is; | ||
@@ -65,3 +83,3 @@ | ||
function isNodeType(type) { | ||
return t.isType(this.type, type); | ||
return t().isType(this.type, type); | ||
} | ||
@@ -79,5 +97,5 @@ | ||
if (this.isExpression()) { | ||
return t.isBlockStatement(replacement); | ||
return t().isBlockStatement(replacement); | ||
} else if (this.isBlockStatement()) { | ||
return t.isExpression(replacement); | ||
return t().isExpression(replacement); | ||
} | ||
@@ -89,7 +107,7 @@ | ||
function isCompletionRecord(allowInsideFunction) { | ||
var path = this; | ||
var first = true; | ||
let path = this; | ||
let first = true; | ||
do { | ||
var container = path.container; | ||
const container = path.container; | ||
@@ -111,6 +129,6 @@ if (path.isFunction() && !first) { | ||
function isStatementOrBlock() { | ||
if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) { | ||
if (this.parentPath.isLabeledStatement() || t().isBlockStatement(this.container)) { | ||
return false; | ||
} else { | ||
return (0, _includes.default)(t.STATEMENT_OR_BLOCK_KEYS, this.key); | ||
return (0, _includes().default)(t().STATEMENT_OR_BLOCK_KEYS, this.key); | ||
} | ||
@@ -121,6 +139,6 @@ } | ||
if (!this.isReferencedIdentifier()) return false; | ||
var binding = this.scope.getBinding(this.node.name); | ||
const binding = this.scope.getBinding(this.node.name); | ||
if (!binding || binding.kind !== "module") return false; | ||
var path = binding.path; | ||
var parent = path.parentPath; | ||
const path = binding.path; | ||
const parent = path.parentPath; | ||
if (!parent.isImportDeclaration()) return false; | ||
@@ -150,3 +168,3 @@ | ||
function getSource() { | ||
var node = this.node; | ||
const node = this.node; | ||
@@ -165,7 +183,7 @@ if (node.end) { | ||
function _guessExecutionStatusRelativeTo(target) { | ||
var targetFuncParent = target.scope.getFunctionParent() || target.scope.getProgramParent(); | ||
var selfFuncParent = this.scope.getFunctionParent() || target.scope.getProgramParent(); | ||
const targetFuncParent = target.scope.getFunctionParent() || target.scope.getProgramParent(); | ||
const selfFuncParent = this.scope.getFunctionParent() || target.scope.getProgramParent(); | ||
if (targetFuncParent.node !== selfFuncParent.node) { | ||
var status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent); | ||
const status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent); | ||
@@ -179,11 +197,11 @@ if (status) { | ||
var targetPaths = target.getAncestry(); | ||
const targetPaths = target.getAncestry(); | ||
if (targetPaths.indexOf(this) >= 0) return "after"; | ||
var selfPaths = this.getAncestry(); | ||
var commonPath; | ||
var targetIndex; | ||
var selfIndex; | ||
const selfPaths = this.getAncestry(); | ||
let commonPath; | ||
let targetIndex; | ||
let selfIndex; | ||
for (selfIndex = 0; selfIndex < selfPaths.length; selfIndex++) { | ||
var selfPath = selfPaths[selfIndex]; | ||
const selfPath = selfPaths[selfIndex]; | ||
targetIndex = targetPaths.indexOf(selfPath); | ||
@@ -201,4 +219,4 @@ | ||
var targetRelationship = targetPaths[targetIndex - 1]; | ||
var selfRelationship = selfPaths[selfIndex - 1]; | ||
const targetRelationship = targetPaths[targetIndex - 1]; | ||
const selfRelationship = selfPaths[selfIndex - 1]; | ||
@@ -213,5 +231,5 @@ if (!targetRelationship || !selfRelationship) { | ||
var keys = t.VISITOR_KEYS[commonPath.type]; | ||
var targetKeyPosition = keys.indexOf(targetRelationship.key); | ||
var selfKeyPosition = keys.indexOf(selfRelationship.key); | ||
const keys = t().VISITOR_KEYS[commonPath.type]; | ||
const targetKeyPosition = keys.indexOf(targetRelationship.key); | ||
const selfKeyPosition = keys.indexOf(selfRelationship.key); | ||
return targetKeyPosition > selfKeyPosition ? "before" : "after"; | ||
@@ -221,23 +239,10 @@ } | ||
function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent) { | ||
var targetFuncPath = targetFuncParent.path; | ||
const targetFuncPath = targetFuncParent.path; | ||
if (!targetFuncPath.isFunctionDeclaration()) return; | ||
var binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name); | ||
const binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name); | ||
if (!binding.references) return "before"; | ||
var referencePaths = binding.referencePaths; | ||
const 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 _path2 = _ref; | ||
if (_path2.key !== "callee" || !_path2.parentPath.isCallExpression()) { | ||
for (const path of referencePaths) { | ||
if (path.key !== "callee" || !path.parentPath.isCallExpression()) { | ||
return; | ||
@@ -247,23 +252,9 @@ } | ||
var allStatus; | ||
let 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 _path3 = _ref2; | ||
var childOfFunction = !!_path3.find(function (path) { | ||
return path.node === targetFuncPath.node; | ||
}); | ||
for (const path of referencePaths) { | ||
const childOfFunction = !!path.find(path => path.node === targetFuncPath.node); | ||
if (childOfFunction) continue; | ||
var status = this._guessExecutionStatusRelativeTo(_path3); | ||
const status = this._guessExecutionStatusRelativeTo(path); | ||
@@ -294,3 +285,3 @@ if (allStatus) { | ||
} else if (this.isReferencedIdentifier()) { | ||
var binding = this.scope.getBinding(this.node.name); | ||
const binding = this.scope.getBinding(this.node.name); | ||
if (!binding) return; | ||
@@ -301,6 +292,4 @@ if (!binding.constant) return; | ||
if (binding.path !== this) { | ||
var ret = binding.path.resolve(dangerous, resolved); | ||
if (this.find(function (parent) { | ||
return parent.node === ret.node; | ||
})) return; | ||
const ret = binding.path.resolve(dangerous, resolved); | ||
if (this.find(parent => parent.node === ret.node)) return; | ||
return ret; | ||
@@ -311,16 +300,14 @@ } | ||
} 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); | ||
const targetKey = this.toComputedKey(); | ||
if (!t().isLiteral(targetKey)) return; | ||
const targetName = targetKey.value; | ||
const target = this.get("object").resolve(dangerous, resolved); | ||
if (target.isObjectExpression()) { | ||
var props = target.get("properties"); | ||
var _arr = props; | ||
const props = target.get("properties"); | ||
for (var _i3 = 0; _i3 < _arr.length; _i3++) { | ||
var prop = _arr[_i3]; | ||
for (const prop of props) { | ||
if (!prop.isProperty()) continue; | ||
var key = prop.get("key"); | ||
var match = prop.isnt("computed") && key.isIdentifier({ | ||
const key = prop.get("key"); | ||
let match = prop.isnt("computed") && key.isIdentifier({ | ||
name: targetName | ||
@@ -334,4 +321,4 @@ }); | ||
} else if (target.isArrayExpression() && !isNaN(+targetName)) { | ||
var elems = target.get("elements"); | ||
var elem = elems[targetName]; | ||
const elems = target.get("elements"); | ||
const elem = elems[targetName]; | ||
if (elem) return elem.resolve(dangerous, resolved); | ||
@@ -344,3 +331,3 @@ } | ||
if (this.isIdentifier()) { | ||
var binding = this.scope.getBinding(this.node.name); | ||
const binding = this.scope.getBinding(this.node.name); | ||
@@ -360,5 +347,3 @@ if (!binding) { | ||
if (this.isTemplateLiteral()) { | ||
return this.get("expressions").every(function (expression) { | ||
return expression.isConstantExpression(); | ||
}); | ||
return this.get("expressions").every(expression => expression.isConstantExpression()); | ||
} | ||
@@ -365,0 +350,0 @@ |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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()) { | ||
const referenceVisitor = { | ||
ReferencedIdentifier(path, state) { | ||
if (path.isJSXIdentifier() && t().react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) { | ||
return; | ||
@@ -17,3 +27,3 @@ } | ||
if (path.node.name === "this") { | ||
var scope = path.scope; | ||
let scope = path.scope; | ||
@@ -29,3 +39,3 @@ do { | ||
var binding = path.scope.getBinding(path.node.name); | ||
const binding = path.scope.getBinding(path.node.name); | ||
if (!binding) return; | ||
@@ -35,6 +45,7 @@ if (binding !== state.scope.getBinding(path.node.name)) return; | ||
} | ||
}; | ||
var PathHoister = function () { | ||
function PathHoister(path, scope) { | ||
class PathHoister { | ||
constructor(path, scope) { | ||
this.breakOnScopePaths = []; | ||
@@ -48,8 +59,6 @@ this.bindings = {}; | ||
var _proto = PathHoister.prototype; | ||
isCompatibleScope(scope) { | ||
for (const key in this.bindings) { | ||
const binding = this.bindings[key]; | ||
_proto.isCompatibleScope = function isCompatibleScope(scope) { | ||
for (var key in this.bindings) { | ||
var binding = this.bindings[key]; | ||
if (!scope.bindingIdentifierEquals(key, binding.identifier)) { | ||
@@ -61,6 +70,6 @@ return false; | ||
return true; | ||
}; | ||
} | ||
_proto.getCompatibleScopes = function getCompatibleScopes() { | ||
var scope = this.path.scope; | ||
getCompatibleScopes() { | ||
let scope = this.path.scope; | ||
@@ -78,9 +87,9 @@ do { | ||
} while (scope = scope.parent); | ||
}; | ||
} | ||
_proto.getAttachmentPath = function getAttachmentPath() { | ||
var path = this._getAttachmentPath(); | ||
getAttachmentPath() { | ||
let path = this._getAttachmentPath(); | ||
if (!path) return; | ||
var targetScope = path.scope; | ||
let targetScope = path.scope; | ||
@@ -92,5 +101,5 @@ if (targetScope.path === path) { | ||
if (targetScope.path.isProgram() || targetScope.path.isFunction()) { | ||
for (var name in this.bindings) { | ||
for (const name in this.bindings) { | ||
if (!targetScope.hasOwnBinding(name)) continue; | ||
var binding = this.bindings[name]; | ||
const binding = this.bindings[name]; | ||
@@ -101,3 +110,3 @@ if (binding.kind === "param" || binding.path.parentKey === "params") { | ||
var bindingParentPath = this.getAttachmentParentForPath(binding.path); | ||
const bindingParentPath = this.getAttachmentParentForPath(binding.path); | ||
@@ -107,7 +116,4 @@ if (bindingParentPath.key >= path.key) { | ||
path = binding.path; | ||
var _arr = binding.constantViolations; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var violationPath = _arr[_i]; | ||
for (const violationPath of binding.constantViolations) { | ||
if (this.getAttachmentParentForPath(violationPath).key > path.key) { | ||
@@ -122,7 +128,7 @@ path = violationPath; | ||
return path; | ||
}; | ||
} | ||
_proto._getAttachmentPath = function _getAttachmentPath() { | ||
var scopes = this.scopes; | ||
var scope = scopes.pop(); | ||
_getAttachmentPath() { | ||
const scopes = this.scopes; | ||
const scope = scopes.pop(); | ||
if (!scope) return; | ||
@@ -133,5 +139,5 @@ | ||
if (this.scope === scope) return; | ||
var bodies = scope.path.get("body").get("body"); | ||
const bodies = scope.path.get("body").get("body"); | ||
for (var i = 0; i < bodies.length; i++) { | ||
for (let i = 0; i < bodies.length; i++) { | ||
if (bodies[i].node._blockHoist) continue; | ||
@@ -146,10 +152,10 @@ return bodies[i]; | ||
} | ||
}; | ||
} | ||
_proto.getNextScopeAttachmentParent = function getNextScopeAttachmentParent() { | ||
var scope = this.scopes.pop(); | ||
getNextScopeAttachmentParent() { | ||
const scope = this.scopes.pop(); | ||
if (scope) return this.getAttachmentParentForPath(scope.path); | ||
}; | ||
} | ||
_proto.getAttachmentParentForPath = function getAttachmentParentForPath(path) { | ||
getAttachmentParentForPath(path) { | ||
do { | ||
@@ -160,8 +166,8 @@ if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) { | ||
} while (path = path.parentPath); | ||
}; | ||
} | ||
_proto.hasOwnParamBindings = function hasOwnParamBindings(scope) { | ||
for (var name in this.bindings) { | ||
hasOwnParamBindings(scope) { | ||
for (const name in this.bindings) { | ||
if (!scope.hasOwnBinding(name)) continue; | ||
var binding = this.bindings[name]; | ||
const binding = this.bindings[name]; | ||
if (binding.kind === "param" && binding.constant) return true; | ||
@@ -171,30 +177,26 @@ } | ||
return false; | ||
}; | ||
} | ||
_proto.run = function run() { | ||
run() { | ||
this.path.traverse(referenceVisitor, this); | ||
this.getCompatibleScopes(); | ||
var attachTo = this.getAttachmentPath(); | ||
const 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"; | ||
let uid = attachTo.scope.generateUidIdentifier("ref"); | ||
const declarator = t().variableDeclarator(uid, this.path.node); | ||
const insertFn = this.attachAfter ? "insertAfter" : "insertBefore"; | ||
const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : t().variableDeclaration("var", [declarator])]); | ||
const parent = this.path.parentPath; | ||
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); | ||
uid = t().JSXExpressionContainer(uid); | ||
} | ||
this.path.replaceWith(t.cloneNode(uid)); | ||
this.path.replaceWith(t().cloneNode(uid)); | ||
return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init"); | ||
}; | ||
} | ||
return PathHoister; | ||
}(); | ||
} | ||
exports.default = PathHoister; |
"use strict"; | ||
exports.__esModule = true; | ||
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(); | ||
const hooks = [function (self, parent) { | ||
const 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(); | ||
@@ -8,0 +10,0 @@ if (removeParent) { |
"use strict"; | ||
exports.__esModule = true; | ||
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; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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 = { | ||
const 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; | ||
checkPath({ | ||
node, | ||
parent | ||
}, opts) { | ||
if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) { | ||
if (t().isJSXIdentifier(node, opts)) { | ||
if (t().react.isCompatTag(node.name)) return false; | ||
} else { | ||
@@ -24,36 +35,44 @@ return false; | ||
return t.isReferenced(node, parent); | ||
return t().isReferenced(node, parent); | ||
} | ||
}; | ||
exports.ReferencedIdentifier = ReferencedIdentifier; | ||
var ReferencedMemberExpression = { | ||
const ReferencedMemberExpression = { | ||
types: ["MemberExpression"], | ||
checkPath: function checkPath(_ref2) { | ||
var node = _ref2.node, | ||
parent = _ref2.parent; | ||
return t.isMemberExpression(node) && t.isReferenced(node, parent); | ||
checkPath({ | ||
node, | ||
parent | ||
}) { | ||
return t().isMemberExpression(node) && t().isReferenced(node, parent); | ||
} | ||
}; | ||
exports.ReferencedMemberExpression = ReferencedMemberExpression; | ||
var BindingIdentifier = { | ||
const BindingIdentifier = { | ||
types: ["Identifier"], | ||
checkPath: function checkPath(_ref3) { | ||
var node = _ref3.node, | ||
parent = _ref3.parent; | ||
return t.isIdentifier(node) && t.isBinding(node, parent); | ||
checkPath({ | ||
node, | ||
parent | ||
}) { | ||
return t().isIdentifier(node) && t().isBinding(node, parent); | ||
} | ||
}; | ||
exports.BindingIdentifier = BindingIdentifier; | ||
var Statement = { | ||
const 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, { | ||
checkPath({ | ||
node, | ||
parent | ||
}) { | ||
if (t().isStatement(node)) { | ||
if (t().isVariableDeclaration(node)) { | ||
if (t().isForXStatement(parent, { | ||
left: node | ||
})) return false; | ||
if (t.isForStatement(parent, { | ||
if (t().isForStatement(parent, { | ||
init: node | ||
@@ -68,71 +87,84 @@ })) return false; | ||
} | ||
}; | ||
exports.Statement = Statement; | ||
var Expression = { | ||
const Expression = { | ||
types: ["Expression"], | ||
checkPath: function checkPath(path) { | ||
checkPath(path) { | ||
if (path.isIdentifier()) { | ||
return path.isReferencedIdentifier(); | ||
} else { | ||
return t.isExpression(path.node); | ||
return t().isExpression(path.node); | ||
} | ||
} | ||
}; | ||
exports.Expression = Expression; | ||
var Scope = { | ||
const Scope = { | ||
types: ["Scopable"], | ||
checkPath: function checkPath(path) { | ||
return t.isScope(path.node, path.parent); | ||
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); | ||
const Referenced = { | ||
checkPath(path) { | ||
return t().isReferenced(path.node, path.parent); | ||
} | ||
}; | ||
exports.Referenced = Referenced; | ||
var BlockScoped = { | ||
checkPath: function checkPath(path) { | ||
return t.isBlockScoped(path.node); | ||
const BlockScoped = { | ||
checkPath(path) { | ||
return t().isBlockScoped(path.node); | ||
} | ||
}; | ||
exports.BlockScoped = BlockScoped; | ||
var Var = { | ||
const Var = { | ||
types: ["VariableDeclaration"], | ||
checkPath: function checkPath(path) { | ||
return t.isVar(path.node); | ||
checkPath(path) { | ||
return t().isVar(path.node); | ||
} | ||
}; | ||
exports.Var = Var; | ||
var User = { | ||
checkPath: function checkPath(path) { | ||
const User = { | ||
checkPath(path) { | ||
return path.node && !!path.node.loc; | ||
} | ||
}; | ||
exports.User = User; | ||
var Generated = { | ||
checkPath: function checkPath(path) { | ||
const Generated = { | ||
checkPath(path) { | ||
return !path.isUser(); | ||
} | ||
}; | ||
exports.Generated = Generated; | ||
var Pure = { | ||
checkPath: function checkPath(path, opts) { | ||
const Pure = { | ||
checkPath(path, opts) { | ||
return path.scope.isPure(path.node, opts); | ||
} | ||
}; | ||
exports.Pure = Pure; | ||
var Flow = { | ||
const Flow = { | ||
types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"], | ||
checkPath: function checkPath(_ref5) { | ||
var node = _ref5.node; | ||
if (t.isFlow(node)) { | ||
checkPath({ | ||
node | ||
}) { | ||
if (t().isFlow(node)) { | ||
return true; | ||
} else if (t.isImportDeclaration(node)) { | ||
} else if (t().isImportDeclaration(node)) { | ||
return node.importKind === "type" || node.importKind === "typeof"; | ||
} else if (t.isExportDeclaration(node)) { | ||
} else if (t().isExportDeclaration(node)) { | ||
return node.exportKind === "type"; | ||
} else if (t.isImportSpecifier(node)) { | ||
} else if (t().isImportSpecifier(node)) { | ||
return node.importKind === "type" || node.importKind === "typeof"; | ||
@@ -143,33 +175,41 @@ } else { | ||
} | ||
}; | ||
exports.Flow = Flow; | ||
var RestProperty = { | ||
const RestProperty = { | ||
types: ["RestElement"], | ||
checkPath: function checkPath(path) { | ||
checkPath(path) { | ||
return path.parentPath && path.parentPath.isObjectPattern(); | ||
} | ||
}; | ||
exports.RestProperty = RestProperty; | ||
var SpreadProperty = { | ||
const SpreadProperty = { | ||
types: ["RestElement"], | ||
checkPath: function checkPath(path) { | ||
checkPath(path) { | ||
return path.parentPath && path.parentPath.isObjectExpression(); | ||
} | ||
}; | ||
exports.SpreadProperty = SpreadProperty; | ||
var ExistentialTypeParam = { | ||
const ExistentialTypeParam = { | ||
types: ["ExistsTypeAnnotation"] | ||
}; | ||
exports.ExistentialTypeParam = ExistentialTypeParam; | ||
var NumericLiteralTypeAnnotation = { | ||
const NumericLiteralTypeAnnotation = { | ||
types: ["NumberLiteralTypeAnnotation"] | ||
}; | ||
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation; | ||
var ForAwaitStatement = { | ||
const ForAwaitStatement = { | ||
types: ["ForOfStatement"], | ||
checkPath: function checkPath(_ref6) { | ||
var node = _ref6.node; | ||
checkPath({ | ||
node | ||
}) { | ||
return node.await === true; | ||
} | ||
}; | ||
exports.ForAwaitStatement = ForAwaitStatement; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.insertBefore = insertBefore; | ||
@@ -21,4 +23,12 @@ exports._containerInsert = _containerInsert; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -41,4 +51,4 @@ | ||
} else if (this.isStatementOrBlock()) { | ||
var shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null); | ||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null); | ||
this.replaceWith(t().blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
return this.unshiftContainer("body", nodes); | ||
@@ -51,12 +61,9 @@ } else { | ||
function _containerInsert(from, nodes) { | ||
var _container; | ||
this.updateSiblingKeys(from, nodes.length); | ||
var paths = []; | ||
const paths = []; | ||
this.container.splice(from, 0, ...nodes); | ||
(_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); | ||
for (let i = 0; i < nodes.length; i++) { | ||
const to = from + i; | ||
const path = this.getSibling(to); | ||
paths.push(path); | ||
@@ -69,26 +76,10 @@ | ||
var contexts = this._getQueueContexts(); | ||
const contexts = this._getQueueContexts(); | ||
for (var _i = 0; _i < paths.length; _i++) { | ||
var _path = paths[_i]; | ||
for (const path of paths) { | ||
path.setScope(); | ||
path.debug("Inserted."); | ||
_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); | ||
for (const context of contexts) { | ||
context.maybeQueue(path, true); | ||
} | ||
@@ -117,5 +108,5 @@ } | ||
if (this.node) { | ||
var temp = this.scope.generateDeclaredUidIdentifier(); | ||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(temp), this.node))); | ||
nodes.push(t.expressionStatement(t.cloneNode(temp))); | ||
const temp = this.scope.generateDeclaredUidIdentifier(); | ||
nodes.unshift(t().expressionStatement(t().assignmentExpression("=", t().cloneNode(temp), this.node))); | ||
nodes.push(t().expressionStatement(t().cloneNode(temp))); | ||
} | ||
@@ -127,4 +118,4 @@ | ||
} else if (this.isStatementOrBlock()) { | ||
var shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null); | ||
this.replaceWith(t.blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
const shouldInsertCurrentNode = this.node && (!this.isExpressionStatement() || this.node.expression != null); | ||
this.replaceWith(t().blockStatement(shouldInsertCurrentNode ? [this.node] : [])); | ||
return this.pushContainer("body", nodes); | ||
@@ -139,6 +130,6 @@ } else { | ||
var paths = _cache.path.get(this.parent); | ||
const paths = _cache.path.get(this.parent); | ||
for (var i = 0; i < paths.length; i++) { | ||
var path = paths[i]; | ||
for (let i = 0; i < paths.length; i++) { | ||
const path = paths[i]; | ||
@@ -160,5 +151,5 @@ if (path.key >= fromIndex) { | ||
for (var i = 0; i < nodes.length; i++) { | ||
var node = nodes[i]; | ||
var msg = void 0; | ||
for (let i = 0; i < nodes.length; i++) { | ||
const node = nodes[i]; | ||
let msg; | ||
@@ -176,4 +167,4 @@ if (!node) { | ||
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); | ||
const type = Array.isArray(node) ? "array" : typeof node; | ||
throw new Error(`Node list ${msg} with the index of ${i} and type of ${type}`); | ||
} | ||
@@ -190,7 +181,7 @@ } | ||
var path = _index.default.get({ | ||
const path = _index.default.get({ | ||
parentPath: this, | ||
parent: this.node, | ||
container: this.node[listKey], | ||
listKey: listKey, | ||
listKey, | ||
key: 0 | ||
@@ -206,9 +197,9 @@ }); | ||
nodes = this._verifyNodeList(nodes); | ||
var container = this.node[listKey]; | ||
const container = this.node[listKey]; | ||
var path = _index.default.get({ | ||
const path = _index.default.get({ | ||
parentPath: this, | ||
parent: this.node, | ||
container: container, | ||
listKey: listKey, | ||
listKey, | ||
key: container.length | ||
@@ -220,9 +211,5 @@ }); | ||
function hoist(scope) { | ||
if (scope === void 0) { | ||
scope = this.scope; | ||
} | ||
var hoister = new _hoister.default(this, scope); | ||
function hoist(scope = this.scope) { | ||
const hoister = new _hoister.default(this, scope); | ||
return hoister.run(); | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.remove = remove; | ||
@@ -34,15 +36,8 @@ exports._removeFromScope = _removeFromScope; | ||
function _removeFromScope() { | ||
var _this = this; | ||
var bindings = this.getBindingIdentifiers(); | ||
Object.keys(bindings).forEach(function (name) { | ||
return _this.scope.removeBinding(name); | ||
}); | ||
const bindings = this.getBindingIdentifiers(); | ||
Object.keys(bindings).forEach(name => this.scope.removeBinding(name)); | ||
} | ||
function _callRemovalHooks() { | ||
var _arr = _removalHooks.hooks; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var fn = _arr[_i]; | ||
for (const fn of _removalHooks.hooks) { | ||
if (fn(this, this.parentPath)) return true; | ||
@@ -49,0 +44,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.replaceWithMultiple = replaceWithMultiple; | ||
@@ -11,4 +13,12 @@ exports.replaceWithSourceString = replaceWithSourceString; | ||
var _codeFrame = require("@babel/code-frame"); | ||
function _codeFrame() { | ||
const data = require("@babel/code-frame"); | ||
_codeFrame = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _index = _interopRequireDefault(require("../index")); | ||
@@ -18,6 +28,22 @@ | ||
var _babylon = require("babylon"); | ||
function _babylon() { | ||
const data = require("babylon"); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
_babylon = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -27,11 +53,12 @@ | ||
var hoistVariablesVisitor = { | ||
Function: function Function(path) { | ||
const hoistVariablesVisitor = { | ||
Function(path) { | ||
path.skip(); | ||
}, | ||
VariableDeclaration: function VariableDeclaration(path) { | ||
VariableDeclaration(path) { | ||
if (path.node.kind !== "var") return; | ||
var bindings = path.getBindingIdentifiers(); | ||
const bindings = path.getBindingIdentifiers(); | ||
for (var key in bindings) { | ||
for (const key in bindings) { | ||
path.scope.push({ | ||
@@ -42,10 +69,7 @@ id: bindings[key] | ||
var exprs = []; | ||
var _arr = path.node.declarations; | ||
const exprs = []; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var declar = _arr[_i]; | ||
for (const declar of path.node.declarations) { | ||
if (declar.init) { | ||
exprs.push(t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init))); | ||
exprs.push(t().expressionStatement(t().assignmentExpression("=", declar.id, declar.init))); | ||
} | ||
@@ -56,2 +80,3 @@ } | ||
} | ||
}; | ||
@@ -62,6 +87,6 @@ | ||
nodes = this._verifyNodeList(nodes); | ||
t.inheritLeadingComments(nodes[0], this.node); | ||
t.inheritTrailingComments(nodes[nodes.length - 1], this.node); | ||
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); | ||
const paths = this.insertAfter(nodes); | ||
@@ -81,9 +106,9 @@ if (this.node) { | ||
try { | ||
replacement = "(" + replacement + ")"; | ||
replacement = (0, _babylon.parse)(replacement); | ||
replacement = `(${replacement})`; | ||
replacement = (0, _babylon().parse)(replacement); | ||
} catch (err) { | ||
var loc = err.loc; | ||
const loc = err.loc; | ||
if (loc) { | ||
err.message += " - make sure this is an expression.\n" + (0, _codeFrame.codeFrameColumns)(replacement, { | ||
err.message += " - make sure this is an expression.\n" + (0, _codeFrame().codeFrameColumns)(replacement, { | ||
start: { | ||
@@ -126,3 +151,3 @@ line: loc.line, | ||
if (this.isProgram() && !t.isProgram(replacement)) { | ||
if (this.isProgram() && !t().isProgram(replacement)) { | ||
throw new Error("You can only replace a Program root node with another Program node"); | ||
@@ -139,7 +164,7 @@ } | ||
var nodePath = ""; | ||
let nodePath = ""; | ||
if (this.isNodeType("Statement") && t.isExpression(replacement)) { | ||
if (this.isNodeType("Statement") && t().isExpression(replacement)) { | ||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement) && !this.parentPath.isExportDefaultDeclaration()) { | ||
replacement = t.expressionStatement(replacement); | ||
replacement = t().expressionStatement(replacement); | ||
nodePath = "expression"; | ||
@@ -149,3 +174,3 @@ } | ||
if (this.isNodeType("Expression") && t.isStatement(replacement)) { | ||
if (this.isNodeType("Expression") && t().isStatement(replacement)) { | ||
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) { | ||
@@ -156,7 +181,7 @@ return this.replaceExpressionWithStatements([replacement]); | ||
var oldNode = this.node; | ||
const oldNode = this.node; | ||
if (oldNode) { | ||
t.inheritsComments(replacement, oldNode); | ||
t.removeComments(oldNode); | ||
t().inheritsComments(replacement, oldNode); | ||
t().removeComments(oldNode); | ||
} | ||
@@ -178,8 +203,8 @@ | ||
if (this.inList) { | ||
t.validate(this.parent, this.key, [node]); | ||
t().validate(this.parent, this.key, [node]); | ||
} else { | ||
t.validate(this.parent, this.key, node); | ||
t().validate(this.parent, this.key, node); | ||
} | ||
this.debug("Replace with " + (node && node.type)); | ||
this.debug(`Replace with ${node && node.type}`); | ||
this.node = this.container[this.key] = node; | ||
@@ -190,3 +215,3 @@ } | ||
this.resync(); | ||
var toSequenceExpression = t.toSequenceExpression(nodes, this.scope); | ||
const toSequenceExpression = t().toSequenceExpression(nodes, this.scope); | ||
@@ -197,48 +222,30 @@ if (toSequenceExpression) { | ||
var container = t.arrowFunctionExpression([], t.blockStatement(nodes)); | ||
this.replaceWith(t.callExpression(container, [])); | ||
const container = t().arrowFunctionExpression([], t().blockStatement(nodes)); | ||
this.replaceWith(t().callExpression(container, [])); | ||
this.traverse(hoistVariablesVisitor); | ||
var completionRecords = this.get("callee").getCompletionRecords(); | ||
const completionRecords = this.get("callee").getCompletionRecords(); | ||
for (var _iterator = completionRecords, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
for (const path of completionRecords) { | ||
if (!path.isExpressionStatement()) continue; | ||
const loop = path.findParent(path => path.isLoop()); | ||
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"); | ||
let 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))); | ||
const 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); | ||
uid = t().identifier(uid.name); | ||
} | ||
_path.get("expression").replaceWith(t.assignmentExpression("=", t.cloneNode(uid), _path.node.expression)); | ||
path.get("expression").replaceWith(t().assignmentExpression("=", t().cloneNode(uid), path.node.expression)); | ||
} else { | ||
_path.replaceWith(t.returnStatement(_path.node.expression)); | ||
path.replaceWith(t().returnStatement(path.node.expression)); | ||
} | ||
} | ||
var callee = this.get("callee"); | ||
const callee = this.get("callee"); | ||
callee.arrowFunctionToExpression(); | ||
@@ -255,3 +262,3 @@ return callee.get("body.body"); | ||
var paths = this._containerInsertAfter(nodes); | ||
const paths = this._containerInsertAfter(nodes); | ||
@@ -258,0 +265,0 @@ this.remove(); |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var Binding = function () { | ||
function Binding(_ref) { | ||
var identifier = _ref.identifier, | ||
scope = _ref.scope, | ||
path = _ref.path, | ||
kind = _ref.kind; | ||
class Binding { | ||
constructor({ | ||
identifier, | ||
scope, | ||
path, | ||
kind | ||
}) { | ||
this.identifier = identifier; | ||
@@ -24,22 +27,20 @@ this.scope = scope; | ||
var _proto = Binding.prototype; | ||
_proto.deoptValue = function deoptValue() { | ||
deoptValue() { | ||
this.clearValue(); | ||
this.hasDeoptedValue = true; | ||
}; | ||
} | ||
_proto.setValue = function setValue(value) { | ||
setValue(value) { | ||
if (this.hasDeoptedValue) return; | ||
this.hasValue = true; | ||
this.value = value; | ||
}; | ||
} | ||
_proto.clearValue = function clearValue() { | ||
clearValue() { | ||
this.hasDeoptedValue = false; | ||
this.hasValue = false; | ||
this.value = null; | ||
}; | ||
} | ||
_proto.reassign = function reassign(path) { | ||
reassign(path) { | ||
this.constant = false; | ||
@@ -52,5 +53,5 @@ | ||
this.constantViolations.push(path); | ||
}; | ||
} | ||
_proto.reference = function reference(path) { | ||
reference(path) { | ||
if (this.referencePaths.indexOf(path) !== -1) { | ||
@@ -63,12 +64,11 @@ return; | ||
this.referencePaths.push(path); | ||
}; | ||
} | ||
_proto.dereference = function dereference() { | ||
dereference() { | ||
this.references--; | ||
this.referenced = !!this.references; | ||
}; | ||
} | ||
return Binding; | ||
}(); | ||
} | ||
exports.default = Binding; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _includes = _interopRequireDefault(require("lodash/includes")); | ||
function _includes() { | ||
const data = _interopRequireDefault(require("lodash/includes")); | ||
var _repeat = _interopRequireDefault(require("lodash/repeat")); | ||
_includes = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _repeat() { | ||
const data = _interopRequireDefault(require("lodash/repeat")); | ||
_repeat = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _renamer = _interopRequireDefault(require("./lib/renamer")); | ||
@@ -14,10 +32,34 @@ | ||
var _defaults = _interopRequireDefault(require("lodash/defaults")); | ||
function _defaults() { | ||
const data = _interopRequireDefault(require("lodash/defaults")); | ||
var _binding2 = _interopRequireDefault(require("./binding")); | ||
_defaults = function () { | ||
return data; | ||
}; | ||
var _globals = _interopRequireDefault(require("globals")); | ||
return data; | ||
} | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
var _binding = _interopRequireDefault(require("./binding")); | ||
function _globals() { | ||
const data = _interopRequireDefault(require("globals")); | ||
_globals = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _cache = require("../cache"); | ||
@@ -29,15 +71,8 @@ | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function gatherNodeParts(node, parts) { | ||
if (t.isModuleDeclaration(node)) { | ||
if (t().isModuleDeclaration(node)) { | ||
if (node.source) { | ||
gatherNodeParts(node.source, parts); | ||
} else if (node.specifiers && node.specifiers.length) { | ||
var _arr = node.specifiers; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var specifier = _arr[_i]; | ||
for (const specifier of node.specifiers) { | ||
gatherNodeParts(specifier, parts); | ||
@@ -48,18 +83,15 @@ } | ||
} | ||
} else if (t.isModuleSpecifier(node)) { | ||
} else if (t().isModuleSpecifier(node)) { | ||
gatherNodeParts(node.local, parts); | ||
} else if (t.isMemberExpression(node)) { | ||
} else if (t().isMemberExpression(node)) { | ||
gatherNodeParts(node.object, parts); | ||
gatherNodeParts(node.property, parts); | ||
} else if (t.isIdentifier(node)) { | ||
} else if (t().isIdentifier(node)) { | ||
parts.push(node.name); | ||
} else if (t.isLiteral(node)) { | ||
} else if (t().isLiteral(node)) { | ||
parts.push(node.value); | ||
} else if (t.isCallExpression(node)) { | ||
} else if (t().isCallExpression(node)) { | ||
gatherNodeParts(node.callee, parts); | ||
} else if (t.isObjectExpression(node) || t.isObjectPattern(node)) { | ||
var _arr2 = node.properties; | ||
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | ||
var prop = _arr2[_i2]; | ||
} else if (t().isObjectExpression(node) || t().isObjectPattern(node)) { | ||
for (const prop of node.properties) { | ||
gatherNodeParts(prop.key || prop.argument, parts); | ||
@@ -70,12 +102,9 @@ } | ||
var collectorVisitor = { | ||
For: function For(path) { | ||
var _arr3 = t.FOR_INIT_KEYS; | ||
const collectorVisitor = { | ||
For(path) { | ||
for (const key of t().FOR_INIT_KEYS) { | ||
const declar = path.get(key); | ||
for (var _i3 = 0; _i3 < _arr3.length; _i3++) { | ||
var key = _arr3[_i3]; | ||
var declar = path.get(key); | ||
if (declar.isVar()) { | ||
var parentScope = path.scope.getFunctionParent() || path.scope.getProgramParent(); | ||
const parentScope = path.scope.getFunctionParent() || path.scope.getProgramParent(); | ||
parentScope.registerBinding("var", declar); | ||
@@ -85,3 +114,4 @@ } | ||
}, | ||
Declaration: function Declaration(path) { | ||
Declaration(path) { | ||
if (path.isBlockScoped()) return; | ||
@@ -93,11 +123,13 @@ | ||
var parent = path.scope.getFunctionParent() || path.scope.getProgramParent(); | ||
const parent = path.scope.getFunctionParent() || path.scope.getProgramParent(); | ||
parent.registerDeclaration(path); | ||
}, | ||
ReferencedIdentifier: function ReferencedIdentifier(path, state) { | ||
ReferencedIdentifier(path, state) { | ||
state.references.push(path); | ||
}, | ||
ForXStatement: function ForXStatement(path, state) { | ||
var left = path.get("left"); | ||
ForXStatement(path, state) { | ||
const left = path.get("left"); | ||
if (left.isPattern() || left.isIdentifier()) { | ||
@@ -107,24 +139,23 @@ state.constantViolations.push(path); | ||
}, | ||
ExportDeclaration: { | ||
exit: function exit(path) { | ||
var node = path.node, | ||
scope = path.scope; | ||
var declar = node.declaration; | ||
exit(path) { | ||
const { | ||
node, | ||
scope | ||
} = path; | ||
const declar = node.declaration; | ||
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) { | ||
var _id = declar.id; | ||
if (!_id) return; | ||
var binding = scope.getBinding(_id.name); | ||
if (t().isClassDeclaration(declar) || t().isFunctionDeclaration(declar)) { | ||
const id = declar.id; | ||
if (!id) return; | ||
const binding = scope.getBinding(id.name); | ||
if (binding) binding.reference(path); | ||
} else if (t.isVariableDeclaration(declar)) { | ||
var _arr4 = declar.declarations; | ||
} else if (t().isVariableDeclaration(declar)) { | ||
for (const decl of declar.declarations) { | ||
const ids = t().getBindingIdentifiers(decl); | ||
for (var _i4 = 0; _i4 < _arr4.length; _i4++) { | ||
var decl = _arr4[_i4]; | ||
var ids = t.getBindingIdentifiers(decl); | ||
for (var name in ids) { | ||
var _binding = scope.getBinding(name); | ||
if (_binding) _binding.reference(path); | ||
for (const name in ids) { | ||
const binding = scope.getBinding(name); | ||
if (binding) binding.reference(path); | ||
} | ||
@@ -134,14 +165,19 @@ } | ||
} | ||
}, | ||
LabeledStatement: function LabeledStatement(path) { | ||
LabeledStatement(path) { | ||
path.scope.getProgramParent().addGlobal(path.node); | ||
path.scope.getBlockParent().registerDeclaration(path); | ||
}, | ||
AssignmentExpression: function AssignmentExpression(path, state) { | ||
AssignmentExpression(path, state) { | ||
state.assignments.push(path); | ||
}, | ||
UpdateExpression: function UpdateExpression(path, state) { | ||
UpdateExpression(path, state) { | ||
state.constantViolations.push(path); | ||
}, | ||
UnaryExpression: function UnaryExpression(path, state) { | ||
UnaryExpression(path, state) { | ||
if (path.node.operator === "delete") { | ||
@@ -151,20 +187,20 @@ state.constantViolations.push(path); | ||
}, | ||
BlockScoped: function BlockScoped(path) { | ||
var scope = path.scope; | ||
BlockScoped(path) { | ||
let scope = path.scope; | ||
if (scope.path === path) scope = scope.parent; | ||
scope.getBlockParent().registerDeclaration(path); | ||
}, | ||
ClassDeclaration: function ClassDeclaration(path) { | ||
var id = path.node.id; | ||
ClassDeclaration(path) { | ||
const id = path.node.id; | ||
if (!id) return; | ||
var name = id.name; | ||
const name = id.name; | ||
path.scope.bindings[name] = path.scope.getBinding(name); | ||
}, | ||
Block: function Block(path) { | ||
var paths = path.get("body"); | ||
var _arr5 = paths; | ||
for (var _i5 = 0; _i5 < _arr5.length; _i5++) { | ||
var bodyPath = _arr5[_i5]; | ||
Block(path) { | ||
const paths = path.get("body"); | ||
for (const bodyPath of paths) { | ||
if (bodyPath.isFunctionDeclaration()) { | ||
@@ -175,10 +211,13 @@ path.scope.getBlockParent().registerDeclaration(bodyPath); | ||
} | ||
}; | ||
var uid = 0; | ||
let uid = 0; | ||
var Scope = function () { | ||
function Scope(path) { | ||
var node = path.node; | ||
class Scope { | ||
constructor(path) { | ||
const { | ||
node | ||
} = path; | ||
var cached = _cache.scope.get(node); | ||
const cached = _cache.scope.get(node); | ||
@@ -197,29 +236,36 @@ if (cached && cached.path === path) { | ||
var _proto = Scope.prototype; | ||
get parent() { | ||
const parent = this.path.findParent(p => p.isScope()); | ||
return parent && parent.scope; | ||
} | ||
_proto.traverse = function traverse(node, opts, state) { | ||
get parentBlock() { | ||
return this.path.parent; | ||
} | ||
get hub() { | ||
return this.path.hub; | ||
} | ||
traverse(node, opts, state) { | ||
(0, _index.default)(node, opts, this, state, this.path); | ||
}; | ||
} | ||
_proto.generateDeclaredUidIdentifier = function generateDeclaredUidIdentifier(name) { | ||
var id = this.generateUidIdentifier(name); | ||
generateDeclaredUidIdentifier(name) { | ||
const id = this.generateUidIdentifier(name); | ||
this.push({ | ||
id: id | ||
id | ||
}); | ||
return t.cloneNode(id); | ||
}; | ||
return t().cloneNode(id); | ||
} | ||
_proto.generateUidIdentifier = function generateUidIdentifier(name) { | ||
return t.identifier(this.generateUid(name)); | ||
}; | ||
generateUidIdentifier(name) { | ||
return t().identifier(this.generateUid(name)); | ||
} | ||
_proto.generateUid = function generateUid(name) { | ||
if (name === void 0) { | ||
name = "temp"; | ||
} | ||
generateUid(name = "temp") { | ||
name = t().toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, ""); | ||
let uid; | ||
let i = 0; | ||
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, ""); | ||
var uid; | ||
var i = 0; | ||
do { | ||
@@ -230,43 +276,43 @@ uid = this._generateUid(name, i); | ||
var program = this.getProgramParent(); | ||
const program = this.getProgramParent(); | ||
program.references[uid] = true; | ||
program.uids[uid] = true; | ||
return uid; | ||
}; | ||
} | ||
_proto._generateUid = function _generateUid(name, i) { | ||
var id = name; | ||
_generateUid(name, i) { | ||
let id = name; | ||
if (i > 1) id += i; | ||
return "_" + id; | ||
}; | ||
return `_${id}`; | ||
} | ||
_proto.generateUidBasedOnNode = function generateUidBasedOnNode(parent, defaultName) { | ||
var node = parent; | ||
generateUidBasedOnNode(parent, defaultName) { | ||
let node = parent; | ||
if (t.isAssignmentExpression(parent)) { | ||
if (t().isAssignmentExpression(parent)) { | ||
node = parent.left; | ||
} else if (t.isVariableDeclarator(parent)) { | ||
} else if (t().isVariableDeclarator(parent)) { | ||
node = parent.id; | ||
} else if (t.isObjectProperty(node) || t.isObjectMethod(node)) { | ||
} else if (t().isObjectProperty(node) || t().isObjectMethod(node)) { | ||
node = node.key; | ||
} | ||
var parts = []; | ||
const parts = []; | ||
gatherNodeParts(node, parts); | ||
var id = parts.join("$"); | ||
let id = parts.join("$"); | ||
id = id.replace(/^_/, "") || defaultName || "ref"; | ||
return this.generateUid(id.slice(0, 20)); | ||
}; | ||
} | ||
_proto.generateUidIdentifierBasedOnNode = function generateUidIdentifierBasedOnNode(parent, defaultName) { | ||
return t.identifier(this.generateUidBasedOnNode(parent, defaultName)); | ||
}; | ||
generateUidIdentifierBasedOnNode(parent, defaultName) { | ||
return t().identifier(this.generateUidBasedOnNode(parent, defaultName)); | ||
} | ||
_proto.isStatic = function isStatic(node) { | ||
if (t.isThisExpression(node) || t.isSuper(node)) { | ||
isStatic(node) { | ||
if (t().isThisExpression(node) || t().isSuper(node)) { | ||
return true; | ||
} | ||
if (t.isIdentifier(node)) { | ||
var binding = this.getBinding(node.name); | ||
if (t().isIdentifier(node)) { | ||
const binding = this.getBinding(node.name); | ||
@@ -281,34 +327,34 @@ if (binding) { | ||
return false; | ||
}; | ||
} | ||
_proto.maybeGenerateMemoised = function maybeGenerateMemoised(node, dontPush) { | ||
maybeGenerateMemoised(node, dontPush) { | ||
if (this.isStatic(node)) { | ||
return null; | ||
} else { | ||
var _id2 = this.generateUidIdentifierBasedOnNode(node); | ||
const id = this.generateUidIdentifierBasedOnNode(node); | ||
if (!dontPush) { | ||
this.push({ | ||
id: _id2 | ||
id | ||
}); | ||
return t.cloneNode(_id2); | ||
return t().cloneNode(id); | ||
} | ||
return _id2; | ||
return id; | ||
} | ||
}; | ||
} | ||
_proto.checkBlockScopedCollisions = function checkBlockScopedCollisions(local, kind, name, id) { | ||
checkBlockScopedCollisions(local, kind, name, id) { | ||
if (kind === "param") return; | ||
if (local.kind === "local") return; | ||
if (kind === "hoisted" && local.kind === "let") return; | ||
var duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const"); | ||
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && (kind === "let" || kind === "const"); | ||
if (duplicate) { | ||
throw this.hub.file.buildCodeFrameError(id, "Duplicate declaration \"" + name + "\"", TypeError); | ||
throw this.hub.file.buildCodeFrameError(id, `Duplicate declaration "${name}"`, TypeError); | ||
} | ||
}; | ||
} | ||
_proto.rename = function rename(oldName, newName, block) { | ||
var binding = this.getBinding(oldName); | ||
rename(oldName, newName, block) { | ||
const binding = this.getBinding(oldName); | ||
@@ -319,5 +365,5 @@ if (binding) { | ||
} | ||
}; | ||
} | ||
_proto._renameFromMap = function _renameFromMap(map, oldName, newName, value) { | ||
_renameFromMap(map, oldName, newName, value) { | ||
if (map[oldName]) { | ||
@@ -327,8 +373,8 @@ map[newName] = value; | ||
} | ||
}; | ||
} | ||
_proto.dump = function dump() { | ||
var sep = (0, _repeat.default)("-", 60); | ||
dump() { | ||
const sep = (0, _repeat().default)("-", 60); | ||
console.log(sep); | ||
var scope = this; | ||
let scope = this; | ||
@@ -338,4 +384,4 @@ do { | ||
for (var name in scope.bindings) { | ||
var binding = scope.bindings[name]; | ||
for (const name in scope.bindings) { | ||
const binding = scope.bindings[name]; | ||
console.log(" -", name, { | ||
@@ -351,9 +397,9 @@ constant: binding.constant, | ||
console.log(sep); | ||
}; | ||
} | ||
_proto.toArray = function toArray(node, i) { | ||
var file = this.hub.file; | ||
toArray(node, i) { | ||
const file = this.hub.file; | ||
if (t.isIdentifier(node)) { | ||
var binding = this.getBinding(node.name); | ||
if (t().isIdentifier(node)) { | ||
const binding = this.getBinding(node.name); | ||
@@ -365,14 +411,14 @@ if (binding && binding.constant && binding.path.isGenericType("Array")) { | ||
if (t.isArrayExpression(node)) { | ||
if (t().isArrayExpression(node)) { | ||
return node; | ||
} | ||
if (t.isIdentifier(node, { | ||
if (t().isIdentifier(node, { | ||
name: "arguments" | ||
})) { | ||
return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier("Array"), t.identifier("prototype")), t.identifier("slice")), t.identifier("call")), [node]); | ||
return t().callExpression(t().memberExpression(t().memberExpression(t().memberExpression(t().identifier("Array"), t().identifier("prototype")), t().identifier("slice")), t().identifier("call")), [node]); | ||
} | ||
var helperName; | ||
var args = [node]; | ||
let helperName; | ||
const args = [node]; | ||
@@ -382,3 +428,3 @@ if (i === true) { | ||
} else if (i) { | ||
args.push(t.numericLiteral(i)); | ||
args.push(t().numericLiteral(i)); | ||
helperName = "slicedToArray"; | ||
@@ -389,18 +435,18 @@ } else { | ||
return t.callExpression(file.addHelper(helperName), args); | ||
}; | ||
return t().callExpression(file.addHelper(helperName), args); | ||
} | ||
_proto.hasLabel = function hasLabel(name) { | ||
hasLabel(name) { | ||
return !!this.getLabel(name); | ||
}; | ||
} | ||
_proto.getLabel = function getLabel(name) { | ||
getLabel(name) { | ||
return this.labels.get(name); | ||
}; | ||
} | ||
_proto.registerLabel = function registerLabel(path) { | ||
registerLabel(path) { | ||
this.labels.set(path.node.label.name, path); | ||
}; | ||
} | ||
_proto.registerDeclaration = function registerDeclaration(path) { | ||
registerDeclaration(path) { | ||
if (path.isFlow()) return; | ||
@@ -413,7 +459,5 @@ | ||
} else if (path.isVariableDeclaration()) { | ||
var declarations = path.get("declarations"); | ||
var _arr6 = declarations; | ||
const declarations = path.get("declarations"); | ||
for (var _i6 = 0; _i6 < _arr6.length; _i6++) { | ||
var declar = _arr6[_i6]; | ||
for (const declar of declarations) { | ||
this.registerBinding(path.node.kind, declar); | ||
@@ -424,14 +468,12 @@ } | ||
} else if (path.isImportDeclaration()) { | ||
var specifiers = path.get("specifiers"); | ||
var _arr7 = specifiers; | ||
const specifiers = path.get("specifiers"); | ||
for (var _i7 = 0; _i7 < _arr7.length; _i7++) { | ||
var specifier = _arr7[_i7]; | ||
for (const specifier of specifiers) { | ||
this.registerBinding("module", specifier); | ||
} | ||
} else if (path.isExportDeclaration()) { | ||
var _declar = path.get("declaration"); | ||
const declar = path.get("declaration"); | ||
if (_declar.isClassDeclaration() || _declar.isFunctionDeclaration() || _declar.isVariableDeclaration()) { | ||
this.registerDeclaration(_declar); | ||
if (declar.isClassDeclaration() || declar.isFunctionDeclaration() || declar.isVariableDeclaration()) { | ||
this.registerDeclaration(declar); | ||
} | ||
@@ -441,45 +483,29 @@ } else { | ||
} | ||
}; | ||
} | ||
_proto.buildUndefinedNode = function buildUndefinedNode() { | ||
buildUndefinedNode() { | ||
if (this.hasBinding("undefined")) { | ||
return t.unaryExpression("void", t.numericLiteral(0), true); | ||
return t().unaryExpression("void", t().numericLiteral(0), true); | ||
} else { | ||
return t.identifier("undefined"); | ||
return t().identifier("undefined"); | ||
} | ||
}; | ||
} | ||
_proto.registerConstantViolation = function registerConstantViolation(path) { | ||
var ids = path.getBindingIdentifiers(); | ||
registerConstantViolation(path) { | ||
const ids = path.getBindingIdentifiers(); | ||
for (var name in ids) { | ||
var binding = this.getBinding(name); | ||
for (const name in ids) { | ||
const binding = this.getBinding(name); | ||
if (binding) binding.reassign(path); | ||
} | ||
}; | ||
} | ||
_proto.registerBinding = function registerBinding(kind, path, bindingPath) { | ||
if (bindingPath === void 0) { | ||
bindingPath = path; | ||
} | ||
registerBinding(kind, path, bindingPath = path) { | ||
if (!kind) throw new ReferenceError("no `kind`"); | ||
if (path.isVariableDeclaration()) { | ||
var declarators = path.get("declarations"); | ||
const declarators = path.get("declarations"); | ||
for (var _iterator = declarators, _isArray = Array.isArray(_iterator), _i8 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i8 >= _iterator.length) break; | ||
_ref = _iterator[_i8++]; | ||
} else { | ||
_i8 = _iterator.next(); | ||
if (_i8.done) break; | ||
_ref = _i8.value; | ||
} | ||
var _declar2 = _ref; | ||
this.registerBinding(kind, _declar2); | ||
for (const declar of declarators) { | ||
this.registerBinding(kind, declar); | ||
} | ||
@@ -490,15 +516,12 @@ | ||
var parent = this.getProgramParent(); | ||
var ids = path.getBindingIdentifiers(true); | ||
const parent = this.getProgramParent(); | ||
const ids = path.getBindingIdentifiers(true); | ||
for (var name in ids) { | ||
var _arr8 = ids[name]; | ||
for (const name in ids) { | ||
for (const id of ids[name]) { | ||
const local = this.getOwnBinding(name); | ||
for (var _i9 = 0; _i9 < _arr8.length; _i9++) { | ||
var _id3 = _arr8[_i9]; | ||
var local = this.getOwnBinding(name); | ||
if (local) { | ||
if (local.identifier === _id3) continue; | ||
this.checkBlockScopedCollisions(local, kind, name, _id3); | ||
if (local.identifier === id) continue; | ||
this.checkBlockScopedCollisions(local, kind, name, id); | ||
} | ||
@@ -511,4 +534,4 @@ | ||
} else { | ||
this.bindings[name] = new _binding2.default({ | ||
identifier: _id3, | ||
this.bindings[name] = new _binding.default({ | ||
identifier: id, | ||
scope: this, | ||
@@ -521,10 +544,10 @@ path: bindingPath, | ||
} | ||
}; | ||
} | ||
_proto.addGlobal = function addGlobal(node) { | ||
addGlobal(node) { | ||
this.globals[node.name] = node; | ||
}; | ||
} | ||
_proto.hasUid = function hasUid(name) { | ||
var scope = this; | ||
hasUid(name) { | ||
let scope = this; | ||
@@ -536,6 +559,6 @@ do { | ||
return false; | ||
}; | ||
} | ||
_proto.hasGlobal = function hasGlobal(name) { | ||
var scope = this; | ||
hasGlobal(name) { | ||
let scope = this; | ||
@@ -547,6 +570,6 @@ do { | ||
return false; | ||
}; | ||
} | ||
_proto.hasReference = function hasReference(name) { | ||
var scope = this; | ||
hasReference(name) { | ||
let scope = this; | ||
@@ -558,11 +581,11 @@ do { | ||
return false; | ||
}; | ||
} | ||
_proto.isPure = function isPure(node, constantsOnly) { | ||
if (t.isIdentifier(node)) { | ||
var binding = this.getBinding(node.name); | ||
isPure(node, constantsOnly) { | ||
if (t().isIdentifier(node)) { | ||
const binding = this.getBinding(node.name); | ||
if (!binding) return false; | ||
if (constantsOnly) return binding.constant; | ||
return true; | ||
} else if (t.isClass(node)) { | ||
} else if (t().isClass(node)) { | ||
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) { | ||
@@ -573,27 +596,12 @@ return false; | ||
return this.isPure(node.body, constantsOnly); | ||
} else if (t.isClassBody(node)) { | ||
for (var _iterator2 = node.body, _isArray2 = Array.isArray(_iterator2), _i10 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i10 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i10++]; | ||
} else { | ||
_i10 = _iterator2.next(); | ||
if (_i10.done) break; | ||
_ref2 = _i10.value; | ||
} | ||
var _method = _ref2; | ||
if (!this.isPure(_method, constantsOnly)) return false; | ||
} else if (t().isClassBody(node)) { | ||
for (const method of node.body) { | ||
if (!this.isPure(method, constantsOnly)) return false; | ||
} | ||
return true; | ||
} else if (t.isBinary(node)) { | ||
} else if (t().isBinary(node)) { | ||
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly); | ||
} else if (t.isArrayExpression(node)) { | ||
var _arr9 = node.elements; | ||
for (var _i11 = 0; _i11 < _arr9.length; _i11++) { | ||
var elem = _arr9[_i11]; | ||
} else if (t().isArrayExpression(node)) { | ||
for (const elem of node.elements) { | ||
if (!this.isPure(elem, constantsOnly)) return false; | ||
@@ -603,7 +611,4 @@ } | ||
return true; | ||
} else if (t.isObjectExpression(node)) { | ||
var _arr10 = node.properties; | ||
for (var _i12 = 0; _i12 < _arr10.length; _i12++) { | ||
var prop = _arr10[_i12]; | ||
} else if (t().isObjectExpression(node)) { | ||
for (const prop of node.properties) { | ||
if (!this.isPure(prop, constantsOnly)) return false; | ||
@@ -613,18 +618,15 @@ } | ||
return true; | ||
} else if (t.isClassMethod(node)) { | ||
} else if (t().isClassMethod(node)) { | ||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false; | ||
if (node.kind === "get" || node.kind === "set") return false; | ||
return true; | ||
} else if (t.isClassProperty(node) || t.isObjectProperty(node)) { | ||
} else if (t().isClassProperty(node) || t().isObjectProperty(node)) { | ||
if (node.computed && !this.isPure(node.key, constantsOnly)) return false; | ||
return this.isPure(node.value, constantsOnly); | ||
} else if (t.isUnaryExpression(node)) { | ||
} else if (t().isUnaryExpression(node)) { | ||
return this.isPure(node.argument, constantsOnly); | ||
} else if (t.isTaggedTemplateExpression(node)) { | ||
return t.matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly); | ||
} else if (t.isTemplateLiteral(node)) { | ||
var _arr11 = node.expressions; | ||
for (var _i13 = 0; _i13 < _arr11.length; _i13++) { | ||
var expression = _arr11[_i13]; | ||
} else if (t().isTaggedTemplateExpression(node)) { | ||
return t().matchesPattern(node.tag, "String.raw") && !this.hasBinding("String", true) && this.isPure(node.quasi, constantsOnly); | ||
} else if (t().isTemplateLiteral(node)) { | ||
for (const expression of node.expressions) { | ||
if (!this.isPure(expression, constantsOnly)) return false; | ||
@@ -635,34 +637,34 @@ } | ||
} else { | ||
return t.isPureish(node); | ||
return t().isPureish(node); | ||
} | ||
}; | ||
} | ||
_proto.setData = function setData(key, val) { | ||
setData(key, val) { | ||
return this.data[key] = val; | ||
}; | ||
} | ||
_proto.getData = function getData(key) { | ||
var scope = this; | ||
getData(key) { | ||
let scope = this; | ||
do { | ||
var data = scope.data[key]; | ||
const data = scope.data[key]; | ||
if (data != null) return data; | ||
} while (scope = scope.parent); | ||
}; | ||
} | ||
_proto.removeData = function removeData(key) { | ||
var scope = this; | ||
removeData(key) { | ||
let scope = this; | ||
do { | ||
var data = scope.data[key]; | ||
const data = scope.data[key]; | ||
if (data != null) scope.data[key] = null; | ||
} while (scope = scope.parent); | ||
}; | ||
} | ||
_proto.init = function init() { | ||
init() { | ||
if (!this.references) this.crawl(); | ||
}; | ||
} | ||
_proto.crawl = function crawl() { | ||
var path = this.path; | ||
crawl() { | ||
const path = this.path; | ||
this.references = Object.create(null); | ||
@@ -675,7 +677,4 @@ this.bindings = Object.create(null); | ||
if (path.isLoop()) { | ||
var _arr12 = t.FOR_INIT_KEYS; | ||
for (var _i14 = 0; _i14 < _arr12.length; _i14++) { | ||
var key = _arr12[_i14]; | ||
var node = path.get(key); | ||
for (const key of t().FOR_INIT_KEYS) { | ||
const node = path.get(key); | ||
if (node.isBlockScoped()) this.registerBinding(node.node.kind, node); | ||
@@ -686,3 +685,3 @@ } | ||
if (path.isFunctionExpression() && path.has("id")) { | ||
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) { | ||
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) { | ||
this.registerBinding("local", path.get("id"), path); | ||
@@ -693,3 +692,3 @@ } | ||
if (path.isClassExpression() && path.has("id")) { | ||
if (!path.get("id").node[t.NOT_LOCAL_BINDING]) { | ||
if (!path.get("id").node[t().NOT_LOCAL_BINDING]) { | ||
this.registerBinding("local", path); | ||
@@ -700,18 +699,6 @@ } | ||
if (path.isFunction()) { | ||
var params = path.get("params"); | ||
const params = path.get("params"); | ||
for (var _iterator3 = params, _isArray3 = Array.isArray(_iterator3), _i15 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray3) { | ||
if (_i15 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i15++]; | ||
} else { | ||
_i15 = _iterator3.next(); | ||
if (_i15.done) break; | ||
_ref3 = _i15.value; | ||
} | ||
var _param = _ref3; | ||
this.registerBinding("param", _param); | ||
for (const param of params) { | ||
this.registerBinding("param", param); | ||
} | ||
@@ -724,5 +711,5 @@ } | ||
var parent = this.getProgramParent(); | ||
const parent = this.getProgramParent(); | ||
if (parent.crawling) return; | ||
var state = { | ||
const state = { | ||
references: [], | ||
@@ -736,72 +723,32 @@ constantViolations: [], | ||
for (var _iterator4 = state.assignments, _isArray4 = Array.isArray(_iterator4), _i16 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
for (const path of state.assignments) { | ||
const ids = path.getBindingIdentifiers(); | ||
let programParent; | ||
if (_isArray4) { | ||
if (_i16 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i16++]; | ||
} else { | ||
_i16 = _iterator4.next(); | ||
if (_i16.done) break; | ||
_ref4 = _i16.value; | ||
} | ||
var _path3 = _ref4; | ||
var ids = _path3.getBindingIdentifiers(); | ||
var programParent = void 0; | ||
for (var name in ids) { | ||
if (_path3.scope.getBinding(name)) continue; | ||
programParent = programParent || _path3.scope.getProgramParent(); | ||
for (const name in ids) { | ||
if (path.scope.getBinding(name)) continue; | ||
programParent = programParent || path.scope.getProgramParent(); | ||
programParent.addGlobal(ids[name]); | ||
} | ||
_path3.scope.registerConstantViolation(_path3); | ||
path.scope.registerConstantViolation(path); | ||
} | ||
for (var _iterator5 = state.references, _isArray5 = Array.isArray(_iterator5), _i17 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
for (const ref of state.references) { | ||
const binding = ref.scope.getBinding(ref.node.name); | ||
if (_isArray5) { | ||
if (_i17 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i17++]; | ||
} else { | ||
_i17 = _iterator5.next(); | ||
if (_i17.done) break; | ||
_ref5 = _i17.value; | ||
} | ||
var _ref7 = _ref5; | ||
var binding = _ref7.scope.getBinding(_ref7.node.name); | ||
if (binding) { | ||
binding.reference(_ref7); | ||
binding.reference(ref); | ||
} else { | ||
_ref7.scope.getProgramParent().addGlobal(_ref7.node); | ||
ref.scope.getProgramParent().addGlobal(ref.node); | ||
} | ||
} | ||
for (var _iterator6 = state.constantViolations, _isArray6 = Array.isArray(_iterator6), _i18 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray6) { | ||
if (_i18 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i18++]; | ||
} else { | ||
_i18 = _iterator6.next(); | ||
if (_i18.done) break; | ||
_ref6 = _i18.value; | ||
} | ||
var _path4 = _ref6; | ||
_path4.scope.registerConstantViolation(_path4); | ||
for (const path of state.constantViolations) { | ||
path.scope.registerConstantViolation(path); | ||
} | ||
}; | ||
} | ||
_proto.push = function push(opts) { | ||
var path = this.path; | ||
push(opts) { | ||
let path = this.path; | ||
@@ -821,25 +768,22 @@ if (!path.isBlockStatement() && !path.isProgram()) { | ||
var unique = opts.unique; | ||
var kind = opts.kind || "var"; | ||
var blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist; | ||
var dataKey = "declaration:" + kind + ":" + blockHoist; | ||
var declarPath = !unique && path.getData(dataKey); | ||
const unique = opts.unique; | ||
const kind = opts.kind || "var"; | ||
const blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist; | ||
const dataKey = `declaration:${kind}:${blockHoist}`; | ||
let declarPath = !unique && path.getData(dataKey); | ||
if (!declarPath) { | ||
var declar = t.variableDeclaration(kind, []); | ||
const declar = t().variableDeclaration(kind, []); | ||
declar._blockHoist = blockHoist; | ||
var _path$unshiftContaine = path.unshiftContainer("body", [declar]); | ||
declarPath = _path$unshiftContaine[0]; | ||
[declarPath] = path.unshiftContainer("body", [declar]); | ||
if (!unique) path.setData(dataKey, declarPath); | ||
} | ||
var declarator = t.variableDeclarator(opts.id, opts.init); | ||
const declarator = t().variableDeclarator(opts.id, opts.init); | ||
declarPath.node.declarations.push(declarator); | ||
this.registerBinding(kind, declarPath.get("declarations").pop()); | ||
}; | ||
} | ||
_proto.getProgramParent = function getProgramParent() { | ||
var scope = this; | ||
getProgramParent() { | ||
let scope = this; | ||
@@ -853,6 +797,6 @@ do { | ||
throw new Error("Couldn't find a Program"); | ||
}; | ||
} | ||
_proto.getFunctionParent = function getFunctionParent() { | ||
var scope = this; | ||
getFunctionParent() { | ||
let scope = this; | ||
@@ -866,6 +810,6 @@ do { | ||
return null; | ||
}; | ||
} | ||
_proto.getBlockParent = function getBlockParent() { | ||
var scope = this; | ||
getBlockParent() { | ||
let scope = this; | ||
@@ -879,10 +823,10 @@ do { | ||
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program..."); | ||
}; | ||
} | ||
_proto.getAllBindings = function getAllBindings() { | ||
var ids = Object.create(null); | ||
var scope = this; | ||
getAllBindings() { | ||
const ids = Object.create(null); | ||
let scope = this; | ||
do { | ||
(0, _defaults.default)(ids, scope.bindings); | ||
(0, _defaults().default)(ids, scope.bindings); | ||
scope = scope.parent; | ||
@@ -892,15 +836,13 @@ } while (scope); | ||
return ids; | ||
}; | ||
} | ||
_proto.getAllBindingsOfKind = function getAllBindingsOfKind() { | ||
var ids = Object.create(null); | ||
var _arr13 = arguments; | ||
getAllBindingsOfKind() { | ||
const ids = Object.create(null); | ||
for (var _i19 = 0; _i19 < _arr13.length; _i19++) { | ||
var kind = _arr13[_i19]; | ||
var scope = this; | ||
for (const kind of arguments) { | ||
let scope = this; | ||
do { | ||
for (var name in scope.bindings) { | ||
var binding = scope.bindings[name]; | ||
for (const name in scope.bindings) { | ||
const binding = scope.bindings[name]; | ||
if (binding.kind === kind) ids[name] = binding; | ||
@@ -914,36 +856,36 @@ } | ||
return ids; | ||
}; | ||
} | ||
_proto.bindingIdentifierEquals = function bindingIdentifierEquals(name, node) { | ||
bindingIdentifierEquals(name, node) { | ||
return this.getBindingIdentifier(name) === node; | ||
}; | ||
} | ||
_proto.getBinding = function getBinding(name) { | ||
var scope = this; | ||
getBinding(name) { | ||
let scope = this; | ||
do { | ||
var binding = scope.getOwnBinding(name); | ||
const binding = scope.getOwnBinding(name); | ||
if (binding) return binding; | ||
} while (scope = scope.parent); | ||
}; | ||
} | ||
_proto.getOwnBinding = function getOwnBinding(name) { | ||
getOwnBinding(name) { | ||
return this.bindings[name]; | ||
}; | ||
} | ||
_proto.getBindingIdentifier = function getBindingIdentifier(name) { | ||
var info = this.getBinding(name); | ||
getBindingIdentifier(name) { | ||
const info = this.getBinding(name); | ||
return info && info.identifier; | ||
}; | ||
} | ||
_proto.getOwnBindingIdentifier = function getOwnBindingIdentifier(name) { | ||
var binding = this.bindings[name]; | ||
getOwnBindingIdentifier(name) { | ||
const binding = this.bindings[name]; | ||
return binding && binding.identifier; | ||
}; | ||
} | ||
_proto.hasOwnBinding = function hasOwnBinding(name) { | ||
hasOwnBinding(name) { | ||
return !!this.getOwnBinding(name); | ||
}; | ||
} | ||
_proto.hasBinding = function hasBinding(name, noGlobals) { | ||
hasBinding(name, noGlobals) { | ||
if (!name) return false; | ||
@@ -953,13 +895,13 @@ if (this.hasOwnBinding(name)) return true; | ||
if (this.hasUid(name)) return true; | ||
if (!noGlobals && (0, _includes.default)(Scope.globals, name)) return true; | ||
if (!noGlobals && (0, _includes.default)(Scope.contextVariables, name)) return true; | ||
if (!noGlobals && (0, _includes().default)(Scope.globals, name)) return true; | ||
if (!noGlobals && (0, _includes().default)(Scope.contextVariables, name)) return true; | ||
return false; | ||
}; | ||
} | ||
_proto.parentHasBinding = function parentHasBinding(name, noGlobals) { | ||
parentHasBinding(name, noGlobals) { | ||
return this.parent && this.parent.hasBinding(name, noGlobals); | ||
}; | ||
} | ||
_proto.moveBindingTo = function moveBindingTo(name, scope) { | ||
var info = this.getBinding(name); | ||
moveBindingTo(name, scope) { | ||
const info = this.getBinding(name); | ||
@@ -971,10 +913,10 @@ if (info) { | ||
} | ||
}; | ||
} | ||
_proto.removeOwnBinding = function removeOwnBinding(name) { | ||
removeOwnBinding(name) { | ||
delete this.bindings[name]; | ||
}; | ||
} | ||
_proto.removeBinding = function removeBinding(name) { | ||
var info = this.getBinding(name); | ||
removeBinding(name) { | ||
const info = this.getBinding(name); | ||
@@ -985,3 +927,3 @@ if (info) { | ||
var scope = this; | ||
let scope = this; | ||
@@ -993,29 +935,8 @@ do { | ||
} while (scope = scope.parent); | ||
}; | ||
} | ||
_createClass(Scope, [{ | ||
key: "parent", | ||
get: function get() { | ||
var parent = this.path.findParent(function (p) { | ||
return p.isScope(); | ||
}); | ||
return parent && parent.scope; | ||
} | ||
}, { | ||
key: "parentBlock", | ||
get: function get() { | ||
return this.path.parent; | ||
} | ||
}, { | ||
key: "hub", | ||
get: function get() { | ||
return this.path.hub; | ||
} | ||
}]); | ||
} | ||
return Scope; | ||
}(); | ||
exports.default = Scope; | ||
Scope.globals = Object.keys(_globals.default.builtin); | ||
Scope.globals = Object.keys(_globals().default.builtin); | ||
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"]; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
@@ -8,6 +10,22 @@ | ||
var _helperSplitExportDeclaration = _interopRequireDefault(require("@babel/helper-split-export-declaration")); | ||
function _helperSplitExportDeclaration() { | ||
const data = _interopRequireDefault(require("@babel/helper-split-export-declaration")); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
_helperSplitExportDeclaration = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
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; } } | ||
@@ -17,6 +35,6 @@ | ||
var renameVisitor = { | ||
ReferencedIdentifier: function ReferencedIdentifier(_ref, state) { | ||
var node = _ref.node; | ||
const renameVisitor = { | ||
ReferencedIdentifier({ | ||
node | ||
}, state) { | ||
if (node.name === state.oldName) { | ||
@@ -26,3 +44,4 @@ node.name = state.newName; | ||
}, | ||
Scope: function Scope(path, state) { | ||
Scope(path, state) { | ||
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) { | ||
@@ -32,13 +51,15 @@ path.skip(); | ||
}, | ||
"AssignmentExpression|Declaration": function AssignmentExpressionDeclaration(path, state) { | ||
var ids = path.getOuterBindingIdentifiers(); | ||
for (var name in ids) { | ||
"AssignmentExpression|Declaration"(path, state) { | ||
const ids = path.getOuterBindingIdentifiers(); | ||
for (const name in ids) { | ||
if (name === state.oldName) ids[name].name = state.newName; | ||
} | ||
} | ||
}; | ||
var Renamer = function () { | ||
function Renamer(binding, oldName, newName) { | ||
class Renamer { | ||
constructor(binding, oldName, newName) { | ||
this.newName = newName; | ||
@@ -49,7 +70,5 @@ this.oldName = oldName; | ||
var _proto = Renamer.prototype; | ||
maybeConvertFromExportDeclaration(parentDeclar) { | ||
const maybeExportDeclar = parentDeclar.parentPath; | ||
_proto.maybeConvertFromExportDeclaration = function maybeConvertFromExportDeclaration(parentDeclar) { | ||
var maybeExportDeclar = parentDeclar.parentPath; | ||
if (!maybeExportDeclar.isExportDeclaration()) { | ||
@@ -63,34 +82,36 @@ return; | ||
(0, _helperSplitExportDeclaration.default)(maybeExportDeclar); | ||
}; | ||
(0, _helperSplitExportDeclaration().default)(maybeExportDeclar); | ||
} | ||
_proto.maybeConvertFromClassFunctionDeclaration = function maybeConvertFromClassFunctionDeclaration(path) { | ||
maybeConvertFromClassFunctionDeclaration(path) { | ||
return; | ||
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return; | ||
if (this.binding.kind !== "hoisted") return; | ||
path.node.id = t.identifier(this.oldName); | ||
path.node.id = t().identifier(this.oldName); | ||
path.node._blockHoist = 3; | ||
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(t.identifier(this.newName), t.toExpression(path.node))])); | ||
}; | ||
path.replaceWith(t().variableDeclaration("let", [t().variableDeclarator(t().identifier(this.newName), t().toExpression(path.node))])); | ||
} | ||
_proto.maybeConvertFromClassFunctionExpression = function maybeConvertFromClassFunctionExpression(path) { | ||
maybeConvertFromClassFunctionExpression(path) { | ||
return; | ||
if (!path.isFunctionExpression() && !path.isClassExpression()) return; | ||
if (this.binding.kind !== "local") return; | ||
path.node.id = t.identifier(this.oldName); | ||
path.node.id = t().identifier(this.oldName); | ||
this.binding.scope.parent.push({ | ||
id: t.identifier(this.newName) | ||
id: t().identifier(this.newName) | ||
}); | ||
path.replaceWith(t.assignmentExpression("=", t.identifier(this.newName), path.node)); | ||
}; | ||
path.replaceWith(t().assignmentExpression("=", t().identifier(this.newName), path.node)); | ||
} | ||
_proto.rename = function rename(block) { | ||
var binding = this.binding, | ||
oldName = this.oldName, | ||
newName = this.newName; | ||
var scope = binding.scope, | ||
path = binding.path; | ||
var parentDeclar = path.find(function (path) { | ||
return path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression(); | ||
}); | ||
rename(block) { | ||
const { | ||
binding, | ||
oldName, | ||
newName | ||
} = this; | ||
const { | ||
scope, | ||
path | ||
} = binding; | ||
const parentDeclar = path.find(path => path.isDeclaration() || path.isFunctionExpression() || path.isClassExpression()); | ||
@@ -115,7 +136,6 @@ if (parentDeclar) { | ||
} | ||
}; | ||
} | ||
return Renamer; | ||
}(); | ||
} | ||
exports.default = Renamer; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.explode = explode; | ||
@@ -10,6 +12,22 @@ exports.verify = verify; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var _clone = _interopRequireDefault(require("lodash/clone")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _clone() { | ||
const data = _interopRequireDefault(require("lodash/clone")); | ||
_clone = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -23,23 +41,11 @@ | ||
for (var nodeType in visitor) { | ||
for (const nodeType in visitor) { | ||
if (shouldIgnoreKey(nodeType)) continue; | ||
var parts = nodeType.split("|"); | ||
const parts = nodeType.split("|"); | ||
if (parts.length === 1) continue; | ||
var fns = visitor[nodeType]; | ||
const fns = visitor[nodeType]; | ||
delete visitor[nodeType]; | ||
for (var _iterator = parts, _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 _part = _ref; | ||
visitor[_part] = fns; | ||
for (const part of parts) { | ||
visitor[part] = fns; | ||
} | ||
@@ -53,42 +59,35 @@ } | ||
var _arr = Object.keys(visitor); | ||
for (var _i2 = 0; _i2 < _arr.length; _i2++) { | ||
var _nodeType = _arr[_i2]; | ||
if (shouldIgnoreKey(_nodeType)) continue; | ||
var wrapper = virtualTypes[_nodeType]; | ||
for (const nodeType of Object.keys(visitor)) { | ||
if (shouldIgnoreKey(nodeType)) continue; | ||
const wrapper = virtualTypes[nodeType]; | ||
if (!wrapper) continue; | ||
var _fns = visitor[_nodeType]; | ||
const fns = visitor[nodeType]; | ||
for (var type in _fns) { | ||
_fns[type] = wrapCheck(wrapper, _fns[type]); | ||
for (const type in fns) { | ||
fns[type] = wrapCheck(wrapper, fns[type]); | ||
} | ||
delete visitor[_nodeType]; | ||
delete visitor[nodeType]; | ||
if (wrapper.types) { | ||
var _arr2 = wrapper.types; | ||
for (var _i4 = 0; _i4 < _arr2.length; _i4++) { | ||
var _type = _arr2[_i4]; | ||
if (visitor[_type]) { | ||
mergePair(visitor[_type], _fns); | ||
for (const type of wrapper.types) { | ||
if (visitor[type]) { | ||
mergePair(visitor[type], fns); | ||
} else { | ||
visitor[_type] = _fns; | ||
visitor[type] = fns; | ||
} | ||
} | ||
} else { | ||
mergePair(visitor, _fns); | ||
mergePair(visitor, fns); | ||
} | ||
} | ||
for (var _nodeType2 in visitor) { | ||
if (shouldIgnoreKey(_nodeType2)) continue; | ||
var _fns2 = visitor[_nodeType2]; | ||
var aliases = t.FLIPPED_ALIAS_KEYS[_nodeType2]; | ||
var deprecratedKey = t.DEPRECATED_KEYS[_nodeType2]; | ||
for (const nodeType in visitor) { | ||
if (shouldIgnoreKey(nodeType)) continue; | ||
const fns = visitor[nodeType]; | ||
let aliases = t().FLIPPED_ALIAS_KEYS[nodeType]; | ||
const deprecratedKey = t().DEPRECATED_KEYS[nodeType]; | ||
if (deprecratedKey) { | ||
console.trace("Visitor defined for " + _nodeType2 + " but it has been renamed to " + deprecratedKey); | ||
console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecratedKey}`); | ||
aliases = [deprecratedKey]; | ||
@@ -98,23 +97,11 @@ } | ||
if (!aliases) continue; | ||
delete visitor[_nodeType2]; | ||
delete visitor[nodeType]; | ||
for (var _iterator2 = aliases, _isArray2 = Array.isArray(_iterator2), _i3 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (const alias of aliases) { | ||
const existing = visitor[alias]; | ||
if (_isArray2) { | ||
if (_i3 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i3++]; | ||
} else { | ||
_i3 = _iterator2.next(); | ||
if (_i3.done) break; | ||
_ref2 = _i3.value; | ||
} | ||
var _alias = _ref2; | ||
var existing = visitor[_alias]; | ||
if (existing) { | ||
mergePair(existing, _fns2); | ||
mergePair(existing, fns); | ||
} else { | ||
visitor[_alias] = (0, _clone.default)(_fns2); | ||
visitor[alias] = (0, _clone().default)(fns); | ||
} | ||
@@ -124,5 +111,5 @@ } | ||
for (var _nodeType3 in visitor) { | ||
if (shouldIgnoreKey(_nodeType3)) continue; | ||
ensureCallbackArrays(visitor[_nodeType3]); | ||
for (const nodeType in visitor) { | ||
if (shouldIgnoreKey(nodeType)) continue; | ||
ensureCallbackArrays(visitor[nodeType]); | ||
} | ||
@@ -140,3 +127,3 @@ | ||
for (var nodeType in visitor) { | ||
for (const nodeType in visitor) { | ||
if (nodeType === "enter" || nodeType === "exit") { | ||
@@ -148,14 +135,14 @@ validateVisitorMethods(nodeType, visitor[nodeType]); | ||
if (t.TYPES.indexOf(nodeType) < 0) { | ||
throw new Error("You gave us a visitor for the node type " + nodeType + " but it's not a valid type"); | ||
if (t().TYPES.indexOf(nodeType) < 0) { | ||
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`); | ||
} | ||
var visitors = visitor[nodeType]; | ||
const visitors = visitor[nodeType]; | ||
if (typeof visitors === "object") { | ||
for (var visitorKey in visitors) { | ||
for (const visitorKey in visitors) { | ||
if (visitorKey === "enter" || visitorKey === "exit") { | ||
validateVisitorMethods(nodeType + "." + visitorKey, visitors[visitorKey]); | ||
validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]); | ||
} else { | ||
throw new Error("You passed `traverse()` a visitor object with the property " + (nodeType + " that has the invalid property " + visitorKey)); | ||
throw new Error("You passed `traverse()` a visitor object with the property " + `${nodeType} that has the invalid property ${visitorKey}`); | ||
} | ||
@@ -170,38 +157,21 @@ } | ||
function validateVisitorMethods(path, val) { | ||
var fns = [].concat(val); | ||
const fns = [].concat(val); | ||
for (var _iterator3 = fns, _isArray3 = Array.isArray(_iterator3), _i5 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
if (_isArray3) { | ||
if (_i5 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i5++]; | ||
} else { | ||
_i5 = _iterator3.next(); | ||
if (_i5.done) break; | ||
_ref3 = _i5.value; | ||
for (const fn of fns) { | ||
if (typeof fn !== "function") { | ||
throw new TypeError(`Non-function found defined in ${path} with type ${typeof fn}`); | ||
} | ||
var _fn = _ref3; | ||
if (typeof _fn !== "function") { | ||
throw new TypeError("Non-function found defined in " + path + " with type " + typeof _fn); | ||
} | ||
} | ||
} | ||
function merge(visitors, states, wrapper) { | ||
if (states === void 0) { | ||
states = []; | ||
} | ||
function merge(visitors, states = [], wrapper) { | ||
const rootVisitor = {}; | ||
var rootVisitor = {}; | ||
for (var i = 0; i < visitors.length; i++) { | ||
var visitor = visitors[i]; | ||
var state = states[i]; | ||
for (let i = 0; i < visitors.length; i++) { | ||
const visitor = visitors[i]; | ||
const state = states[i]; | ||
explode(visitor); | ||
for (var type in visitor) { | ||
var visitorType = visitor[type]; | ||
for (const type in visitor) { | ||
let visitorType = visitor[type]; | ||
@@ -212,3 +182,3 @@ if (state || wrapper) { | ||
var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {}; | ||
const nodeVisitor = rootVisitor[type] = rootVisitor[type] || {}; | ||
mergePair(nodeVisitor, visitorType); | ||
@@ -222,12 +192,12 @@ } | ||
function wrapWithStateOrWrapper(oldVisitor, state, wrapper) { | ||
var newVisitor = {}; | ||
const newVisitor = {}; | ||
var _loop = function _loop(key) { | ||
var fns = oldVisitor[key]; | ||
if (!Array.isArray(fns)) return "continue"; | ||
for (const key in oldVisitor) { | ||
let fns = oldVisitor[key]; | ||
if (!Array.isArray(fns)) continue; | ||
fns = fns.map(function (fn) { | ||
var newFn = fn; | ||
let newFn = fn; | ||
if (state) { | ||
newFn = function newFn(path) { | ||
newFn = function (path) { | ||
return fn.call(state, path, state); | ||
@@ -244,8 +214,2 @@ }; | ||
newVisitor[key] = fns; | ||
}; | ||
for (var key in oldVisitor) { | ||
var _ret = _loop(key); | ||
if (_ret === "continue") continue; | ||
} | ||
@@ -257,5 +221,5 @@ | ||
function ensureEntranceObjects(obj) { | ||
for (var key in obj) { | ||
for (const key in obj) { | ||
if (shouldIgnoreKey(key)) continue; | ||
var fns = obj[key]; | ||
const fns = obj[key]; | ||
@@ -276,3 +240,3 @@ if (typeof fns === "function") { | ||
function wrapCheck(wrapper, fn) { | ||
var newFn = function newFn(path) { | ||
const newFn = function (path) { | ||
if (wrapper.checkPath(path)) { | ||
@@ -283,5 +247,3 @@ return fn.apply(this, arguments); | ||
newFn.toString = function () { | ||
return fn.toString(); | ||
}; | ||
newFn.toString = () => fn.toString(); | ||
@@ -303,5 +265,5 @@ return newFn; | ||
function mergePair(dest, src) { | ||
for (var key in src) { | ||
for (const key in src) { | ||
dest[key] = [].concat(dest[key] || [], src[key]); | ||
} | ||
} |
{ | ||
"name": "@babel/traverse", | ||
"version": "7.0.0-beta.42", | ||
"version": "7.0.0-beta.43", | ||
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes", | ||
@@ -11,8 +11,8 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"dependencies": { | ||
"@babel/code-frame": "7.0.0-beta.42", | ||
"@babel/generator": "7.0.0-beta.42", | ||
"@babel/helper-function-name": "7.0.0-beta.42", | ||
"@babel/helper-split-export-declaration": "7.0.0-beta.42", | ||
"@babel/types": "7.0.0-beta.42", | ||
"babylon": "7.0.0-beta.42", | ||
"@babel/code-frame": "7.0.0-beta.43", | ||
"@babel/generator": "7.0.0-beta.43", | ||
"@babel/helper-function-name": "7.0.0-beta.43", | ||
"@babel/helper-split-export-declaration": "7.0.0-beta.43", | ||
"@babel/types": "7.0.0-beta.43", | ||
"babylon": "7.0.0-beta.43", | ||
"debug": "^3.1.0", | ||
@@ -24,4 +24,4 @@ "globals": "^11.1.0", | ||
"devDependencies": { | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.42" | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.43" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
142258
4237
+ Added@babel/code-frame@7.0.0-beta.43(transitive)
+ Added@babel/generator@7.0.0-beta.43(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.43(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.43(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.43(transitive)
+ Added@babel/highlight@7.0.0-beta.43(transitive)
+ Added@babel/template@7.0.0-beta.43(transitive)
+ Added@babel/types@7.0.0-beta.43(transitive)
+ Addedbabylon@7.0.0-beta.43(transitive)
- Removed@babel/code-frame@7.0.0-beta.42(transitive)
- Removed@babel/generator@7.0.0-beta.42(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.42(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.42(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.42(transitive)
- Removed@babel/highlight@7.0.0-beta.42(transitive)
- Removed@babel/template@7.0.0-beta.42(transitive)
- Removed@babel/types@7.0.0-beta.42(transitive)
- Removedbabylon@7.0.0-beta.42(transitive)
Updated@babel/types@7.0.0-beta.43
Updatedbabylon@7.0.0-beta.43