@babel/traverse 8.0.0-rc.4 → 8.0.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +14 -14
- package/lib/index.js +20 -17
- package/lib/index.js.map +1 -1
- package/package.json +10 -10
package/lib/index.js
CHANGED
|
@@ -362,19 +362,20 @@ function explode$1(visitor) {
|
|
|
362
362
|
delete visitor.__esModule;
|
|
363
363
|
ensureEntranceObjects(visitor);
|
|
364
364
|
ensureCallbackArrays(visitor);
|
|
365
|
+
const visitorBase = visitor;
|
|
365
366
|
for (const nodeType of Object.keys(visitor)) {
|
|
366
367
|
if (shouldIgnoreKey(nodeType)) continue;
|
|
367
368
|
if (!isVirtualType(nodeType)) continue;
|
|
368
|
-
const fns =
|
|
369
|
+
const fns = visitorBase[nodeType];
|
|
369
370
|
for (const type of Object.keys(fns)) {
|
|
370
371
|
fns[type] = wrapCheck(nodeType, fns[type]);
|
|
371
372
|
}
|
|
372
|
-
delete
|
|
373
|
+
delete visitorBase[nodeType];
|
|
373
374
|
const types = virtualTypes[nodeType];
|
|
374
375
|
if (types !== null) {
|
|
375
376
|
for (const type of types) {
|
|
376
|
-
|
|
377
|
-
mergePair(
|
|
377
|
+
visitorBase[type] ??= {};
|
|
378
|
+
mergePair(visitorBase[type], fns);
|
|
378
379
|
}
|
|
379
380
|
} else {
|
|
380
381
|
mergePair(visitor, fns);
|
|
@@ -396,11 +397,11 @@ function explode$1(visitor) {
|
|
|
396
397
|
const fns = visitor[nodeType];
|
|
397
398
|
delete visitor[nodeType];
|
|
398
399
|
for (const alias of aliases) {
|
|
399
|
-
const existing =
|
|
400
|
+
const existing = visitorBase[alias];
|
|
400
401
|
if (existing) {
|
|
401
402
|
mergePair(existing, fns);
|
|
402
403
|
} else {
|
|
403
|
-
|
|
404
|
+
visitorBase[alias] = {
|
|
404
405
|
...fns
|
|
405
406
|
};
|
|
406
407
|
}
|
|
@@ -423,7 +424,7 @@ function verify$1(visitor) {
|
|
|
423
424
|
}
|
|
424
425
|
if (shouldIgnoreKey(nodeType)) continue;
|
|
425
426
|
if (!TYPES.includes(nodeType)) {
|
|
426
|
-
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"8.0.0-rc.
|
|
427
|
+
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"8.0.0-rc.6"}`);
|
|
427
428
|
}
|
|
428
429
|
const visitors = visitor[nodeType];
|
|
429
430
|
if (typeof visitors === "object") {
|
|
@@ -568,7 +569,8 @@ const visitors = /*#__PURE__*/Object.defineProperty({
|
|
|
568
569
|
const {
|
|
569
570
|
getAssignmentIdentifiers: getAssignmentIdentifiers$1
|
|
570
571
|
} = _t;
|
|
571
|
-
|
|
572
|
+
let renameVisitor;
|
|
573
|
+
const getRenameVisitor = () => renameVisitor ??= explode$1({
|
|
572
574
|
ReferencedIdentifier({
|
|
573
575
|
node
|
|
574
576
|
}, state) {
|
|
@@ -605,7 +607,7 @@ const renameVisitor = {
|
|
|
605
607
|
if (name === state.oldName) ids[name].name = state.newName;
|
|
606
608
|
}
|
|
607
609
|
}
|
|
608
|
-
};
|
|
610
|
+
});
|
|
609
611
|
class Renamer {
|
|
610
612
|
constructor(binding, oldName, newName) {
|
|
611
613
|
this.newName = newName;
|
|
@@ -665,7 +667,7 @@ class Renamer {
|
|
|
665
667
|
skipKeys.decorators = true;
|
|
666
668
|
}
|
|
667
669
|
}
|
|
668
|
-
traverseNode(blockToTraverse,
|
|
670
|
+
traverseNode(blockToTraverse, getRenameVisitor(), scope, this, scope.path, skipKeys);
|
|
669
671
|
scope.removeOwnBinding(oldName);
|
|
670
672
|
scope.bindings[newName] = binding;
|
|
671
673
|
this.binding.identifier.name = newName;
|
|
@@ -2392,6 +2394,7 @@ function remove() {
|
|
|
2392
2394
|
_markRemoved.call(this);
|
|
2393
2395
|
}
|
|
2394
2396
|
function _removeFromScope() {
|
|
2397
|
+
if (!this.node) return;
|
|
2395
2398
|
const bindings = _t.getBindingIdentifiers(this.node, false, false, true);
|
|
2396
2399
|
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
|
|
2397
2400
|
}
|
|
@@ -2683,7 +2686,7 @@ function replaceWithSourceString(replacement) {
|
|
|
2683
2686
|
err.message += " - make sure this is an expression.\n" + codeFrameColumns(replacement, {
|
|
2684
2687
|
start: {
|
|
2685
2688
|
line: loc.line,
|
|
2686
|
-
column: loc.column
|
|
2689
|
+
column: loc.column
|
|
2687
2690
|
}
|
|
2688
2691
|
});
|
|
2689
2692
|
err.code = "BABEL_REPLACE_SOURCE_ERROR";
|
|
@@ -3722,7 +3725,7 @@ function splitExportDeclaration() {
|
|
|
3722
3725
|
this.replaceWith(declaration.node);
|
|
3723
3726
|
return this;
|
|
3724
3727
|
}
|
|
3725
|
-
const
|
|
3728
|
+
const getRefersOuterBindingVisitor = () => explode$1({
|
|
3726
3729
|
"ReferencedIdentifier|BindingIdentifier"(path, state) {
|
|
3727
3730
|
if (path.node.name !== state.name) return;
|
|
3728
3731
|
state.needsRename = true;
|
|
@@ -3733,7 +3736,7 @@ const refersOuterBindingVisitor = {
|
|
|
3733
3736
|
path.skip();
|
|
3734
3737
|
}
|
|
3735
3738
|
}
|
|
3736
|
-
};
|
|
3739
|
+
});
|
|
3737
3740
|
function ensureFunctionName(supportUnicodeId) {
|
|
3738
3741
|
if (this.node.id) return this;
|
|
3739
3742
|
const res = getFunctionName(this.node, this.parent);
|
|
@@ -3763,7 +3766,7 @@ function ensureFunctionName(supportUnicodeId) {
|
|
|
3763
3766
|
state.needsRename = true;
|
|
3764
3767
|
}
|
|
3765
3768
|
} else if (scope.parent.hasBinding(name) || scope.hasGlobal(name)) {
|
|
3766
|
-
this.traverse(
|
|
3769
|
+
this.traverse(getRefersOuterBindingVisitor(), state);
|
|
3767
3770
|
}
|
|
3768
3771
|
if (!state.needsRename) {
|
|
3769
3772
|
this.node.id = id;
|
|
@@ -4495,8 +4498,8 @@ function shareCommentsWithSiblings() {
|
|
|
4495
4498
|
if (!trailing && !leading) return;
|
|
4496
4499
|
const prev = this.getSibling(this.key - 1);
|
|
4497
4500
|
const next = this.getSibling(this.key + 1);
|
|
4498
|
-
const hasPrev =
|
|
4499
|
-
const hasNext =
|
|
4501
|
+
const hasPrev = !!prev.node;
|
|
4502
|
+
const hasNext = !!next.node;
|
|
4500
4503
|
if (hasPrev) {
|
|
4501
4504
|
if (leading) {
|
|
4502
4505
|
prev.addComments("trailing", removeIfExisting(leading, prev.node.trailingComments));
|
|
@@ -4875,7 +4878,7 @@ function setup(parentPath, container, listKey, key) {
|
|
|
4875
4878
|
function setKey(key) {
|
|
4876
4879
|
this.key = key;
|
|
4877
4880
|
this.node = this.container[this.key];
|
|
4878
|
-
this.type = this.node?.type;
|
|
4881
|
+
this.type = this.node?.type ?? null;
|
|
4879
4882
|
}
|
|
4880
4883
|
function requeue(pathToQueue = this) {
|
|
4881
4884
|
if (pathToQueue.removed) return;
|