Socket
Socket
Sign inDemoInstall

@babel/traverse

Package Overview
Dependencies
30
Maintainers
4
Versions
172
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.21.4-esm.2 to 7.21.4-esm.3

25

lib/cache.js

@@ -1,14 +0,25 @@

export let path = new WeakMap();
export let scope = new WeakMap();
export function clear() {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.clear = clear;
exports.clearPath = clearPath;
exports.clearScope = clearScope;
exports.scope = exports.path = void 0;
let path = new WeakMap();
exports.path = path;
let scope = new WeakMap();
exports.scope = scope;
function clear() {
clearPath();
clearScope();
}
export function clearPath() {
path = new WeakMap();
function clearPath() {
exports.path = path = new WeakMap();
}
export function clearScope() {
scope = new WeakMap();
function clearScope() {
exports.scope = scope = new WeakMap();
}
//# sourceMappingURL=cache.js.map

@@ -1,7 +0,13 @@

import NodePath from "./path/index.js";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _path = require("./path");
var _t = require("@babel/types");
const {
VISITOR_KEYS
} = _t;
export default class TraversalContext {
class TraversalContext {
constructor(scope, opts, state, parentPath) {

@@ -29,3 +35,3 @@ this.queue = null;

create(node, container, key, listKey) {
return NodePath.get({
return _path.default.get({
parentPath: this.parentPath,

@@ -108,3 +114,4 @@ parent: node,

}
exports.default = TraversalContext;
//# sourceMappingURL=context.js.map

@@ -1,2 +0,8 @@

export default class Hub {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
class Hub {
getCode() {}

@@ -11,3 +17,4 @@ getScope() {}

}
exports.default = Hub;
//# sourceMappingURL=hub.js.map

@@ -1,3 +0,33 @@

import * as visitors from "./visitors.js";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "Hub", {
enumerable: true,
get: function () {
return _hub.default;
}
});
Object.defineProperty(exports, "NodePath", {
enumerable: true,
get: function () {
return _path.default;
}
});
Object.defineProperty(exports, "Scope", {
enumerable: true,
get: function () {
return _scope.default;
}
});
exports.visitors = exports.default = void 0;
var visitors = require("./visitors");
exports.visitors = visitors;
var _t = require("@babel/types");
var cache = require("./cache");
var _traverseNode = require("./traverse-node");
var _path = require("./path");
var _scope = require("./scope");
var _hub = require("./hub");
const {

@@ -8,8 +38,2 @@ VISITOR_KEYS,

} = _t;
import * as cache from "./cache.js";
import { traverseNode } from "./traverse-node.js";
export { default as NodePath } from "./path/index.js";
export { default as Scope } from "./scope/index.js";
export { default as Hub } from "./hub.js";
export { visitors };
function traverse(parent, opts = {}, scope, state, parentPath) {

@@ -26,5 +50,6 @@ if (!parent) return;

visitors.explode(opts);
traverseNode(parent, opts, scope, state, parentPath);
(0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath);
}
export default traverse;
var _default = traverse;
exports.default = _default;
traverse.visitors = visitors;

@@ -38,3 +63,3 @@ traverse.verify = visitors.verify;

traverse.node = function (node, opts, scope, state, path, skipKeys) {
traverseNode(node, opts, scope, state, path, skipKeys);
(0, _traverseNode.traverseNode)(node, opts, scope, state, path, skipKeys);
};

@@ -41,0 +66,0 @@ traverse.clearNode = function (node, opts) {

@@ -1,6 +0,21 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.find = find;
exports.findParent = findParent;
exports.getAncestry = getAncestry;
exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
exports.getFunctionParent = getFunctionParent;
exports.getStatementParent = getStatementParent;
exports.inType = inType;
exports.isAncestor = isAncestor;
exports.isDescendant = isDescendant;
var _t = require("@babel/types");
const {
VISITOR_KEYS
} = _t;
export function findParent(callback) {
function findParent(callback) {
let path = this;

@@ -12,3 +27,3 @@ while (path = path.parentPath) {

}
export function find(callback) {
function find(callback) {
let path = this;

@@ -20,6 +35,6 @@ do {

}
export function getFunctionParent() {
function getFunctionParent() {
return this.findParent(p => p.isFunction());
}
export function getStatementParent() {
function getStatementParent() {
let path = this;

@@ -38,3 +53,3 @@ do {

}
export function getEarliestCommonAncestorFrom(paths) {
function getEarliestCommonAncestorFrom(paths) {
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {

@@ -64,3 +79,3 @@ let earliest;

}
export function getDeepestCommonAncestorFrom(paths, filter) {
function getDeepestCommonAncestorFrom(paths, filter) {
if (!paths.length) {

@@ -105,3 +120,3 @@ return this;

}
export function getAncestry() {
function getAncestry() {
let path = this;

@@ -114,9 +129,9 @@ const paths = [];

}
export function isAncestor(maybeDescendant) {
function isAncestor(maybeDescendant) {
return maybeDescendant.isDescendant(this);
}
export function isDescendant(maybeAncestor) {
function isDescendant(maybeAncestor) {
return !!this.findParent(parent => parent === maybeAncestor);
}
export function inType(...candidateTypes) {
function inType(...candidateTypes) {
let path = this;

@@ -123,0 +138,0 @@ while (path) {

@@ -1,2 +0,10 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addComment = addComment;
exports.addComments = addComments;
exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
var _t = require("@babel/types");
const {

@@ -6,3 +14,3 @@ addComment: _addComment,

} = _t;
export function shareCommentsWithSiblings() {
function shareCommentsWithSiblings() {
if (typeof this.key === "string") return;

@@ -40,6 +48,6 @@ const node = this.node;

}
export function addComment(type, content, line) {
function addComment(type, content, line) {
_addComment(this.node, type, content, line);
}
export function addComments(type, comments) {
function addComments(type, comments) {
_addComments(this.node, type, comments);

@@ -46,0 +54,0 @@ }

@@ -1,4 +0,29 @@

import { traverseNode } from "../traverse-node.js";
import { SHOULD_SKIP, SHOULD_STOP } from "./index.js";
export function call(key) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._call = _call;
exports._getQueueContexts = _getQueueContexts;
exports._resyncKey = _resyncKey;
exports._resyncList = _resyncList;
exports._resyncParent = _resyncParent;
exports._resyncRemoved = _resyncRemoved;
exports.call = call;
exports.isBlacklisted = exports.isDenylisted = isDenylisted;
exports.popContext = popContext;
exports.pushContext = pushContext;
exports.requeue = requeue;
exports.resync = resync;
exports.setContext = setContext;
exports.setKey = setKey;
exports.setScope = setScope;
exports.setup = setup;
exports.skip = skip;
exports.skipKey = skipKey;
exports.stop = stop;
exports.visit = visit;
var _traverseNode = require("../traverse-node");
var _index = require("./index");
function call(key) {
const opts = this.opts;

@@ -14,3 +39,3 @@ this.debug(key);

}
export function _call(fns) {
function _call(fns) {
if (!fns) return false;

@@ -33,3 +58,3 @@ for (const fn of fns) {

}
export function isDenylisted() {
function isDenylisted() {
var _this$opts$denylist;

@@ -39,3 +64,2 @@ const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;

}
export { isDenylisted as isBlacklisted };
function restoreContext(path, context) {

@@ -48,3 +72,3 @@ if (path.context !== context) {

}
export function visit() {
function visit() {
if (!this.node) {

@@ -66,3 +90,3 @@ return false;

this.debug("Recursing into...");
this.shouldStop = traverseNode(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
this.shouldStop = (0, _traverseNode.traverseNode)(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
restoreContext(this, currentContext);

@@ -72,6 +96,6 @@ this.call("exit");

}
export function skip() {
function skip() {
this.shouldSkip = true;
}
export function skipKey(key) {
function skipKey(key) {
if (this.skipKeys == null) {

@@ -82,6 +106,6 @@ this.skipKeys = {};

}
export function stop() {
this._traverseFlags |= SHOULD_SKIP | SHOULD_STOP;
function stop() {
this._traverseFlags |= _index.SHOULD_SKIP | _index.SHOULD_STOP;
}
export function setScope() {
function setScope() {
if (this.opts && this.opts.noScope) return;

@@ -101,3 +125,3 @@ let path = this.parentPath;

}
export function setContext(context) {
function setContext(context) {
if (this.skipKeys != null) {

@@ -115,3 +139,3 @@ this.skipKeys = {};

}
export function resync() {
function resync() {
if (this.removed) return;

@@ -122,3 +146,3 @@ this._resyncParent();

}
export function _resyncParent() {
function _resyncParent() {
if (this.parentPath) {

@@ -128,3 +152,3 @@ this.parent = this.parentPath.node;

}
export function _resyncKey() {
function _resyncKey() {
if (!this.container) return;

@@ -151,3 +175,3 @@ if (this.node === this.container[this.key]) {

}
export function _resyncList() {
function _resyncList() {
if (!this.parent || !this.inList) return;

@@ -158,3 +182,3 @@ const newContainer = this.parent[this.listKey];

}
export function _resyncRemoved() {
function _resyncRemoved() {
if (this.key == null || !this.container || this.container[this.key] !== this.node) {

@@ -164,3 +188,3 @@ this._markRemoved();

}
export function popContext() {
function popContext() {
this.contexts.pop();

@@ -173,7 +197,7 @@ if (this.contexts.length > 0) {

}
export function pushContext(context) {
function pushContext(context) {
this.contexts.push(context);
this.setContext(context);
}
export function setup(parentPath, container, listKey, key) {
function setup(parentPath, container, listKey, key) {
this.listKey = listKey;

@@ -184,3 +208,3 @@ this.container = container;

}
export function setKey(key) {
function setKey(key) {
var _this$node;

@@ -191,3 +215,3 @@ this.key = key;

}
export function requeue(pathToQueue = this) {
function requeue(pathToQueue = this) {
if (pathToQueue.removed) return;

@@ -200,3 +224,3 @@ ;

}
export function _getQueueContexts() {
function _getQueueContexts() {
let path = this;

@@ -203,0 +227,0 @@ let contexts = this.contexts;

@@ -1,2 +0,15 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.arrowFunctionToExpression = arrowFunctionToExpression;
exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
exports.ensureBlock = ensureBlock;
exports.toComputedKey = toComputedKey;
exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
var _t = require("@babel/types");
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
var _helperFunctionName = require("@babel/helper-function-name");
var _visitors = require("../visitors");
const {

@@ -29,6 +42,3 @@ arrowFunctionExpression,

} = _t;
import environmentVisitor from "@babel/helper-environment-visitor";
import nameFunction from "@babel/helper-function-name";
import { merge as mergeVisitors } from "../visitors.js";
export function toComputedKey() {
function toComputedKey() {
let key;

@@ -47,3 +57,3 @@ if (this.isMemberExpression()) {

}
export function ensureBlock() {
function ensureBlock() {
const body = this.get("body");

@@ -83,7 +93,7 @@ const bodyNode = body.node;

}
export function arrowFunctionToShadowed() {
function arrowFunctionToShadowed() {
if (!this.isArrowFunctionExpression()) return;
this.arrowFunctionToExpression();
}
export function unwrapFunctionEnvironment() {
function unwrapFunctionEnvironment() {
if (!this.isArrowFunctionExpression() && !this.isFunctionExpression() && !this.isFunctionDeclaration()) {

@@ -97,3 +107,3 @@ throw this.buildCodeFrameError("Can only unwrap the environment of a function.");

}
export function arrowFunctionToExpression({
function arrowFunctionToExpression({
allowInsertArrow = true,

@@ -122,3 +132,3 @@ allowInsertArrowWithRest = allowInsertArrow,

fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
fn.replaceWith(callExpression(memberExpression(nameFunction(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
fn.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
return fn.get("callee.object");

@@ -128,3 +138,3 @@ }

}
const getSuperCallsVisitor = mergeVisitors([{
const getSuperCallsVisitor = (0, _visitors.merge)([{
CallExpression(child, {

@@ -136,3 +146,3 @@ allSuperCalls

}
}, environmentVisitor]);
}, _helperEnvironmentVisitor.default]);
function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true, allowInsertArrowWithRest = true) {

@@ -324,3 +334,3 @@ let arrowParent;

}
const assignSuperThisVisitor = mergeVisitors([{
const assignSuperThisVisitor = (0, _visitors.merge)([{
CallExpression(child, {

@@ -335,3 +345,3 @@ supers,

}
}, environmentVisitor]);
}, _helperEnvironmentVisitor.default]);
function getThisBinding(thisEnvFn, inConstructor) {

@@ -386,3 +396,3 @@ return getBinding(thisEnvFn, "this", thisBinding => {

}
const getScopeInformationVisitor = mergeVisitors([{
const getScopeInformationVisitor = (0, _visitors.merge)([{
ThisExpression(child, {

@@ -445,3 +455,3 @@ thisPaths

}
}, environmentVisitor]);
}, _helperEnvironmentVisitor.default]);
function getScopeInformation(fnPath) {

@@ -448,0 +458,0 @@ const thisPaths = [];

@@ -0,1 +1,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.evaluate = evaluate;
exports.evaluateTruthy = evaluateTruthy;
const VALID_CALLEES = ["String", "Number", "Math"];

@@ -9,3 +16,3 @@ const INVALID_METHODS = ["random"];

}
export function evaluateTruthy() {
function evaluateTruthy() {
const res = this.evaluate();

@@ -319,3 +326,3 @@ if (res.confident) return !!res.value;

}
export function evaluate() {
function evaluate() {
const state = {

@@ -322,0 +329,0 @@ confident: true,

@@ -1,3 +0,22 @@

import NodePath from "./index.js";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._getKey = _getKey;
exports._getPattern = _getPattern;
exports.get = get;
exports.getAllNextSiblings = getAllNextSiblings;
exports.getAllPrevSiblings = getAllPrevSiblings;
exports.getBindingIdentifierPaths = getBindingIdentifierPaths;
exports.getBindingIdentifiers = getBindingIdentifiers;
exports.getCompletionRecords = getCompletionRecords;
exports.getNextSibling = getNextSibling;
exports.getOpposite = getOpposite;
exports.getOuterBindingIdentifierPaths = getOuterBindingIdentifierPaths;
exports.getOuterBindingIdentifiers = getOuterBindingIdentifiers;
exports.getPrevSibling = getPrevSibling;
exports.getSibling = getSibling;
var _index = require("./index");
var _t = require("@babel/types");
const {

@@ -24,3 +43,3 @@ getBindingIdentifiers: _getBindingIdentifiers,

}
export function getOpposite() {
function getOpposite() {
if (this.key === "left") {

@@ -171,3 +190,3 @@ return this.getSibling("right");

}
export function getCompletionRecords() {
function getCompletionRecords() {
const records = _getCompletionRecords(this, {

@@ -180,4 +199,4 @@ canHaveBreak: false,

}
export function getSibling(key) {
return NodePath.get({
function getSibling(key) {
return _index.default.get({
parentPath: this.parentPath,

@@ -190,9 +209,9 @@ parent: this.parent,

}
export function getPrevSibling() {
function getPrevSibling() {
return this.getSibling(this.key - 1);
}
export function getNextSibling() {
function getNextSibling() {
return this.getSibling(this.key + 1);
}
export function getAllNextSiblings() {
function getAllNextSiblings() {
let _key = this.key;

@@ -207,3 +226,3 @@ let sibling = this.getSibling(++_key);

}
export function getAllPrevSiblings() {
function getAllPrevSiblings() {
let _key = this.key;

@@ -227,4 +246,3 @@ let sibling = this.getSibling(--_key);

}
export { get };
export function _getKey(key, context) {
function _getKey(key, context) {
const node = this.node;

@@ -234,3 +252,3 @@ const container = node[key];

return container.map((_, i) => {
return NodePath.get({
return _index.default.get({
listKey: key,

@@ -244,3 +262,3 @@ parentPath: this,

} else {
return NodePath.get({
return _index.default.get({
parentPath: this,

@@ -253,3 +271,3 @@ parent: node,

}
export function _getPattern(parts, context) {
function _getPattern(parts, context) {
let path = this;

@@ -272,7 +290,5 @@ for (const part of parts) {

}
export { getBindingIdentifiers };
function getOuterBindingIdentifiers(duplicates) {
return _getOuterBindingIdentifiers(this.node, duplicates);
}
export { getOuterBindingIdentifiers };
function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {

@@ -326,8 +342,6 @@ const path = this;

}
export { getBindingIdentifierPaths };
function getOuterBindingIdentifierPaths(duplicates = false) {
return this.getBindingIdentifierPaths(duplicates, true);
}
export { getOuterBindingIdentifierPaths };
//# sourceMappingURL=family.js.map

@@ -1,28 +0,37 @@

import * as virtualTypes from "./lib/virtual-types.js";
import buildDebug from "debug";
import traverse from "../index.js";
import Scope from "../scope/index.js";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.SHOULD_STOP = exports.SHOULD_SKIP = exports.REMOVED = void 0;
var virtualTypes = require("./lib/virtual-types");
var _debug = require("debug");
var _index = require("../index");
var _scope = require("../scope");
var _t = require("@babel/types");
var t = _t;
var _cache = require("../cache");
var _generator = require("@babel/generator");
var NodePath_ancestry = require("./ancestry");
var NodePath_inference = require("./inference");
var NodePath_replacement = require("./replacement");
var NodePath_evaluation = require("./evaluation");
var NodePath_conversion = require("./conversion");
var NodePath_introspection = require("./introspection");
var NodePath_context = require("./context");
var NodePath_removal = require("./removal");
var NodePath_modification = require("./modification");
var NodePath_family = require("./family");
var NodePath_comments = require("./comments");
var NodePath_virtual_types_validator = require("./lib/virtual-types-validator");
const {
validate
} = _t;
import * as t from "@babel/types";
import { path as pathCache } from "../cache.js";
import generator from "@babel/generator";
import * as NodePath_ancestry from "./ancestry.js";
import * as NodePath_inference from "./inference/index.js";
import * as NodePath_replacement from "./replacement.js";
import * as NodePath_evaluation from "./evaluation.js";
import * as NodePath_conversion from "./conversion.js";
import * as NodePath_introspection from "./introspection.js";
import * as NodePath_context from "./context.js";
import * as NodePath_removal from "./removal.js";
import * as NodePath_modification from "./modification.js";
import * as NodePath_family from "./family.js";
import * as NodePath_comments from "./comments.js";
import * as NodePath_virtual_types_validator from "./lib/virtual-types-validator.js";
const debug = buildDebug("babel");
export const REMOVED = 1 << 0;
export const SHOULD_STOP = 1 << 1;
export const SHOULD_SKIP = 1 << 2;
const debug = _debug("babel");
const REMOVED = 1 << 0;
exports.REMOVED = REMOVED;
const SHOULD_STOP = 1 << 1;
exports.SHOULD_STOP = SHOULD_STOP;
const SHOULD_SKIP = 1 << 2;
exports.SHOULD_SKIP = SHOULD_SKIP;
class NodePath {

@@ -62,6 +71,6 @@ constructor(hub, parent) {

const targetNode = container[key];
let paths = pathCache.get(parent);
let paths = _cache.path.get(parent);
if (!paths) {
paths = new Map();
pathCache.set(parent, paths);
_cache.path.set(parent, paths);
}

@@ -77,3 +86,3 @@ let path = paths.get(targetNode);

getScope(scope) {
return this.isScope() ? new Scope(this) : scope;
return this.isScope() ? new _scope.default(this) : scope;
}

@@ -101,3 +110,3 @@ setData(key, val) {

traverse(visitor, state) {
traverse(this.node, visitor, this.scope, state, this);
(0, _index.default)(this.node, visitor, this.scope, state, this);
}

@@ -123,3 +132,3 @@ set(key, node) {

toString() {
return generator(this.node).code;
return (0, _generator.default)(this.node).code;
}

@@ -189,4 +198,5 @@ get inList() {

}
export default NodePath;
var _default = NodePath;
exports.default = _default;
//# sourceMappingURL=index.js.map

@@ -1,3 +0,14 @@

import * as inferers from "./inferers.js";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._getTypeAnnotation = _getTypeAnnotation;
exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
exports.couldBeBaseType = couldBeBaseType;
exports.getTypeAnnotation = getTypeAnnotation;
exports.isBaseType = isBaseType;
exports.isGenericType = isGenericType;
var inferers = require("./inferers");
var _t = require("@babel/types");
const {

@@ -25,3 +36,3 @@ anyTypeAnnotation,

} = _t;
export function getTypeAnnotation() {
function getTypeAnnotation() {
let type = this.getData("typeAnnotation");

@@ -39,3 +50,3 @@ if (type != null) {

const typeAnnotationInferringNodes = new WeakSet();
export function _getTypeAnnotation() {
function _getTypeAnnotation() {
const node = this.node;

@@ -78,3 +89,3 @@ if (!node) {

}
export function isBaseType(baseName, soft) {
function isBaseType(baseName, soft) {
return _isBaseType(baseName, this.getTypeAnnotation(), soft);

@@ -105,3 +116,3 @@ }

}
export function couldBeBaseType(name) {
function couldBeBaseType(name) {
const type = this.getTypeAnnotation();

@@ -120,3 +131,3 @@ if (isAnyTypeAnnotation(type)) return true;

}
export function baseTypeStrictlyMatches(rightArg) {
function baseTypeStrictlyMatches(rightArg) {
const left = this.getTypeAnnotation();

@@ -129,3 +140,3 @@ const right = rightArg.getTypeAnnotation();

}
export function isGenericType(genericName) {
function isGenericType(genericName) {
const type = this.getTypeAnnotation();

@@ -132,0 +143,0 @@ if (genericName === "Array") {

@@ -1,2 +0,9 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _t = require("@babel/types");
var _util = require("./util");
const {

@@ -8,4 +15,3 @@ BOOLEAN_NUMBER_BINARY_OPERATORS,

} = _t;
import { createUnionType } from "./util.js";
export default function (node) {
function _default(node) {
if (!this.isReferenced()) return;

@@ -45,3 +51,3 @@ const binding = this.scope.getBinding(node.name);

}
return createUnionType(types);
return (0, _util.createUnionType)(types);
}

@@ -140,3 +146,3 @@ function getConstantViolationsBefore(binding, path, functions) {

return {
typeAnnotation: createUnionType(types),
typeAnnotation: (0, _util.createUnionType)(types),
ifStatement

@@ -143,0 +149,0 @@ };

@@ -1,2 +0,40 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ArrayExpression = ArrayExpression;
exports.AssignmentExpression = AssignmentExpression;
exports.BinaryExpression = BinaryExpression;
exports.BooleanLiteral = BooleanLiteral;
exports.CallExpression = CallExpression;
exports.ConditionalExpression = ConditionalExpression;
exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
Object.defineProperty(exports, "Identifier", {
enumerable: true,
get: function () {
return _infererReference.default;
}
});
exports.LogicalExpression = LogicalExpression;
exports.NewExpression = NewExpression;
exports.NullLiteral = NullLiteral;
exports.NumericLiteral = NumericLiteral;
exports.ObjectExpression = ObjectExpression;
exports.ParenthesizedExpression = ParenthesizedExpression;
exports.RegExpLiteral = RegExpLiteral;
exports.RestElement = RestElement;
exports.SequenceExpression = SequenceExpression;
exports.StringLiteral = StringLiteral;
exports.TSAsExpression = TSAsExpression;
exports.TSNonNullExpression = TSNonNullExpression;
exports.TaggedTemplateExpression = TaggedTemplateExpression;
exports.TemplateLiteral = TemplateLiteral;
exports.TypeCastExpression = TypeCastExpression;
exports.UnaryExpression = UnaryExpression;
exports.UpdateExpression = UpdateExpression;
exports.VariableDeclarator = VariableDeclarator;
var _t = require("@babel/types");
var _infererReference = require("./inferer-reference");
var _util = require("./util");
const {

@@ -22,20 +60,18 @@ BOOLEAN_BINARY_OPERATORS,

} = _t;
export { default as Identifier } from "./inferer-reference.js";
import { createUnionType } from "./util.js";
export function VariableDeclarator() {
function VariableDeclarator() {
if (!this.get("id").isIdentifier()) return;
return this.get("init").getTypeAnnotation();
}
export function TypeCastExpression(node) {
function TypeCastExpression(node) {
return node.typeAnnotation;
}
TypeCastExpression.validParent = true;
export function TSAsExpression(node) {
function TSAsExpression(node) {
return node.typeAnnotation;
}
TSAsExpression.validParent = true;
export function TSNonNullExpression() {
function TSNonNullExpression() {
return this.get("expression").getTypeAnnotation();
}
export function NewExpression(node) {
function NewExpression(node) {
if (node.callee.type === "Identifier") {

@@ -45,6 +81,6 @@ return genericTypeAnnotation(node.callee);

}
export function TemplateLiteral() {
function TemplateLiteral() {
return stringTypeAnnotation();
}
export function UnaryExpression(node) {
function UnaryExpression(node) {
const operator = node.operator;

@@ -61,3 +97,3 @@ if (operator === "void") {

}
export function BinaryExpression(node) {
function BinaryExpression(node) {
const operator = node.operator;

@@ -79,20 +115,20 @@ if (NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {

}
export function LogicalExpression() {
function LogicalExpression() {
const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
return createUnionType(argumentTypes);
return (0, _util.createUnionType)(argumentTypes);
}
export function ConditionalExpression() {
function ConditionalExpression() {
const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
return createUnionType(argumentTypes);
return (0, _util.createUnionType)(argumentTypes);
}
export function SequenceExpression() {
function SequenceExpression() {
return this.get("expressions").pop().getTypeAnnotation();
}
export function ParenthesizedExpression() {
function ParenthesizedExpression() {
return this.get("expression").getTypeAnnotation();
}
export function AssignmentExpression() {
function AssignmentExpression() {
return this.get("right").getTypeAnnotation();
}
export function UpdateExpression(node) {
function UpdateExpression(node) {
const operator = node.operator;

@@ -103,24 +139,24 @@ if (operator === "++" || operator === "--") {

}
export function StringLiteral() {
function StringLiteral() {
return stringTypeAnnotation();
}
export function NumericLiteral() {
function NumericLiteral() {
return numberTypeAnnotation();
}
export function BooleanLiteral() {
function BooleanLiteral() {
return booleanTypeAnnotation();
}
export function NullLiteral() {
function NullLiteral() {
return nullLiteralTypeAnnotation();
}
export function RegExpLiteral() {
function RegExpLiteral() {
return genericTypeAnnotation(identifier("RegExp"));
}
export function ObjectExpression() {
function ObjectExpression() {
return genericTypeAnnotation(identifier("Object"));
}
export function ArrayExpression() {
function ArrayExpression() {
return genericTypeAnnotation(identifier("Array"));
}
export function RestElement() {
function RestElement() {
return ArrayExpression();

@@ -132,3 +168,2 @@ }

}
export { Func as FunctionExpression, Func as ArrowFunctionExpression, Func as FunctionDeclaration, Func as ClassExpression, Func as ClassDeclaration };
const isArrayFrom = buildMatchMemberExpression("Array.from");

@@ -138,3 +173,3 @@ const isObjectKeys = buildMatchMemberExpression("Object.keys");

const isObjectEntries = buildMatchMemberExpression("Object.entries");
export function CallExpression() {
function CallExpression() {
const {

@@ -154,3 +189,3 @@ callee

}
export function TaggedTemplateExpression() {
function TaggedTemplateExpression() {
return resolveCall(this.get("tag"));

@@ -157,0 +192,0 @@ }

@@ -1,2 +0,8 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createUnionType = createUnionType;
var _t = require("@babel/types");
const {

@@ -9,3 +15,3 @@ createFlowUnionType,

} = _t;
export function createUnionType(types) {
function createUnionType(types) {
{

@@ -12,0 +18,0 @@ if (isFlowType(types[0])) {

@@ -1,2 +0,26 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
exports._resolve = _resolve;
exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
exports.equals = equals;
exports.getSource = getSource;
exports.has = has;
exports.is = void 0;
exports.isCompletionRecord = isCompletionRecord;
exports.isConstantExpression = isConstantExpression;
exports.isInStrictMode = isInStrictMode;
exports.isNodeType = isNodeType;
exports.isStatementOrBlock = isStatementOrBlock;
exports.isStatic = isStatic;
exports.isnt = isnt;
exports.matchesPattern = matchesPattern;
exports.referencesImport = referencesImport;
exports.resolve = resolve;
exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
var _t = require("@babel/types");
const {

@@ -13,6 +37,6 @@ STATEMENT_OR_BLOCK_KEYS,

} = _t;
export function matchesPattern(pattern, allowPartial) {
function matchesPattern(pattern, allowPartial) {
return _matchesPattern(this.node, pattern, allowPartial);
}
export function has(key) {
function has(key) {
const val = this.node && this.node[key];

@@ -25,19 +49,20 @@ if (val && Array.isArray(val)) {

}
export function isStatic() {
function isStatic() {
return this.scope.isStatic(this.node);
}
export const is = has;
export function isnt(key) {
const is = has;
exports.is = is;
function isnt(key) {
return !this.has(key);
}
export function equals(key, value) {
function equals(key, value) {
return this.node[key] === value;
}
export function isNodeType(type) {
function isNodeType(type) {
return isType(this.type, type);
}
export function canHaveVariableDeclarationOrExpression() {
function canHaveVariableDeclarationOrExpression() {
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
}
export function canSwapBetweenExpressionAndStatement(replacement) {
function canSwapBetweenExpressionAndStatement(replacement) {
if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {

@@ -53,3 +78,3 @@ return false;

}
export function isCompletionRecord(allowInsideFunction) {
function isCompletionRecord(allowInsideFunction) {
let path = this;

@@ -72,3 +97,3 @@ let first = true;

}
export function isStatementOrBlock() {
function isStatementOrBlock() {
if (this.parentPath.isLabeledStatement() || isBlockStatement(this.container)) {

@@ -80,3 +105,3 @@ return false;

}
export function referencesImport(moduleSource, importName) {
function referencesImport(moduleSource, importName) {
if (!this.isReferencedIdentifier()) {

@@ -114,3 +139,3 @@ if (this.isJSXMemberExpression() && this.node.property.name === importName || (this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {

}
export function getSource() {
function getSource() {
const node = this.node;

@@ -123,3 +148,3 @@ if (node.end) {

}
export function willIMaybeExecuteBefore(target) {
function willIMaybeExecuteBefore(target) {
return this._guessExecutionStatusRelativeTo(target) !== "after";

@@ -168,3 +193,3 @@ }

const SYMBOL_CHECKING = Symbol();
export function _guessExecutionStatusRelativeTo(target) {
function _guessExecutionStatusRelativeTo(target) {
return _guessExecutionStatusRelativeToCached(this, target, new Map());

@@ -264,6 +289,6 @@ }

}
export function resolve(dangerous, resolved) {
function resolve(dangerous, resolved) {
return this._resolve(dangerous, resolved) || this;
}
export function _resolve(dangerous, resolved) {
function _resolve(dangerous, resolved) {
if (resolved && resolved.indexOf(this) >= 0) return;

@@ -313,3 +338,3 @@ resolved = resolved || [];

}
export function isConstantExpression() {
function isConstantExpression() {
if (this.isIdentifier()) {

@@ -343,3 +368,3 @@ const binding = this.scope.getBinding(this.node.name);

}
export function isInStrictMode() {
function isInStrictMode() {
const start = this.isProgram() ? this : this.parentPath;

@@ -346,0 +371,0 @@ const strictParent = start.find(path => {

@@ -1,6 +0,12 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _t = require("@babel/types");
var _t2 = _t;
const {
react
} = _t;
import * as _t2 from "@babel/types";
const {

@@ -39,3 +45,3 @@ cloneNode,

};
export default class PathHoister {
class PathHoister {
constructor(path, scope) {

@@ -164,3 +170,4 @@ this.breakOnScopePaths = void 0;

}
exports.default = PathHoister;
//# sourceMappingURL=hoister.js.map

@@ -1,2 +0,8 @@

export const hooks = [function (self, parent) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hooks = void 0;
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();

@@ -30,3 +36,4 @@ if (removeParent) {

}];
exports.hooks = hooks;
//# sourceMappingURL=removal-hooks.js.map

@@ -1,2 +0,25 @@

import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isBindingIdentifier = isBindingIdentifier;
exports.isBlockScoped = isBlockScoped;
exports.isExistentialTypeParam = isExistentialTypeParam;
exports.isExpression = isExpression;
exports.isFlow = isFlow;
exports.isForAwaitStatement = isForAwaitStatement;
exports.isGenerated = isGenerated;
exports.isNumericLiteralTypeAnnotation = isNumericLiteralTypeAnnotation;
exports.isPure = isPure;
exports.isReferenced = isReferenced;
exports.isReferencedIdentifier = isReferencedIdentifier;
exports.isReferencedMemberExpression = isReferencedMemberExpression;
exports.isRestProperty = isRestProperty;
exports.isScope = isScope;
exports.isSpreadProperty = isSpreadProperty;
exports.isStatement = isStatement;
exports.isUser = isUser;
exports.isVar = isVar;
var _t = require("@babel/types");
const {

@@ -28,3 +51,3 @@ isBinding,

} = react;
export function isReferencedIdentifier(opts) {
function isReferencedIdentifier(opts) {
const {

@@ -43,3 +66,3 @@ node,

}
export function isReferencedMemberExpression() {
function isReferencedMemberExpression() {
const {

@@ -51,3 +74,3 @@ node,

}
export function isBindingIdentifier() {
function isBindingIdentifier() {
const {

@@ -60,3 +83,3 @@ node,

}
export function isStatement() {
function isStatement() {
const {

@@ -80,3 +103,3 @@ node,

}
export function isExpression() {
function isExpression() {
if (this.isIdentifier()) {

@@ -88,24 +111,24 @@ return this.isReferencedIdentifier();

}
export function isScope() {
function isScope() {
return nodeIsScope(this.node, this.parent);
}
export function isReferenced() {
function isReferenced() {
return nodeIsReferenced(this.node, this.parent);
}
export function isBlockScoped() {
function isBlockScoped() {
return nodeIsBlockScoped(this.node);
}
export function isVar() {
function isVar() {
return nodeIsVar(this.node);
}
export function isUser() {
function isUser() {
return this.node && !!this.node.loc;
}
export function isGenerated() {
function isGenerated() {
return !this.isUser();
}
export function isPure(constantsOnly) {
function isPure(constantsOnly) {
return this.scope.isPure(this.node, constantsOnly);
}
export function isFlow() {
function isFlow() {
const {

@@ -126,9 +149,9 @@ node

}
export function isRestProperty() {
function isRestProperty() {
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectPattern();
}
export function isSpreadProperty() {
function isSpreadProperty() {
return nodeIsRestElement(this.node) && this.parentPath && this.parentPath.isObjectExpression();
}
export function isForAwaitStatement() {
function isForAwaitStatement() {
return isForOfStatement(this.node, {

@@ -138,6 +161,6 @@ await: true

}
export function isExistentialTypeParam() {
function isExistentialTypeParam() {
throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.");
}
export function isNumericLiteralTypeAnnotation() {
function isNumericLiteralTypeAnnotation() {
throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.");

@@ -144,0 +167,0 @@ }

@@ -1,20 +0,44 @@

export const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
export const ReferencedMemberExpression = ["MemberExpression"];
export const BindingIdentifier = ["Identifier"];
export const Statement = ["Statement"];
export const Expression = ["Expression"];
export const Scope = ["Scopable", "Pattern"];
export const Referenced = null;
export const BlockScoped = null;
export const Var = ["VariableDeclaration"];
export const User = null;
export const Generated = null;
export const Pure = null;
export const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
export const RestProperty = ["RestElement"];
export const SpreadProperty = ["RestElement"];
export const ExistentialTypeParam = ["ExistsTypeAnnotation"];
export const NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
export const ForAwaitStatement = ["ForOfStatement"];
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Var = exports.User = exports.Statement = exports.SpreadProperty = exports.Scope = exports.RestProperty = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = exports.Referenced = exports.Pure = exports.NumericLiteralTypeAnnotation = exports.Generated = exports.ForAwaitStatement = exports.Flow = exports.Expression = exports.ExistentialTypeParam = exports.BlockScoped = exports.BindingIdentifier = void 0;
const ReferencedIdentifier = ["Identifier", "JSXIdentifier"];
exports.ReferencedIdentifier = ReferencedIdentifier;
const ReferencedMemberExpression = ["MemberExpression"];
exports.ReferencedMemberExpression = ReferencedMemberExpression;
const BindingIdentifier = ["Identifier"];
exports.BindingIdentifier = BindingIdentifier;
const Statement = ["Statement"];
exports.Statement = Statement;
const Expression = ["Expression"];
exports.Expression = Expression;
const Scope = ["Scopable", "Pattern"];
exports.Scope = Scope;
const Referenced = null;
exports.Referenced = Referenced;
const BlockScoped = null;
exports.BlockScoped = BlockScoped;
const Var = ["VariableDeclaration"];
exports.Var = Var;
const User = null;
exports.User = User;
const Generated = null;
exports.Generated = Generated;
const Pure = null;
exports.Pure = Pure;
const Flow = ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"];
exports.Flow = Flow;
const RestProperty = ["RestElement"];
exports.RestProperty = RestProperty;
const SpreadProperty = ["RestElement"];
exports.SpreadProperty = SpreadProperty;
const ExistentialTypeParam = ["ExistsTypeAnnotation"];
exports.ExistentialTypeParam = ExistentialTypeParam;
const NumericLiteralTypeAnnotation = ["NumberLiteralTypeAnnotation"];
exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
const ForAwaitStatement = ["ForOfStatement"];
exports.ForAwaitStatement = ForAwaitStatement;
//# sourceMappingURL=virtual-types.js.map

@@ -1,5 +0,20 @@

import { path as pathCache } from "../cache.js";
import PathHoister from "./lib/hoister.js";
import NodePath from "./index.js";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._containerInsert = _containerInsert;
exports._containerInsertAfter = _containerInsertAfter;
exports._containerInsertBefore = _containerInsertBefore;
exports._verifyNodeList = _verifyNodeList;
exports.hoist = hoist;
exports.insertAfter = insertAfter;
exports.insertBefore = insertBefore;
exports.pushContainer = pushContainer;
exports.unshiftContainer = unshiftContainer;
exports.updateSiblingKeys = updateSiblingKeys;
var _cache = require("../cache");
var _hoister = require("./lib/hoister");
var _index = require("./index");
var _t = require("@babel/types");
const {

@@ -22,3 +37,3 @@ arrowFunctionExpression,

} = _t;
export function insertBefore(nodes_) {
function insertBefore(nodes_) {
this._assertUnremoved();

@@ -46,3 +61,3 @@ const nodes = this._verifyNodeList(nodes_);

}
export function _containerInsert(from, nodes) {
function _containerInsert(from, nodes) {
this.updateSiblingKeys(from, nodes.length);

@@ -69,6 +84,6 @@ const paths = [];

}
export function _containerInsertBefore(nodes) {
function _containerInsertBefore(nodes) {
return this._containerInsert(this.key, nodes);
}
export function _containerInsertAfter(nodes) {
function _containerInsertAfter(nodes) {
return this._containerInsert(this.key + 1, nodes);

@@ -87,3 +102,3 @@ }

}
export function insertAfter(nodes_) {
function insertAfter(nodes_) {
this._assertUnremoved();

@@ -148,5 +163,5 @@ if (this.isSequenceExpression()) {

}
export function updateSiblingKeys(fromIndex, incrementBy) {
function updateSiblingKeys(fromIndex, incrementBy) {
if (!this.parent) return;
const paths = pathCache.get(this.parent);
const paths = _cache.path.get(this.parent);
for (const [, path] of paths) {

@@ -158,3 +173,3 @@ if (path.key >= fromIndex) {

}
export function _verifyNodeList(nodes) {
function _verifyNodeList(nodes) {
if (!nodes) {

@@ -175,3 +190,3 @@ return [];

msg = "without a type";
} else if (node instanceof NodePath) {
} else if (node instanceof _index.default) {
msg = "has a NodePath when it expected a raw object";

@@ -186,6 +201,6 @@ }

}
export function unshiftContainer(listKey, nodes) {
function unshiftContainer(listKey, nodes) {
this._assertUnremoved();
nodes = this._verifyNodeList(nodes);
const path = NodePath.get({
const path = _index.default.get({
parentPath: this,

@@ -199,7 +214,7 @@ parent: this.node,

}
export function pushContainer(listKey, nodes) {
function pushContainer(listKey, nodes) {
this._assertUnremoved();
const verifiedNodes = this._verifyNodeList(nodes);
const container = this.node[listKey];
const path = NodePath.get({
const path = _index.default.get({
parentPath: this,

@@ -213,4 +228,4 @@ parent: this.node,

}
export function hoist(scope = this.scope) {
const hoister = new PathHoister(this, scope);
function hoist(scope = this.scope) {
const hoister = new _hoister.default(this, scope);
return hoister.run();

@@ -217,0 +232,0 @@ }

@@ -1,5 +0,16 @@

import { hooks } from "./lib/removal-hooks.js";
import { path as pathCache } from "../cache.js";
import { REMOVED, SHOULD_SKIP } from "./index.js";
export function remove() {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._assertUnremoved = _assertUnremoved;
exports._callRemovalHooks = _callRemovalHooks;
exports._markRemoved = _markRemoved;
exports._remove = _remove;
exports._removeFromScope = _removeFromScope;
exports.remove = remove;
var _removalHooks = require("./lib/removal-hooks");
var _cache = require("../cache");
var _index = require("./index");
function remove() {
var _this$opts;

@@ -19,12 +30,12 @@ this._assertUnremoved();

}
export function _removeFromScope() {
function _removeFromScope() {
const bindings = this.getBindingIdentifiers();
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
}
export function _callRemovalHooks() {
for (const fn of hooks) {
function _callRemovalHooks() {
for (const fn of _removalHooks.hooks) {
if (fn(this, this.parentPath)) return true;
}
}
export function _remove() {
function _remove() {
if (Array.isArray(this.container)) {

@@ -37,8 +48,8 @@ this.container.splice(this.key, 1);

}
export function _markRemoved() {
this._traverseFlags |= SHOULD_SKIP | REMOVED;
if (this.parent) pathCache.get(this.parent).delete(this.node);
function _markRemoved() {
this._traverseFlags |= _index.SHOULD_SKIP | _index.REMOVED;
if (this.parent) _cache.path.get(this.parent).delete(this.node);
this.node = null;
}
export function _assertUnremoved() {
function _assertUnremoved() {
if (this.removed) {

@@ -45,0 +56,0 @@ throw this.buildCodeFrameError("NodePath has been removed so is read-only.");

@@ -1,7 +0,19 @@

import { codeFrameColumns } from "@babel/code-frame";
import traverse from "../index.js";
import NodePath from "./index.js";
import { path as pathCache } from "../cache.js";
import { parse } from "@babel/parser";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._replaceWith = _replaceWith;
exports.replaceExpressionWithStatements = replaceExpressionWithStatements;
exports.replaceInline = replaceInline;
exports.replaceWith = replaceWith;
exports.replaceWithMultiple = replaceWithMultiple;
exports.replaceWithSourceString = replaceWithSourceString;
var _codeFrame = require("@babel/code-frame");
var _index = require("../index");
var _index2 = require("./index");
var _cache = require("../cache");
var _parser = require("@babel/parser");
var _t = require("@babel/types");
var _helperHoistVariables = require("@babel/helper-hoist-variables");
const {

@@ -29,4 +41,3 @@ FUNCTION_TYPES,

} = _t;
import hoistVariables from "@babel/helper-hoist-variables";
export function replaceWithMultiple(nodes) {
function replaceWithMultiple(nodes) {
var _pathCache$get;

@@ -37,3 +48,3 @@ this.resync();

inheritTrailingComments(nodes[nodes.length - 1], this.node);
(_pathCache$get = pathCache.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node);
(_pathCache$get = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get.delete(this.node);
this.node = this.container[this.key] = null;

@@ -48,3 +59,3 @@ const paths = this.insertAfter(nodes);

}
export function replaceWithSourceString(replacement) {
function replaceWithSourceString(replacement) {
this.resync();

@@ -54,7 +65,7 @@ let ast;

replacement = `(${replacement})`;
ast = parse(replacement);
ast = (0, _parser.parse)(replacement);
} catch (err) {
const loc = err.loc;
if (loc) {
err.message += " - make sure this is an expression.\n" + codeFrameColumns(replacement, {
err.message += " - make sure this is an expression.\n" + (0, _codeFrame.codeFrameColumns)(replacement, {
start: {

@@ -70,6 +81,6 @@ line: loc.line,

const expressionAST = ast.program.body[0].expression;
traverse.removeProperties(expressionAST);
_index.default.removeProperties(expressionAST);
return this.replaceWith(expressionAST);
}
export function replaceWith(replacementPath) {
function replaceWith(replacementPath) {
this.resync();

@@ -79,3 +90,3 @@ if (this.removed) {

}
let replacement = replacementPath instanceof NodePath ? replacementPath.node : replacementPath;
let replacement = replacementPath instanceof _index2.default ? replacementPath.node : replacementPath;
if (!replacement) {

@@ -119,3 +130,3 @@ throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");

}
export function _replaceWith(node) {
function _replaceWith(node) {
var _pathCache$get2;

@@ -131,6 +142,6 @@ if (!this.container) {

this.debug(`Replace with ${node == null ? void 0 : node.type}`);
(_pathCache$get2 = pathCache.get(this.parent)) == null ? void 0 : _pathCache$get2.set(node, this).delete(this.node);
(_pathCache$get2 = _cache.path.get(this.parent)) == null ? void 0 : _pathCache$get2.set(node, this).delete(this.node);
this.node = this.container[this.key] = node;
}
export function replaceExpressionWithStatements(nodes) {
function replaceExpressionWithStatements(nodes) {
this.resync();

@@ -147,3 +158,3 @@ const nodesAsSequenceExpression = toSequenceExpression(nodes, this.scope);

const callee = this.get("callee");
hoistVariables(callee.get("body"), id => {
(0, _helperHoistVariables.default)(callee.get("body"), id => {
this.scope.push({

@@ -173,4 +184,4 @@ id

const newCallee = callee;
const needToAwaitFunction = isParentAsync && traverse.hasType(this.get("callee.body").node, "AwaitExpression", FUNCTION_TYPES);
const needToYieldFunction = isParentGenerator && traverse.hasType(this.get("callee.body").node, "YieldExpression", FUNCTION_TYPES);
const needToAwaitFunction = isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", FUNCTION_TYPES);
const needToYieldFunction = isParentGenerator && _index.default.hasType(this.get("callee.body").node, "YieldExpression", FUNCTION_TYPES);
if (needToAwaitFunction) {

@@ -188,3 +199,3 @@ newCallee.set("async", true);

}
export function replaceInline(nodes) {
function replaceInline(nodes) {
this.resync();

@@ -191,0 +202,0 @@ if (Array.isArray(nodes)) {

@@ -1,2 +0,8 @@

export default class Binding {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
class Binding {
constructor({

@@ -62,2 +68,3 @@ identifier,

}
exports.default = Binding;
function isDeclaredInLoop(path) {

@@ -64,0 +71,0 @@ for (let {

@@ -1,6 +0,13 @@

import Renamer from "./lib/renamer.js";
import traverse from "../index.js";
import Binding from "./binding.js";
import globals from "globals";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _renamer = require("./lib/renamer");
var _index = require("../index");
var _binding = require("./binding");
var _globals = require("globals");
var _t = require("@babel/types");
var _cache = require("../cache");
const {

@@ -52,3 +59,2 @@ NOT_LOCAL_BINDING,

} = _t;
import { scope as scopeCache } from "../cache.js";
function gatherNodeParts(node, parts) {

@@ -272,3 +278,3 @@ switch (node == null ? void 0 : node.type) {

let uid = 0;
export default class Scope {
class Scope {
constructor(path) {

@@ -289,7 +295,7 @@ this.uid = void 0;

} = path;
const cached = scopeCache.get(node);
const cached = _cache.scope.get(node);
if ((cached == null ? void 0 : cached.path) === path) {
return cached;
}
scopeCache.set(node, this);
_cache.scope.set(node, this);
this.uid = uid++;

@@ -320,3 +326,3 @@ this.block = node;

traverse(node, opts, state) {
traverse(node, opts, this, state, this.path);
(0, _index.default)(node, opts, this, state, this.path);
}

@@ -401,3 +407,3 @@ generateDeclaredUidIdentifier(name) {

newName || (newName = this.generateUidIdentifier(oldName).name);
const renamer = new Renamer(binding, oldName, newName);
const renamer = new _renamer.default(binding, oldName, newName);
{

@@ -536,3 +542,3 @@ renamer.rename(arguments[2]);

} else {
this.bindings[name] = new Binding({
this.bindings[name] = new _binding.default({
identifier: id,

@@ -870,5 +876,6 @@ scope: this,

}
Scope.globals = Object.keys(globals.builtin);
exports.default = Scope;
Scope.globals = Object.keys(_globals.builtin);
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
//# sourceMappingURL=index.js.map

@@ -1,6 +0,12 @@

import splitExportDeclaration from "@babel/helper-split-export-declaration";
import * as t from "@babel/types";
import { requeueComputedKeyAndDecorators } from "@babel/helper-environment-visitor";
import { traverseNode } from "../../traverse-node.js";
import { explode } from "../../visitors.js";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
var t = require("@babel/types");
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
var _traverseNode = require("../../traverse-node");
var _visitors = require("../../visitors");
const renameVisitor = {

@@ -18,3 +24,3 @@ ReferencedIdentifier({

if (path.isMethod()) {
requeueComputedKeyAndDecorators(path);
(0, _helperEnvironmentVisitor.requeueComputedKeyAndDecorators)(path);
}

@@ -31,3 +37,3 @@ }

};
export default class Renamer {
class Renamer {
constructor(binding, oldName, newName) {

@@ -54,3 +60,3 @@ this.newName = newName;

}
splitExportDeclaration(maybeExportDeclar);
(0, _helperSplitExportDeclaration.default)(maybeExportDeclar);
}

@@ -81,3 +87,3 @@ maybeConvertFromClassFunctionDeclaration(path) {

const blockToTraverse = arguments[0] || scope.block;
traverseNode(blockToTraverse, explode(renameVisitor), scope, this, scope.path, {
(0, _traverseNode.traverseNode)(blockToTraverse, (0, _visitors.explode)(renameVisitor), scope, this, scope.path, {
discriminant: true

@@ -96,3 +102,4 @@ });

}
exports.default = Renamer;
//# sourceMappingURL=renamer.js.map

@@ -1,10 +0,16 @@

import TraversalContext from "./context.js";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.traverseNode = traverseNode;
var _context = require("./context");
var _t = require("@babel/types");
const {
VISITOR_KEYS
} = _t;
export function traverseNode(node, opts, scope, state, path, skipKeys) {
function traverseNode(node, opts, scope, state, path, skipKeys) {
const keys = VISITOR_KEYS[node.type];
if (!keys) return false;
const context = new TraversalContext(scope, opts, state, path);
const context = new _context.default(scope, opts, state, path);
for (const key of keys) {

@@ -11,0 +17,0 @@ if (skipKeys && skipKeys[key]) continue;

@@ -1,3 +0,11 @@

import * as virtualTypes from "./path/lib/virtual-types.js";
import * as _t from "@babel/types";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.explode = explode;
exports.merge = merge;
exports.verify = verify;
var virtualTypes = require("./path/lib/virtual-types");
var _t = require("@babel/types");
const {

@@ -13,3 +21,3 @@ DEPRECATED_KEYS,

}
export function explode(visitor) {
function explode(visitor) {
if (visitor._exploded) return visitor;

@@ -82,3 +90,3 @@ visitor._exploded = true;

}
export function verify(visitor) {
function verify(visitor) {
if (visitor._verified) return;

@@ -117,3 +125,3 @@ if (typeof visitor === "function") {

}
export function merge(visitors, states = [], wrapper) {
function merge(visitors, states = [], wrapper) {
const rootVisitor = {};

@@ -120,0 +128,0 @@ for (let i = 0; i < visitors.length; i++) {

{
"name": "@babel/traverse",
"version": "7.21.4-esm.2",
"version": "7.21.4-esm.3",
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",

@@ -19,10 +19,10 @@ "author": "The Babel Team (https://babel.dev/team)",

"dependencies": {
"@babel/code-frame": "7.21.4-esm.2",
"@babel/generator": "7.21.4-esm.2",
"@babel/helper-environment-visitor": "7.21.4-esm.2",
"@babel/helper-function-name": "7.21.4-esm.2",
"@babel/helper-hoist-variables": "7.21.4-esm.2",
"@babel/helper-split-export-declaration": "7.21.4-esm.2",
"@babel/parser": "7.21.4-esm.2",
"@babel/types": "7.21.4-esm.2",
"@babel/code-frame": "7.21.4-esm.3",
"@babel/generator": "7.21.4-esm.3",
"@babel/helper-environment-visitor": "7.21.4-esm.3",
"@babel/helper-function-name": "7.21.4-esm.3",
"@babel/helper-hoist-variables": "7.21.4-esm.3",
"@babel/helper-split-export-declaration": "7.21.4-esm.3",
"@babel/parser": "7.21.4-esm.3",
"@babel/types": "7.21.4-esm.3",
"debug": "^4.1.0",

@@ -32,3 +32,3 @@ "globals": "^11.1.0"

"devDependencies": {
"@babel/helper-plugin-test-runner": "7.21.4-esm.2"
"@babel/helper-plugin-test-runner": "7.21.4-esm.3"
},

@@ -35,0 +35,0 @@ "engines": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc