feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
exports.default = void 0;
var _index = require("./path/index.js");
var _t = require("@babel/types");
var _context = require("./path/context.js");
const {
VISITOR_KEYS
} = _t;
@@ -76,9 +77,9 @@ class TraversalContext {
for (; visitIndex < queue.length;) {
const path = queue[visitIndex];
visitIndex++;
path.resync();
_context.resync.call(path);
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
path.pushContext(this);
_context.pushContext.call(path, this);
}
if (path.key === null) continue;
const {
@@ -98,7 +99,7 @@ class TraversalContext {
}
}
for (let i = 0; i < visitIndex; i++) {
queue[i].popContext();
_context.popContext.call(queue[i]);
}
this.queue = null;
return stop;

File diff suppressed because one or more lines are too long

View File

@@ -10,7 +10,7 @@ exports._resyncList = _resyncList;
exports._resyncParent = _resyncParent;
exports._resyncRemoved = _resyncRemoved;
exports.call = call;
exports.isBlacklisted = exports.isDenylisted = isDenylisted;
exports.isDenylisted = isDenylisted;
exports.popContext = popContext;
exports.pushContext = pushContext;
exports.requeue = requeue;
@@ -61,7 +61,10 @@ function _call(fns) {
function isDenylisted() {
var _this$opts$denylist;
const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
return denylist && denylist.indexOf(this.node.type) > -1;
return denylist == null ? void 0 : denylist.includes(this.node.type);
}
{
exports.isBlacklisted = isDenylisted;
}
function restoreContext(path, context) {
if (path.context !== context) {
@@ -82,7 +85,7 @@ function visit() {
return false;
}
const currentContext = this.context;
if (this.shouldSkip || this.call("enter")) {
if (this.shouldSkip || call.call(this, "enter")) {
this.debug("Skip...");
return this.shouldStop;
}
@@ -90,7 +93,7 @@ function visit() {
this.debug("Recursing into...");
this.shouldStop = (0, _traverseNode.traverseNode)(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
restoreContext(this, currentContext);
this.call("exit");
call.call(this, "exit");
return this.shouldStop;
}
function skip() {
@@ -132,7 +135,7 @@ function setContext(context) {
this.state = context.state;
this.opts = context.opts;
}
this.setScope();
setScope.call(this);
return this;
}
function resync() {
@@ -154,14 +157,14 @@ function _resyncKey() {
if (Array.isArray(this.container)) {
for (let i = 0; i < this.container.length; i++) {
if (this.container[i] === this.node) {
this.setKey(i);
setKey.call(this, i);
return;
}
}
} else {
for (const key of Object.keys(this.container)) {
if (this.container[key] === this.node) {
this.setKey(key);
setKey.call(this, key);
return;
}
}
@@ -195,7 +198,7 @@ function setup(parentPath, container, listKey, key) {
this.listKey = listKey;
this.container = container;
this.parentPath = parentPath || this.parentPath;
this.setKey(key);
setKey.call(this, key);
}
function setKey(key) {
var _this$node;

File diff suppressed because one or more lines are too long

View File

@@ -12,6 +12,7 @@ exports.unwrapFunctionEnvironment = unwrapFunctionEnvironment;
var _t = require("@babel/types");
var _template = require("@babel/template");
var _visitors = require("../visitors.js");
var _context = require("./context.js");
const {
arrowFunctionExpression,
assignmentExpression,
@@ -96,7 +97,7 @@ function ensureBlock() {
}
this.node.body = blockStatement(statements);
const parentPath = this.get(stringPath);
body.setup(parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
_context.setup.call(body, parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key);
return this.node;
}
{

File diff suppressed because one or more lines are too long

View File

@@ -18,7 +18,8 @@ var NodePath_replacement = require("./replacement.js");
var NodePath_evaluation = require("./evaluation.js");
var NodePath_conversion = require("./conversion.js");
var NodePath_introspection = require("./introspection.js");
var NodePath_context = require("./context.js");
var _context = require("./context.js");
var NodePath_context = _context;
var NodePath_removal = require("./removal.js");
var NodePath_modification = require("./modification.js");
var NodePath_family = require("./family.js");
@@ -89,7 +90,7 @@ const NodePath_Final = exports.default = class NodePath {
path = new NodePath(hub, parent);
if (targetNode) paths.set(targetNode, path);
}
path.setup(parentPath, container, listKey, key);
_context.setup.call(path, parentPath, container, listKey, key);
return path;
}
getScope(scope) {
@@ -181,11 +182,7 @@ const methods = {
splitExportDeclaration: NodePath_conversion.splitExportDeclaration,
ensureFunctionName: NodePath_conversion.ensureFunctionName,
matchesPattern: NodePath_introspection.matchesPattern,
has: NodePath_introspection.has,
isStatic: NodePath_introspection.isStatic,
is: NodePath_introspection.is,
isnt: NodePath_introspection.isnt,
equals: NodePath_introspection.equals,
isNodeType: NodePath_introspection.isNodeType,
canHaveVariableDeclarationOrExpression: NodePath_introspection.canHaveVariableDeclarationOrExpression,
canSwapBetweenExpressionAndStatement: NodePath_introspection.canSwapBetweenExpressionAndStatement,
@@ -198,29 +195,19 @@ const methods = {
resolve: NodePath_introspection.resolve,
isConstantExpression: NodePath_introspection.isConstantExpression,
isInStrictMode: NodePath_introspection.isInStrictMode,
call: NodePath_context.call,
isDenylisted: NodePath_context.isDenylisted,
isBlacklisted: NodePath_context.isBlacklisted,
visit: NodePath_context.visit,
skip: NodePath_context.skip,
skipKey: NodePath_context.skipKey,
stop: NodePath_context.stop,
setScope: NodePath_context.setScope,
setContext: NodePath_context.setContext,
resync: NodePath_context.resync,
popContext: NodePath_context.popContext,
pushContext: NodePath_context.pushContext,
setup: NodePath_context.setup,
setKey: NodePath_context.setKey,
requeue: NodePath_context.requeue,
requeueComputedKeyAndDecorators: NodePath_context.requeueComputedKeyAndDecorators,
remove: NodePath_removal.remove,
insertBefore: NodePath_modification.insertBefore,
insertAfter: NodePath_modification.insertAfter,
updateSiblingKeys: NodePath_modification.updateSiblingKeys,
unshiftContainer: NodePath_modification.unshiftContainer,
pushContainer: NodePath_modification.pushContainer,
hoist: NodePath_modification.hoist,
getOpposite: NodePath_family.getOpposite,
getCompletionRecords: NodePath_family.getCompletionRecords,
getSibling: NodePath_family.getSibling,
@@ -241,11 +228,25 @@ const methods = {
Object.assign(NodePath_Final.prototype, methods);
{
NodePath_Final.prototype.arrowFunctionToShadowed = NodePath_conversion[String("arrowFunctionToShadowed")];
Object.assign(NodePath_Final.prototype, {
has: NodePath_introspection[String("has")],
is: NodePath_introspection[String("is")],
isnt: NodePath_introspection[String("isnt")],
equals: NodePath_introspection[String("equals")],
hoist: NodePath_modification[String("hoist")],
updateSiblingKeys: NodePath_modification.updateSiblingKeys,
call: NodePath_context.call,
isBlacklisted: NodePath_context[String("isBlacklisted")],
setScope: NodePath_context.setScope,
resync: NodePath_context.resync,
popContext: NodePath_context.popContext,
pushContext: NodePath_context.pushContext,
setup: NodePath_context.setup,
setKey: NodePath_context.setKey
});
}
{
NodePath_Final.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
}
{
NodePath_Final.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
Object.assign(NodePath_Final.prototype, {
_getTypeAnnotation: NodePath_inference._getTypeAnnotation,

File diff suppressed because one or more lines are too long

View File

@@ -7,17 +7,13 @@ 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;
@@ -37,24 +33,28 @@ const {
function matchesPattern(pattern, allowPartial) {
return _matchesPattern(this.node, pattern, allowPartial);
}
function has(key) {
var _this$node;
const val = (_this$node = this.node) == null ? void 0 : _this$node[key];
if (val && Array.isArray(val)) {
return !!val.length;
} else {
return !!val;
}
{
exports.has = function has(key) {
var _this$node;
const val = (_this$node = this.node) == null ? void 0 : _this$node[key];
if (val && Array.isArray(val)) {
return !!val.length;
} else {
return !!val;
}
};
}
function isStatic() {
return this.scope.isStatic(this.node);
}
const is = exports.is = has;
function isnt(key) {
return !this.has(key);
}
function equals(key, value) {
return this.node[key] === value;
{
exports.is = exports.has;
exports.isnt = function isnt(key) {
return !this.has(key);
};
exports.equals = function equals(key, value) {
return this.node[key] === value;
};
}
function isNodeType(type) {
return isType(this.type, type);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -7,7 +7,6 @@ exports._containerInsert = _containerInsert;
exports._containerInsertAfter = _containerInsertAfter;
exports._containerInsertBefore = _containerInsertBefore;
exports._verifyNodeList = _verifyNodeList;
exports.hoist = hoist;
exports.insertAfter = insertAfter;
exports.insertBefore = insertBefore;
exports.pushContainer = pushContainer;
@@ -60,7 +59,7 @@ function insertBefore(nodes_) {
}
}
function _containerInsert(from, nodes) {
this.updateSiblingKeys(from, nodes.length);
updateSiblingKeys.call(this, from, nodes.length);
const paths = [];
this.container.splice(from, 0, ...nodes);
for (let i = 0; i < nodes.length; i++) {
@@ -69,12 +68,12 @@ function _containerInsert(from, nodes) {
const path = this.getSibling(to);
paths.push(path);
if ((_this$context = this.context) != null && _this$context.queue) {
path.pushContext(this.context);
_context.pushContext.call(path, this.context);
}
}
const contexts = _context._getQueueContexts.call(this);
for (const path of paths) {
path.setScope();
_context.setScope.call(path);
path.debug("Inserted.");
for (const context of contexts) {
context.maybeQueue(path, true);
@@ -164,7 +163,7 @@ function updateSiblingKeys(fromIndex, incrementBy) {
if (!this.parent) return;
const paths = (0, _cache.getCachedPaths)(this.hub, this.parent) || [];
for (const [, path] of paths) {
if (typeof path.key === "number" && path.key >= fromIndex) {
if (typeof path.key === "number" && path.container === this.container && path.key >= fromIndex) {
path.key += incrementBy;
}
}
@@ -220,9 +219,11 @@ function pushContainer(listKey, nodes) {
}).setContext(this.context);
return path.replaceWithMultiple(verifiedNodes);
}
function hoist(scope = this.scope) {
const hoister = new _hoister.default(this, scope);
return hoister.run();
{
exports.hoist = function hoist(scope = this.scope) {
const hoister = new _hoister.default(this, scope);
return hoister.run();
};
}
//# sourceMappingURL=modification.js.map

File diff suppressed because one or more lines are too long

View File

@@ -14,13 +14,15 @@ var _cache = require("../cache.js");
var _replacement = require("./replacement.js");
var _index = require("./index.js");
var _t = require("@babel/types");
var _modification = require("./modification.js");
var _context = require("./context.js");
const {
getBindingIdentifiers
} = _t;
function remove() {
var _this$opts;
_assertUnremoved.call(this);
this.resync();
_context.resync.call(this);
if (_callRemovalHooks.call(this)) {
_markRemoved.call(this);
return;
@@ -46,7 +48,7 @@ function _callRemovalHooks() {
function _remove() {
if (Array.isArray(this.container)) {
this.container.splice(this.key, 1);
this.updateSiblingKeys(this.key, -1);
_modification.updateSiblingKeys.call(this, this.key, -1);
} else {
_replacement._replaceWith.call(this, null);
}

View File

@@ -1 +1 @@
{"version":3,"names":["_removalHooks","require","_cache","_replacement","_index","_t","getBindingIdentifiers","remove","_this$opts","_assertUnremoved","call","resync","_callRemovalHooks","_markRemoved","opts","noScope","_removeFromScope","shareCommentsWithSiblings","_remove","bindings","node","Object","keys","forEach","name","scope","removeBinding","parentPath","fn","hooks","Array","isArray","container","splice","key","updateSiblingKeys","_replaceWith","_traverseFlags","SHOULD_SKIP","REMOVED","parent","getCachedPaths","hub","delete","removed","buildCodeFrameError"],"sources":["../../src/path/removal.ts"],"sourcesContent":["// This file contains methods responsible for removing a node.\n\nimport { hooks } from \"./lib/removal-hooks.ts\";\nimport { getCachedPaths } from \"../cache.ts\";\nimport { _replaceWith } from \"./replacement.ts\";\nimport type NodePath from \"./index.ts\";\nimport { REMOVED, SHOULD_SKIP } from \"./index.ts\";\nimport { getBindingIdentifiers } from \"@babel/types\";\n\nexport function remove(this: NodePath) {\n _assertUnremoved.call(this);\n\n this.resync();\n\n if (_callRemovalHooks.call(this)) {\n _markRemoved.call(this);\n return;\n }\n\n if (!this.opts?.noScope) {\n _removeFromScope.call(this);\n }\n\n this.shareCommentsWithSiblings();\n _remove.call(this);\n _markRemoved.call(this);\n}\n\nexport function _removeFromScope(this: NodePath) {\n const bindings = getBindingIdentifiers(this.node, false, false, true);\n Object.keys(bindings).forEach(name => this.scope.removeBinding(name));\n}\n\nexport function _callRemovalHooks(this: NodePath) {\n if (this.parentPath) {\n for (const fn of hooks) {\n if (fn(this, this.parentPath)) return true;\n }\n }\n}\n\nexport function _remove(this: NodePath) {\n if (Array.isArray(this.container)) {\n this.container.splice(this.key as number, 1);\n this.updateSiblingKeys(this.key as number, -1);\n } else {\n _replaceWith.call(this, null);\n }\n}\n\nexport function _markRemoved(this: NodePath) {\n // this.shouldSkip = true; this.removed = true;\n this._traverseFlags |= SHOULD_SKIP | REMOVED;\n if (this.parent) {\n getCachedPaths(this.hub, this.parent).delete(this.node);\n }\n this.node = null;\n}\n\nexport function _assertUnremoved(this: NodePath) {\n if (this.removed) {\n throw this.buildCodeFrameError(\n \"NodePath has been removed so is read-only.\",\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,EAAA,GAAAJ,OAAA;AAAqD;EAA5CK;AAAqB,IAAAD,EAAA;AAEvB,SAASE,MAAMA,CAAA,EAAiB;EAAA,IAAAC,UAAA;EACrCC,gBAAgB,CAACC,IAAI,CAAC,IAAI,CAAC;EAE3B,IAAI,CAACC,MAAM,CAAC,CAAC;EAEb,IAAIC,iBAAiB,CAACF,IAAI,CAAC,IAAI,CAAC,EAAE;IAChCG,YAAY,CAACH,IAAI,CAAC,IAAI,CAAC;IACvB;EACF;EAEA,IAAI,GAAAF,UAAA,GAAC,IAAI,CAACM,IAAI,aAATN,UAAA,CAAWO,OAAO,GAAE;IACvBC,gBAAgB,CAACN,IAAI,CAAC,IAAI,CAAC;EAC7B;EAEA,IAAI,CAACO,yBAAyB,CAAC,CAAC;EAChCC,OAAO,CAACR,IAAI,CAAC,IAAI,CAAC;EAClBG,YAAY,CAACH,IAAI,CAAC,IAAI,CAAC;AACzB;AAEO,SAASM,gBAAgBA,CAAA,EAAiB;EAC/C,MAAMG,QAAQ,GAAGb,qBAAqB,CAAC,IAAI,CAACc,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC;EACrEC,MAAM,CAACC,IAAI,CAACH,QAAQ,CAAC,CAACI,OAAO,CAACC,IAAI,IAAI,IAAI,CAACC,KAAK,CAACC,aAAa,CAACF,IAAI,CAAC,CAAC;AACvE;AAEO,SAASZ,iBAAiBA,CAAA,EAAiB;EAChD,IAAI,IAAI,CAACe,UAAU,EAAE;IACnB,KAAK,MAAMC,EAAE,IAAIC,mBAAK,EAAE;MACtB,IAAID,EAAE,CAAC,IAAI,EAAE,IAAI,CAACD,UAAU,CAAC,EAAE,OAAO,IAAI;IAC5C;EACF;AACF;AAEO,SAAST,OAAOA,CAAA,EAAiB;EACtC,IAAIY,KAAK,CAACC,OAAO,CAAC,IAAI,CAACC,SAAS,CAAC,EAAE;IACjC,IAAI,CAACA,SAAS,CAACC,MAAM,CAAC,IAAI,CAACC,GAAG,EAAY,CAAC,CAAC;IAC5C,IAAI,CAACC,iBAAiB,CAAC,IAAI,CAACD,GAAG,EAAY,CAAC,CAAC,CAAC;EAChD,CAAC,MAAM;IACLE,yBAAY,CAAC1B,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;EAC/B;AACF;AAEO,SAASG,YAAYA,CAAA,EAAiB;EAE3C,IAAI,CAACwB,cAAc,IAAIC,kBAAW,GAAGC,cAAO;EAC5C,IAAI,IAAI,CAACC,MAAM,EAAE;IACf,IAAAC,qBAAc,EAAC,IAAI,CAACC,GAAG,EAAE,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,CAAC,IAAI,CAACvB,IAAI,CAAC;EACzD;EACA,IAAI,CAACA,IAAI,GAAG,IAAI;AAClB;AAEO,SAASX,gBAAgBA,CAAA,EAAiB;EAC/C,IAAI,IAAI,CAACmC,OAAO,EAAE;IAChB,MAAM,IAAI,CAACC,mBAAmB,CAC5B,4CACF,CAAC;EACH;AACF","ignoreList":[]}
{"version":3,"names":["_removalHooks","require","_cache","_replacement","_index","_t","_modification","_context","getBindingIdentifiers","remove","_this$opts","_assertUnremoved","call","resync","_callRemovalHooks","_markRemoved","opts","noScope","_removeFromScope","shareCommentsWithSiblings","_remove","bindings","node","Object","keys","forEach","name","scope","removeBinding","parentPath","fn","hooks","Array","isArray","container","splice","key","updateSiblingKeys","_replaceWith","_traverseFlags","SHOULD_SKIP","REMOVED","parent","getCachedPaths","hub","delete","removed","buildCodeFrameError"],"sources":["../../src/path/removal.ts"],"sourcesContent":["// This file contains methods responsible for removing a node.\n\nimport { hooks } from \"./lib/removal-hooks.ts\";\nimport { getCachedPaths } from \"../cache.ts\";\nimport { _replaceWith } from \"./replacement.ts\";\nimport type NodePath from \"./index.ts\";\nimport { REMOVED, SHOULD_SKIP } from \"./index.ts\";\nimport { getBindingIdentifiers } from \"@babel/types\";\nimport { updateSiblingKeys } from \"./modification.ts\";\nimport { resync } from \"./context.ts\";\n\nexport function remove(this: NodePath) {\n _assertUnremoved.call(this);\n\n resync.call(this);\n\n if (_callRemovalHooks.call(this)) {\n _markRemoved.call(this);\n return;\n }\n\n if (!this.opts?.noScope) {\n _removeFromScope.call(this);\n }\n\n this.shareCommentsWithSiblings();\n _remove.call(this);\n _markRemoved.call(this);\n}\n\nexport function _removeFromScope(this: NodePath) {\n const bindings = getBindingIdentifiers(this.node, false, false, true);\n Object.keys(bindings).forEach(name => this.scope.removeBinding(name));\n}\n\nexport function _callRemovalHooks(this: NodePath) {\n if (this.parentPath) {\n for (const fn of hooks) {\n if (fn(this, this.parentPath)) return true;\n }\n }\n}\n\nexport function _remove(this: NodePath) {\n if (Array.isArray(this.container)) {\n this.container.splice(this.key as number, 1);\n updateSiblingKeys.call(this, this.key as number, -1);\n } else {\n _replaceWith.call(this, null);\n }\n}\n\nexport function _markRemoved(this: NodePath) {\n // this.shouldSkip = true; this.removed = true;\n this._traverseFlags |= SHOULD_SKIP | REMOVED;\n if (this.parent) {\n getCachedPaths(this.hub, this.parent).delete(this.node);\n }\n this.node = null;\n}\n\nexport function _assertUnremoved(this: NodePath) {\n if (this.removed) {\n throw this.buildCodeFrameError(\n \"NodePath has been removed so is read-only.\",\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAEA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,EAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAAsC;EAF7BO;AAAqB,IAAAH,EAAA;AAIvB,SAASI,MAAMA,CAAA,EAAiB;EAAA,IAAAC,UAAA;EACrCC,gBAAgB,CAACC,IAAI,CAAC,IAAI,CAAC;EAE3BC,eAAM,CAACD,IAAI,CAAC,IAAI,CAAC;EAEjB,IAAIE,iBAAiB,CAACF,IAAI,CAAC,IAAI,CAAC,EAAE;IAChCG,YAAY,CAACH,IAAI,CAAC,IAAI,CAAC;IACvB;EACF;EAEA,IAAI,GAAAF,UAAA,GAAC,IAAI,CAACM,IAAI,aAATN,UAAA,CAAWO,OAAO,GAAE;IACvBC,gBAAgB,CAACN,IAAI,CAAC,IAAI,CAAC;EAC7B;EAEA,IAAI,CAACO,yBAAyB,CAAC,CAAC;EAChCC,OAAO,CAACR,IAAI,CAAC,IAAI,CAAC;EAClBG,YAAY,CAACH,IAAI,CAAC,IAAI,CAAC;AACzB;AAEO,SAASM,gBAAgBA,CAAA,EAAiB;EAC/C,MAAMG,QAAQ,GAAGb,qBAAqB,CAAC,IAAI,CAACc,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC;EACrEC,MAAM,CAACC,IAAI,CAACH,QAAQ,CAAC,CAACI,OAAO,CAACC,IAAI,IAAI,IAAI,CAACC,KAAK,CAACC,aAAa,CAACF,IAAI,CAAC,CAAC;AACvE;AAEO,SAASZ,iBAAiBA,CAAA,EAAiB;EAChD,IAAI,IAAI,CAACe,UAAU,EAAE;IACnB,KAAK,MAAMC,EAAE,IAAIC,mBAAK,EAAE;MACtB,IAAID,EAAE,CAAC,IAAI,EAAE,IAAI,CAACD,UAAU,CAAC,EAAE,OAAO,IAAI;IAC5C;EACF;AACF;AAEO,SAAST,OAAOA,CAAA,EAAiB;EACtC,IAAIY,KAAK,CAACC,OAAO,CAAC,IAAI,CAACC,SAAS,CAAC,EAAE;IACjC,IAAI,CAACA,SAAS,CAACC,MAAM,CAAC,IAAI,CAACC,GAAG,EAAY,CAAC,CAAC;IAC5CC,+BAAiB,CAACzB,IAAI,CAAC,IAAI,EAAE,IAAI,CAACwB,GAAG,EAAY,CAAC,CAAC,CAAC;EACtD,CAAC,MAAM;IACLE,yBAAY,CAAC1B,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;EAC/B;AACF;AAEO,SAASG,YAAYA,CAAA,EAAiB;EAE3C,IAAI,CAACwB,cAAc,IAAIC,kBAAW,GAAGC,cAAO;EAC5C,IAAI,IAAI,CAACC,MAAM,EAAE;IACf,IAAAC,qBAAc,EAAC,IAAI,CAACC,GAAG,EAAE,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,CAAC,IAAI,CAACvB,IAAI,CAAC;EACzD;EACA,IAAI,CAACA,IAAI,GAAG,IAAI;AAClB;AAEO,SAASX,gBAAgBA,CAAA,EAAiB;EAC/C,IAAI,IAAI,CAACmC,OAAO,EAAE;IAChB,MAAM,IAAI,CAACC,mBAAmB,CAC5B,4CACF,CAAC;EACH;AACF","ignoreList":[]}

View File

@@ -16,6 +16,7 @@ var _cache = require("../cache.js");
var _modification = require("./modification.js");
var _parser = require("@babel/parser");
var _t = require("@babel/types");
var _context = require("./context.js");
const {
FUNCTION_TYPES,
arrowFunctionExpression,
@@ -48,7 +49,7 @@ const {
} = _t;
function replaceWithMultiple(nodes) {
var _getCachedPaths;
this.resync();
_context.resync.call(this);
nodes = _modification._verifyNodeList.call(this, nodes);
inheritLeadingComments(nodes[0], this.node);
inheritTrailingComments(nodes[nodes.length - 1], this.node);
@@ -63,7 +64,7 @@ function replaceWithMultiple(nodes) {
return paths;
}
function replaceWithSourceString(replacement) {
this.resync();
_context.resync.call(this);
let ast;
try {
replacement = `(${replacement})`;
@@ -86,7 +87,7 @@ function replaceWithSourceString(replacement) {
return this.replaceWith(expressionAST);
}
function replaceWith(replacementPath) {
this.resync();
_context.resync.call(this);
if (this.removed) {
throw new Error("You can't replace this node, we've already removed it");
}
@@ -125,7 +126,7 @@ function replaceWith(replacementPath) {
}
_replaceWith.call(this, replacement);
this.type = replacement.type;
this.setScope();
_context.setScope.call(this);
this.requeue();
return [nodePath ? this.get(nodePath) : this];
}
@@ -144,7 +145,7 @@ function _replaceWith(node) {
this.node = this.container[this.key] = node;
}
function replaceExpressionWithStatements(nodes) {
this.resync();
_context.resync.call(this);
const declars = [];
const nodesAsSingleExpression = gatherSequenceExpressions(nodes, declars);
if (nodesAsSingleExpression) {
@@ -154,8 +155,8 @@ function replaceExpressionWithStatements(nodes) {
return this.replaceWith(nodesAsSingleExpression)[0].get("expressions");
}
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 == null ? void 0 : functionParent.node.async;
const isParentGenerator = functionParent == null ? void 0 : functionParent.node.generator;
const container = arrowFunctionExpression([], blockStatement(nodes));
this.replaceWith(callExpression(container, []));
const callee = this.get("callee");
@@ -244,7 +245,7 @@ function gatherSequenceExpressions(nodes, declars) {
}
}
function replaceInline(nodes) {
this.resync();
_context.resync.call(this);
if (Array.isArray(nodes)) {
if (Array.isArray(this.container)) {
nodes = _modification._verifyNodeList.call(this, nodes);

File diff suppressed because one or more lines are too long

View File

@@ -271,12 +271,12 @@ const collectorVisitor = {
for (const param of params) {
path.scope.registerBinding("param", param);
}
if (path.isFunctionExpression() && path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
if (path.isFunctionExpression() && path.node.id && !path.node.id[NOT_LOCAL_BINDING]) {
path.scope.registerBinding("local", path.get("id"), path);
}
},
ClassExpression(path) {
if (path.has("id") && !path.get("id").node[NOT_LOCAL_BINDING]) {
if (path.node.id && !path.node.id[NOT_LOCAL_BINDING]) {
path.scope.registerBinding("local", path.get("id"), path);
}
},
@@ -290,8 +290,8 @@ class Scope {
this.uid = void 0;
this.path = void 0;
this.block = void 0;
this.labels = void 0;
this.inited = void 0;
this.labels = void 0;
this.bindings = void 0;
this.references = void 0;
this.globals = void 0;
@@ -325,15 +325,6 @@ class Scope {
} while (path && !parent);
return (_parent = parent) == null ? void 0 : _parent.scope;
}
get parentBlock() {
return this.path.parent;
}
get hub() {
return this.path.hub;
}
traverse(node, opts, state) {
(0, _index.default)(node, opts, this, state, this.path);
}
generateDeclaredUidIdentifier(name) {
const id = this.generateUidIdentifier(name);
this.push({
@@ -349,7 +340,8 @@ class Scope {
let uid;
let i = 1;
do {
uid = this._generateUid(name, i);
uid = `_${name}`;
if (i > 1) uid += i;
i++;
} while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid));
const program = this.getProgramParent();
@@ -357,11 +349,6 @@ class Scope {
program.uids[uid] = true;
return uid;
}
_generateUid(name, i) {
let id = name;
if (i > 1) id += i;
return `_${id}`;
}
generateUidBasedOnNode(node, defaultName) {
const parts = [];
gatherNodeParts(node, parts);
@@ -405,7 +392,7 @@ class Scope {
if (local.kind === "local") return;
const duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module" || local.kind === "param" && kind === "const";
if (duplicate) {
throw this.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
throw this.path.hub.buildError(id, `Duplicate declaration "${name}"`, TypeError);
}
}
rename(oldName, newName) {
@@ -418,12 +405,6 @@ class Scope {
}
}
}
_renameFromMap(map, oldName, newName, value) {
if (map[oldName]) {
map[newName] = value;
map[oldName] = null;
}
}
dump() {
const sep = "-".repeat(60);
console.log(sep);
@@ -442,37 +423,6 @@ class Scope {
} while (scope = scope.parent);
console.log(sep);
}
toArray(node, i, arrayLikeIsIterable) {
if (isIdentifier(node)) {
const binding = this.getBinding(node.name);
if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
return node;
}
}
if (isArrayExpression(node)) {
return node;
}
if (isIdentifier(node, {
name: "arguments"
})) {
return callExpression(memberExpression(memberExpression(memberExpression(identifier("Array"), identifier("prototype")), identifier("slice")), identifier("call")), [node]);
}
let helperName;
const args = [node];
if (i === true) {
helperName = "toConsumableArray";
} else if (typeof i === "number") {
args.push(numericLiteral(i));
helperName = "slicedToArray";
} else {
helperName = "toArray";
}
if (arrayLikeIsIterable) {
args.unshift(this.hub.addHelper(helperName));
helperName = "maybeArrayLike";
}
return callExpression(this.hub.addHelper(helperName), args);
}
hasLabel(name) {
return !!this.getLabel(name);
}
@@ -812,20 +762,6 @@ class Scope {
} while (scope);
return ids;
}
getAllBindingsOfKind(...kinds) {
const ids = Object.create(null);
for (const kind of kinds) {
let scope = this;
do {
for (const name of Object.keys(scope.bindings)) {
const binding = scope.bindings[name];
if (binding.kind === kind) ids[name] = binding;
}
scope = scope.parent;
} while (scope);
}
return ids;
}
bindingIdentifierEquals(name, node) {
return this.getBindingIdentifier(name) === node;
}
@@ -958,5 +894,82 @@ class Scope {
exports.default = Scope;
Scope.globals = Object.keys(_globals.builtin);
Scope.contextVariables = ["arguments", "undefined", "Infinity", "NaN"];
{
Scope.prototype._renameFromMap = function _renameFromMap(map, oldName, newName, value) {
if (map[oldName]) {
map[newName] = value;
map[oldName] = null;
}
};
Scope.prototype.traverse = function (node, opts, state) {
(0, _index.default)(node, opts, this, state, this.path);
};
Scope.prototype._generateUid = function _generateUid(name, i) {
let id = name;
if (i > 1) id += i;
return `_${id}`;
};
Scope.prototype.toArray = function toArray(node, i, arrayLikeIsIterable) {
if (isIdentifier(node)) {
const binding = this.getBinding(node.name);
if (binding != null && binding.constant && binding.path.isGenericType("Array")) {
return node;
}
}
if (isArrayExpression(node)) {
return node;
}
if (isIdentifier(node, {
name: "arguments"
})) {
return callExpression(memberExpression(memberExpression(memberExpression(identifier("Array"), identifier("prototype")), identifier("slice")), identifier("call")), [node]);
}
let helperName;
const args = [node];
if (i === true) {
helperName = "toConsumableArray";
} else if (typeof i === "number") {
args.push(numericLiteral(i));
helperName = "slicedToArray";
} else {
helperName = "toArray";
}
if (arrayLikeIsIterable) {
args.unshift(this.path.hub.addHelper(helperName));
helperName = "maybeArrayLike";
}
return callExpression(this.path.hub.addHelper(helperName), args);
};
Scope.prototype.getAllBindingsOfKind = function getAllBindingsOfKind(...kinds) {
const ids = Object.create(null);
for (const kind of kinds) {
let scope = this;
do {
for (const name of Object.keys(scope.bindings)) {
const binding = scope.bindings[name];
if (binding.kind === kind) ids[name] = binding;
}
scope = scope.parent;
} while (scope);
}
return ids;
};
Object.defineProperties(Scope.prototype, {
parentBlock: {
configurable: true,
enumerable: true,
get() {
return this.path.parent;
}
},
hub: {
configurable: true,
enumerable: true,
get() {
return this.path.hub;
}
}
});
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = void 0;
var t = require("@babel/types");
var _t = t;
var _traverseNode = require("../../traverse-node.js");
var _visitors = require("../../visitors.js");
var _context = require("../../path/context.js");
const {
getAssignmentIdentifiers
} = _t;
const renameVisitor = {
ReferencedIdentifier({
node
@@ -45,7 +49,7 @@ const renameVisitor = {
},
"AssignmentExpression|Declaration|VariableDeclarator"(path, state) {
if (path.isVariableDeclaration()) return;
const ids = path.isAssignmentExpression() ? path.getAssignmentIdentifiers() : path.getOuterBindingIdentifiers();
const ids = path.isAssignmentExpression() ? getAssignmentIdentifiers(path.node) : path.getOuterBindingIdentifiers();
for (const name in ids) {
if (name === state.oldName) ids[name].name = state.newName;
}
@@ -99,9 +103,18 @@ class Renamer {
}
}
const blockToTraverse = arguments[0] || scope.block;
(0, _traverseNode.traverseNode)(blockToTraverse, (0, _visitors.explode)(renameVisitor), scope, this, scope.path, {
const skipKeys = {
discriminant: true
});
};
if (t.isMethod(blockToTraverse)) {
if (blockToTraverse.computed) {
skipKeys.key = true;
}
if (!t.isObjectMethod(blockToTraverse)) {
skipKeys.decorators = true;
}
}
(0, _traverseNode.traverseNode)(blockToTraverse, (0, _visitors.explode)(renameVisitor), scope, this, scope.path, skipKeys);
if (!arguments[0]) {
scope.removeOwnBinding(oldName);
scope.bindings[newName] = binding;

File diff suppressed because one or more lines are too long

View File

@@ -104,7 +104,7 @@ function verify$1(visitor) {
}
if (shouldIgnoreKey(nodeType)) continue;
if (!TYPES.includes(nodeType)) {
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"7.25.3"}`);
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"7.25.9"}`);
}
const visitors = visitor[nodeType];
if (typeof visitors === "object") {

View File

@@ -1,6 +1,6 @@
{
"name": "@babel/traverse",
"version": "7.25.3",
"version": "7.25.9",
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
"author": "The Babel Team (https://babel.dev/team)",
"homepage": "https://babel.dev/docs/en/next/babel-traverse",
@@ -16,17 +16,17 @@
},
"main": "./lib/index.js",
"dependencies": {
"@babel/code-frame": "^7.24.7",
"@babel/generator": "^7.25.0",
"@babel/parser": "^7.25.3",
"@babel/template": "^7.25.0",
"@babel/types": "^7.25.2",
"@babel/code-frame": "^7.25.9",
"@babel/generator": "^7.25.9",
"@babel/parser": "^7.25.9",
"@babel/template": "^7.25.9",
"@babel/types": "^7.25.9",
"debug": "^4.3.1",
"globals": "^11.1.0"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/helper-plugin-test-runner": "^7.24.7"
"@babel/core": "^7.25.9",
"@babel/helper-plugin-test-runner": "^7.25.9"
},
"engines": {
"node": ">=6.9.0"