Socket
Socket
Sign inDemoInstall

@babel/traverse

Package Overview
Dependencies
Maintainers
4
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/traverse - npm Package Compare versions

Comparing version 7.22.8 to 8.0.0-alpha.0

25

lib/cache.js

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

"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() {
export let path = new WeakMap();
export let scope = new WeakMap();
export function clear() {
clearPath();
clearScope();
}
function clearPath() {
exports.path = path = new WeakMap();
export function clearPath() {
path = new WeakMap();
}
function clearScope() {
exports.scope = scope = new WeakMap();
export function clearScope() {
scope = new WeakMap();
}
//# sourceMappingURL=cache.js.map

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

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

@@ -21,2 +13,4 @@ this.scope = scope;

}
queue = null;
priorityQueue = null;
shouldVisit(node) {

@@ -27,3 +21,3 @@ const opts = this.opts;

const keys = VISITOR_KEYS[node.type];
if (!(keys != null && keys.length)) return false;
if (!keys?.length) return false;
for (const key of keys) {

@@ -37,3 +31,3 @@ if (node[key]) {

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

@@ -116,4 +110,3 @@ parent: node,

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

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

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

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

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

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

"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");
import * as _t from "@babel/types";
const {
VISITOR_KEYS
} = _t;
function findParent(callback) {
export function findParent(callback) {
let path = this;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

"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) {
import { traverseNode } from "../traverse-node.js";
import { SHOULD_SKIP, SHOULD_STOP } from "./index.js";
export function call(key) {
const opts = this.opts;

@@ -35,8 +10,7 @@ this.debug(key);

if (this.node) {
var _opts$this$node$type;
return this._call((_opts$this$node$type = opts[this.node.type]) == null ? void 0 : _opts$this$node$type[key]);
return this._call(opts[this.node.type]?.[key]);
}
return false;
}
function _call(fns) {
export function _call(fns) {
if (!fns) return false;

@@ -59,7 +33,7 @@ for (const fn of fns) {

}
function isDenylisted() {
var _this$opts$denylist;
const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
export function isDenylisted() {
const denylist = this.opts.denylist ?? this.opts.blacklist;
return denylist && denylist.indexOf(this.node.type) > -1;
}
export { isDenylisted as isBlacklisted };
function restoreContext(path, context) {

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

}
function visit() {
var _this$opts$shouldSkip, _this$opts;
export function visit() {
if (!this.node) {

@@ -81,3 +54,3 @@ return false;

}
if ((_this$opts$shouldSkip = (_this$opts = this.opts).shouldSkip) != null && _this$opts$shouldSkip.call(_this$opts, this)) {
if (this.opts.shouldSkip?.(this)) {
return false;

@@ -92,3 +65,3 @@ }

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

@@ -98,6 +71,6 @@ this.call("exit");

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

@@ -108,8 +81,7 @@ this.skipKeys = {};

}
function stop() {
this._traverseFlags |= _index.SHOULD_SKIP | _index.SHOULD_STOP;
export function stop() {
this._traverseFlags |= SHOULD_SKIP | SHOULD_STOP;
}
function setScope() {
var _this$opts2, _this$scope;
if ((_this$opts2 = this.opts) != null && _this$opts2.noScope) return;
export function setScope() {
if (this.opts?.noScope) return;
let path = this.parentPath;

@@ -121,4 +93,3 @@ if ((this.key === "key" || this.listKey === "decorators") && path.isMethod() || this.key === "discriminant" && path.isSwitchStatement()) {

while (path && !target) {
var _path$opts;
if ((_path$opts = path.opts) != null && _path$opts.noScope) return;
if (path.opts?.noScope) return;
target = path.scope;

@@ -128,5 +99,5 @@ path = path.parentPath;

this.scope = this.getScope(target);
(_this$scope = this.scope) == null ? void 0 : _this$scope.init();
this.scope?.init();
}
function setContext(context) {
export function setContext(context) {
if (this.skipKeys != null) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -213,11 +184,12 @@ this.container = container;

}
function setKey(key) {
var _this$node;
export function setKey(key) {
this.key = key;
this.node = this.container[this.key];
this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;
this.type = this.node?.type;
}
function requeue(pathToQueue = this) {
export function requeue(pathToQueue = this) {
if (pathToQueue.removed) return;
;
{
pathToQueue.shouldSkip = false;
}
const contexts = this.contexts;

@@ -228,3 +200,3 @@ for (const context of contexts) {

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

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

@@ -1,14 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.arrowFunctionToExpression = arrowFunctionToExpression;
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");
import * as _t from "@babel/types";
const {

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

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

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

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

@@ -92,11 +83,4 @@ const bodyNode = body.node;

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

@@ -110,9 +94,6 @@ throw this.buildCodeFrameError("Can only unwrap the environment of a function.");

}
function arrowFunctionToExpression({
export function arrowFunctionToExpression({
allowInsertArrow = true,
allowInsertArrowWithRest = allowInsertArrow,
noNewArrows = !(() => {
var _arguments$;
return (_arguments$ = arguments[0]) == null ? void 0 : _arguments$.specCompliant;
})()
noNewArrows = true
} = {}) {

@@ -137,3 +118,3 @@ if (!this.isArrowFunctionExpression()) {

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

@@ -143,3 +124,3 @@ }

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

@@ -151,3 +132,3 @@ allSuperCalls

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

@@ -157,4 +138,3 @@ let arrowParent;

if (p.isArrowFunctionExpression()) {
var _arrowParent;
(_arrowParent = arrowParent) != null ? _arrowParent : arrowParent = p;
arrowParent ??= p;
return false;

@@ -340,3 +320,3 @@ }

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

@@ -351,3 +331,3 @@ supers,

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

@@ -402,3 +382,3 @@ return getBinding(thisEnvFn, "this", thisBinding => {

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

@@ -461,3 +441,3 @@ thisPaths

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

@@ -464,0 +444,0 @@ const thisPaths = [];

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

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

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

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

@@ -232,3 +225,3 @@ if (res.confident) return !!res.value;

if (!state.confident) return;
return left != null ? left : right;
return left ?? right;
}

@@ -253,3 +246,3 @@ }

case "**":
return Math.pow(left, right);
return left ** right;
case "<":

@@ -328,3 +321,3 @@ return left < right;

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

@@ -331,0 +324,0 @@ confident: true,

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

"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");
import NodePath from "./index.js";
import * as _t from "@babel/types";
const {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -1,50 +0,30 @@

"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");
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";
const {
validate
} = _t;
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;
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;
class NodePath {
constructor(hub, parent) {
this.contexts = [];
this.state = null;
this.opts = null;
this._traverseFlags = 0;
this.skipKeys = null;
this.parentPath = null;
this.container = null;
this.listKey = null;
this.key = null;
this.node = null;
this.type = null;
this.parent = parent;

@@ -56,2 +36,13 @@ this.hub = hub;

}
contexts = [];
state = null;
opts = null;
_traverseFlags = 0;
skipKeys = null;
parentPath = null;
container = null;
listKey = null;
key = null;
node = null;
type = null;
static get({

@@ -72,6 +63,6 @@ hub,

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

@@ -87,3 +78,3 @@ let path = paths.get(targetNode);

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

@@ -111,3 +102,3 @@ setData(key, val) {

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

@@ -133,3 +124,3 @@ set(key, node) {

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

@@ -179,5 +170,3 @@ get inList() {

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);
{
NodePath.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
}
;
for (const type of t.TYPES) {

@@ -200,5 +189,4 @@ const typeKey = `is${type}`;

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

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

"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");
import * as inferers from "./inferers.js";
import * as _t from "@babel/types";
const {

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

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

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

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

@@ -76,3 +65,2 @@ if (!node) {

try {
var _inferer;
let inferer = inferers[node.type];

@@ -83,3 +71,3 @@ if (inferer) {

inferer = inferers[this.parentPath.type];
if ((_inferer = inferer) != null && _inferer.validParent) {
if (inferer?.validParent) {
return this.parentPath.getTypeAnnotation();

@@ -91,3 +79,3 @@ }

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

@@ -118,3 +106,3 @@ }

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

@@ -133,3 +121,3 @@ if (isAnyTypeAnnotation(type)) return true;

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

@@ -142,3 +130,3 @@ const right = rightArg.getTypeAnnotation();

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

@@ -145,0 +133,0 @@ if (genericName === "Array") {

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

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

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

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

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

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

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

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

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

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

"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");
import * as _t from "@babel/types";
const {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -15,14 +9,10 @@ createFlowUnionType,

} = _t;
function createUnionType(types) {
export function createUnionType(types) {
{
if (isFlowType(types[0])) {
if (createFlowUnionType) {
return createFlowUnionType(types);
}
return createUnionTypeAnnotation(types);
} else {
if (createTSUnionType) {
return createTSUnionType(types);
}
return createFlowUnionType(types);
}
if (isTSType(types[0])) {
return createTSUnionType(types);
}
}

@@ -29,0 +19,0 @@ }

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

"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");
import * as _t from "@babel/types";
const {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -45,11 +39,11 @@ cloneNode,

};
class PathHoister {
export default class PathHoister {
breakOnScopePaths;
bindings;
mutableBinding;
scopes;
scope;
path;
attachAfter;
constructor(path, scope) {
this.breakOnScopePaths = void 0;
this.bindings = void 0;
this.mutableBinding = void 0;
this.scopes = void 0;
this.scope = void 0;
this.path = void 0;
this.attachAfter = void 0;
this.breakOnScopePaths = [];

@@ -170,4 +164,3 @@ this.bindings = {};

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

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

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

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

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

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

"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");
import * as _t from "@babel/types";
const {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

"use strict";
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"];
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,20 +0,5 @@

"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");
import { path as pathCache } from "../cache.js";
import PathHoister from "./lib/hoister.js";
import NodePath from "./index.js";
import * as _t from "@babel/types";
const {

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

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

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

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

@@ -70,3 +55,3 @@ const paths = [];

paths.push(path);
if (this.context && this.context.queue) {
if (this.context?.queue) {
path.pushContext(this.context);

@@ -85,6 +70,6 @@ }

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

@@ -103,3 +88,3 @@ }

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

@@ -164,5 +149,5 @@ if (this.isSequenceExpression()) {

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

@@ -174,3 +159,3 @@ if (typeof path.key === "number" && path.key >= fromIndex) {

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

@@ -191,3 +176,3 @@ return [];

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

@@ -202,6 +187,6 @@ }

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

@@ -215,7 +200,7 @@ parent: this.node,

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

@@ -229,4 +214,4 @@ parent: this.node,

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

@@ -233,0 +218,0 @@ }

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

"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;
import { hooks } from "./lib/removal-hooks.js";
import { path as pathCache } from "../cache.js";
import { REMOVED, SHOULD_SKIP } from "./index.js";
export function remove() {
this._assertUnremoved();
this.resync();
if (!((_this$opts = this.opts) != null && _this$opts.noScope)) {
if (!this.opts?.noScope) {
this._removeFromScope();

@@ -30,12 +18,12 @@ }

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

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

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

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

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

"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");
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";
const {

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

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

@@ -48,3 +36,3 @@ nodes = this._verifyNodeList(nodes);

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

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

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

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

replacement = `(${replacement})`;
ast = (0, _parser.parse)(replacement);
ast = parse(replacement);
} catch (err) {
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" + codeFrameColumns(replacement, {
start: {

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

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

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

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

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

}
function _replaceWith(node) {
var _pathCache$get2;
export function _replaceWith(node) {
if (!this.container) {

@@ -141,7 +128,7 @@ throw new ReferenceError("Container is falsy");

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

@@ -153,8 +140,8 @@ const nodesAsSequenceExpression = toSequenceExpression(nodes, this.scope);

const functionParent = this.getFunctionParent();
const isParentAsync = functionParent == null ? void 0 : functionParent.is("async");
const isParentGenerator = functionParent == null ? void 0 : functionParent.is("generator");
const isParentAsync = functionParent?.is("async");
const isParentGenerator = functionParent?.is("generator");
const container = arrowFunctionExpression([], blockStatement(nodes));
this.replaceWith(callExpression(container, []));
const callee = this.get("callee");
(0, _helperHoistVariables.default)(callee.get("body"), id => {
hoistVariables(callee.get("body"), id => {
this.scope.push({

@@ -184,4 +171,4 @@ id

const newCallee = callee;
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);
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);
if (needToAwaitFunction) {

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

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

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

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

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

@@ -14,11 +12,2 @@ identifier,

}) {
this.identifier = void 0;
this.scope = void 0;
this.path = void 0;
this.kind = void 0;
this.constantViolations = [];
this.constant = true;
this.referencePaths = [];
this.referenced = false;
this.references = 0;
this.identifier = identifier;

@@ -35,2 +24,7 @@ this.scope = scope;

}
constantViolations = [];
constant = true;
referencePaths = [];
referenced = false;
references = 0;
deoptValue() {

@@ -70,3 +64,2 @@ this.clearValue();

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

@@ -73,0 +66,0 @@ for (let {

@@ -1,15 +0,6 @@

"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 t = _t;
var _cache = require("../cache");
var _visitors = require("../visitors");
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";
const {

@@ -61,4 +52,7 @@ NOT_LOCAL_BINDING,

} = _t;
import * as t from "@babel/types";
import { scope as scopeCache } from "../cache.js";
import { isExplodedVisitor } from "../visitors.js";
function gatherNodeParts(node, parts) {
switch (node == null ? void 0 : node.type) {
switch (node?.type) {
default:

@@ -68,3 +62,3 @@ if (isImportDeclaration(node) || isExportDeclaration(node)) {

gatherNodeParts(node.source, parts);
} else if ((isExportNamedDeclaration(node) || isImportDeclaration(node)) && node.specifiers && node.specifiers.length) {
} else if ((isExportNamedDeclaration(node) || isImportDeclaration(node)) && node.specifiers?.length) {
for (const e of node.specifiers) gatherNodeParts(e, parts);

@@ -226,3 +220,3 @@ } else if ((isExportDefaultDeclaration(node) || isExportNamedDeclaration(node)) && node.declaration) {

const binding = scope.getBinding(id.name);
binding == null ? void 0 : binding.reference(path);
binding?.reference(path);
} else if (isVariableDeclaration(declar)) {

@@ -232,3 +226,3 @@ for (const decl of declar.declarations) {

const binding = scope.getBinding(name);
binding == null ? void 0 : binding.reference(path);
binding?.reference(path);
}

@@ -283,23 +277,23 @@ }

let uid = 0;
class Scope {
export default class Scope {
uid;
path;
block;
labels;
inited;
bindings;
references;
globals;
uids;
data;
crawling;
constructor(path) {
this.uid = void 0;
this.path = void 0;
this.block = void 0;
this.labels = void 0;
this.inited = void 0;
this.bindings = void 0;
this.references = void 0;
this.globals = void 0;
this.uids = void 0;
this.data = void 0;
this.crawling = void 0;
const {
node
} = path;
const cached = _cache.scope.get(node);
if ((cached == null ? void 0 : cached.path) === path) {
const cached = scopeCache.get(node);
if (cached?.path === path) {
return cached;
}
_cache.scope.set(node, this);
scopeCache.set(node, this);
this.uid = uid++;

@@ -311,4 +305,5 @@ this.block = node;

}
static globals = Object.keys(globals.builtin);
static contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
get parent() {
var _parent;
let parent,

@@ -322,3 +317,3 @@ path = this.path;

} while (path && !parent);
return (_parent = parent) == null ? void 0 : _parent.scope;
return parent?.scope;
}

@@ -332,3 +327,3 @@ get parentBlock() {

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

@@ -412,6 +407,6 @@ generateDeclaredUidIdentifier(name) {

if (binding) {
newName || (newName = this.generateUidIdentifier(oldName).name);
const renamer = new _renamer.default(binding, oldName, newName);
newName ||= this.generateUidIdentifier(oldName).name;
const renamer = new Renamer(binding, oldName, newName);
{
renamer.rename(arguments[2]);
renamer.rename();
}

@@ -447,3 +442,3 @@ }

const binding = this.getBinding(node.name);
if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
if (binding?.constant && binding.path.isGenericType("Array")) {
return node;

@@ -523,4 +518,3 @@ }

for (const name of Object.keys(ids)) {
var _this$getBinding;
(_this$getBinding = this.getBinding(name)) == null ? void 0 : _this$getBinding.reassign(path);
this.getBinding(name)?.reassign(path);
}

@@ -550,3 +544,3 @@ }

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

@@ -590,7 +584,6 @@ scope: this,

} else if (isClass(node)) {
var _node$decorators;
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
return false;
}
if (((_node$decorators = node.decorators) == null ? void 0 : _node$decorators.length) > 0) {
if (node.decorators?.length > 0) {
return false;

@@ -617,5 +610,4 @@ }

} else if (isMethod(node)) {
var _node$decorators2;
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
if (((_node$decorators2 = node.decorators) == null ? void 0 : _node$decorators2.length) > 0) {
if (node.decorators?.length > 0) {
return false;

@@ -625,5 +617,4 @@ }

} else if (isProperty(node)) {
var _node$decorators3;
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
if (((_node$decorators3 = node.decorators) == null ? void 0 : _node$decorators3.length) > 0) {
if (node.decorators?.length > 0) {
return false;

@@ -688,3 +679,3 @@ }

this.crawling = true;
if (path.type !== "Program" && (0, _visitors.isExplodedVisitor)(collectorVisitor)) {
if (path.type !== "Program" && isExplodedVisitor(collectorVisitor)) {
for (const visit of collectorVisitor.enter) {

@@ -834,4 +825,3 @@ visit.call(state, path, state);

if (binding) {
var _previousPath;
if ((_previousPath = previousPath) != null && _previousPath.isPattern() && binding.kind !== "param" && binding.kind !== "local") {} else {
if (previousPath?.isPattern() && binding.kind !== "param" && binding.kind !== "local") {} else {
return binding;

@@ -849,8 +839,7 @@ }

getBindingIdentifier(name) {
var _this$getBinding2;
return (_this$getBinding2 = this.getBinding(name)) == null ? void 0 : _this$getBinding2.identifier;
return this.getBinding(name)?.identifier;
}
getOwnBindingIdentifier(name) {
const binding = this.bindings[name];
return binding == null ? void 0 : binding.identifier;
return binding?.identifier;
}

@@ -861,3 +850,2 @@ hasOwnBinding(name) {

hasBinding(name, opts) {
var _opts, _opts2, _opts3;
if (!name) return false;

@@ -871,10 +859,9 @@ if (this.hasOwnBinding(name)) return true;

if (this.parentHasBinding(name, opts)) return true;
if (!((_opts = opts) != null && _opts.noUids) && this.hasUid(name)) return true;
if (!((_opts2 = opts) != null && _opts2.noGlobals) && Scope.globals.includes(name)) return true;
if (!((_opts3 = opts) != null && _opts3.noGlobals) && Scope.contextVariables.includes(name)) return true;
if (!opts?.noUids && this.hasUid(name)) return true;
if (!opts?.noGlobals && Scope.globals.includes(name)) return true;
if (!opts?.noGlobals && Scope.contextVariables.includes(name)) return true;
return false;
}
parentHasBinding(name, opts) {
var _this$parent;
return (_this$parent = this.parent) == null ? void 0 : _this$parent.hasBinding(name, opts);
return this.parent?.hasBinding(name, opts);
}

@@ -893,4 +880,3 @@ moveBindingTo(name, scope) {

removeBinding(name) {
var _this$getBinding3;
(_this$getBinding3 = this.getBinding(name)) == null ? void 0 : _this$getBinding3.scope.removeOwnBinding(name);
this.getBinding(name)?.scope.removeOwnBinding(name);
let scope = this;

@@ -904,6 +890,3 @@ do {

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

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

"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");
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";
const renameVisitor = {

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

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

@@ -37,5 +31,4 @@ }

if (node.shorthand && (name === state.oldName || name === state.newName) && scope.getBindingIdentifier(name) === state.binding.identifier) {
var _node$extra;
node.shorthand = false;
if ((_node$extra = node.extra) != null && _node$extra.shorthand) node.extra.shorthand = false;
if (node.extra?.shorthand) node.extra.shorthand = false;
}

@@ -51,3 +44,3 @@ },

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

@@ -74,3 +67,3 @@ this.newName = newName;

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

@@ -100,7 +93,7 @@ maybeConvertFromClassFunctionDeclaration(path) {

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

@@ -116,4 +109,3 @@ scope.bindings[newName] = binding;

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

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

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

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

@@ -1,12 +0,3 @@

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

@@ -22,6 +13,6 @@ DEPRECATED_KEYS,

}
function isExplodedVisitor(visitor) {
return visitor == null ? void 0 : visitor._exploded;
export function isExplodedVisitor(visitor) {
return visitor?._exploded;
}
function explode(visitor) {
export function explode(visitor) {
if (isExplodedVisitor(visitor)) return visitor;

@@ -94,3 +85,3 @@ visitor._exploded = true;

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

@@ -129,3 +120,3 @@ if (typeof visitor === "function") {

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

@@ -146,7 +137,12 @@ for (let i = 0; i < visitors.length; i++) {

}
const nodeVisitor = mergedVisitor[key] || (mergedVisitor[key] = {});
const nodeVisitor = mergedVisitor[key] ||= {};
mergePair(nodeVisitor, typeVisitor);
}
}
;
{
return Object.assign({}, mergedVisitor, {
_exploded: true,
_verified: true
});
}
return mergedVisitor;

@@ -167,3 +163,3 @@ }

if (wrapper) {
newFn = wrapper(state == null ? void 0 : state.key, phase, newFn);
newFn = wrapper(state?.key, phase, newFn);
}

@@ -209,7 +205,3 @@ if (newFn !== fn) {

}
{
if (key === "blacklist") {
return true;
}
}
;
return false;

@@ -216,0 +208,0 @@ }

{
"name": "@babel/traverse",
"version": "7.22.8",
"version": "8.0.0-alpha.0",
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",

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

"dependencies": {
"@babel/code-frame": "^7.22.5",
"@babel/generator": "^7.22.7",
"@babel/helper-environment-visitor": "^7.22.5",
"@babel/helper-function-name": "^7.22.5",
"@babel/helper-hoist-variables": "^7.22.5",
"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/parser": "^7.22.7",
"@babel/types": "^7.22.5",
"@babel/code-frame": "^8.0.0-alpha.0",
"@babel/generator": "^8.0.0-alpha.0",
"@babel/helper-environment-visitor": "^8.0.0-alpha.0",
"@babel/helper-function-name": "^8.0.0-alpha.0",
"@babel/helper-hoist-variables": "^8.0.0-alpha.0",
"@babel/helper-split-export-declaration": "^8.0.0-alpha.0",
"@babel/parser": "^8.0.0-alpha.0",
"@babel/types": "^8.0.0-alpha.0",
"debug": "^4.1.0",
"globals": "^11.1.0"
"globals": "^13.5.0"
},
"devDependencies": {
"@babel/helper-plugin-test-runner": "^7.22.5"
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0"
},
"engines": {
"node": ">=6.9.0"
"node": "^16.20.0 || ^18.16.0 || >=20.0.0"
},
"type": "commonjs"
"exports": {
".": "./lib/index.js",
"./package.json": "./package.json"
},
"type": "module"
}

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 too big to display

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc