@babel/traverse 7.17.9 → 7.18.0
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.
Potentially problematic release.
This version of @babel/traverse might be problematic. Click here for more details.
@@ -94,9 +94,12 @@ function isCompletionRecord(allowInsideFunction) {
|
|
94
94
|
let first = true;
|
95
95
|
|
96
96
|
do {
|
97
|
-
const
|
97
|
+
const {
|
98
|
+
type,
|
99
|
+
container
|
100
|
+
} = path;
|
98
101
|
|
99
|
-
if (path.isFunction()
|
102
|
+
if (!first && (path.isFunction() || type === "StaticBlock")) {
|
100
103
|
return !!allowInsideFunction;
|
101
104
|
}
|
102
105
|
|
@@ -105,7 +108,7 @@ function isCompletionRecord(allowInsideFunction) {
|
|
105
108
|
if (Array.isArray(container) && path.key !== container.length - 1) {
|
106
109
|
return false;
|
107
110
|
}
|
108
|
-
} while ((path = path.parentPath) && !path.isProgram());
|
111
|
+
} while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
|
109
112
|
|
110
113
|
return true;
|
111
114
|
}
|
@@ -164,8 +164,8 @@ const Generated = {
|
|
164
164
|
};
|
165
165
|
exports.Generated = Generated;
|
166
166
|
const Pure = {
|
167
|
-
checkPath(path,
|
168
|
-
return path.scope.isPure(path.node,
|
167
|
+
checkPath(path, constantsOnly) {
|
168
|
+
return path.scope.isPure(path.node, constantsOnly);
|
169
169
|
}
|
170
170
|
|
171
171
|
};
|
package/lib/scope/index.js
CHANGED
@@ -53,7 +53,13 @@ const {
|
|
53
53
|
toIdentifier,
|
54
54
|
unaryExpression,
|
55
55
|
variableDeclaration,
|
56
|
-
variableDeclarator
|
56
|
+
variableDeclarator,
|
57
|
+
isRecordExpression,
|
58
|
+
isTupleExpression,
|
59
|
+
isObjectProperty,
|
60
|
+
isTopicReference,
|
61
|
+
isMetaProperty,
|
62
|
+
isPrivateName
|
57
63
|
} = _t;
|
58
64
|
|
59
65
|
function gatherNodeParts(node, parts) {
|
@@ -430,7 +436,7 @@ class Scope {
|
|
430
436
|
}
|
431
437
|
|
432
438
|
isStatic(node) {
|
433
|
-
if (isThisExpression(node) || isSuper(node)) {
|
439
|
+
if (isThisExpression(node) || isSuper(node) || isTopicReference(node)) {
|
434
440
|
return true;
|
435
441
|
}
|
436
442
|
|
@@ -682,11 +688,19 @@ class Scope {
|
|
682
688
|
if (!binding) return false;
|
683
689
|
if (constantsOnly) return binding.constant;
|
684
690
|
return true;
|
691
|
+
} else if (isThisExpression(node) || isMetaProperty(node) || isTopicReference(node) || isPrivateName(node)) {
|
692
|
+
return true;
|
685
693
|
} else if (isClass(node)) {
|
694
|
+
var _node$decorators;
|
695
|
+
|
686
696
|
if (node.superClass && !this.isPure(node.superClass, constantsOnly)) {
|
687
697
|
return false;
|
688
698
|
}
|
689
699
|
|
700
|
+
if (((_node$decorators = node.decorators) == null ? void 0 : _node$decorators.length) > 0) {
|
701
|
+
return false;
|
702
|
+
}
|
703
|
+
|
690
704
|
return this.isPure(node.body, constantsOnly);
|
691
705
|
} else if (isClassBody(node)) {
|
692
706
|
for (const method of node.body) {
|
@@ -696,25 +710,44 @@ class Scope {
|
|
696
710
|
return true;
|
697
711
|
} else if (isBinary(node)) {
|
698
712
|
return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly);
|
699
|
-
} else if (isArrayExpression(node)) {
|
713
|
+
} else if (isArrayExpression(node) || isTupleExpression(node)) {
|
700
714
|
for (const elem of node.elements) {
|
701
|
-
if (!this.isPure(elem, constantsOnly)) return false;
|
715
|
+
if (elem !== null && !this.isPure(elem, constantsOnly)) return false;
|
702
716
|
}
|
703
717
|
|
704
718
|
return true;
|
705
|
-
} else if (isObjectExpression(node)) {
|
719
|
+
} else if (isObjectExpression(node) || isRecordExpression(node)) {
|
706
720
|
for (const prop of node.properties) {
|
707
721
|
if (!this.isPure(prop, constantsOnly)) return false;
|
708
722
|
}
|
709
723
|
|
710
724
|
return true;
|
711
725
|
} else if (isMethod(node)) {
|
726
|
+
var _node$decorators2;
|
727
|
+
|
712
728
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
713
|
-
|
729
|
+
|
730
|
+
if (((_node$decorators2 = node.decorators) == null ? void 0 : _node$decorators2.length) > 0) {
|
731
|
+
return false;
|
732
|
+
}
|
733
|
+
|
714
734
|
return true;
|
715
735
|
} else if (isProperty(node)) {
|
736
|
+
var _node$decorators3;
|
737
|
+
|
716
738
|
if (node.computed && !this.isPure(node.key, constantsOnly)) return false;
|
717
|
-
|
739
|
+
|
740
|
+
if (((_node$decorators3 = node.decorators) == null ? void 0 : _node$decorators3.length) > 0) {
|
741
|
+
return false;
|
742
|
+
}
|
743
|
+
|
744
|
+
if (isObjectProperty(node) || node.static) {
|
745
|
+
if (node.value !== null && !this.isPure(node.value, constantsOnly)) {
|
746
|
+
return false;
|
747
|
+
}
|
748
|
+
}
|
749
|
+
|
750
|
+
return true;
|
718
751
|
} else if (isUnaryExpression(node)) {
|
719
752
|
return this.isPure(node.argument, constantsOnly);
|
720
753
|
} else if (isTaggedTemplateExpression(node)) {
|
@@ -821,7 +854,9 @@ class Scope {
|
|
821
854
|
push(opts) {
|
822
855
|
let path = this.path;
|
823
856
|
|
824
|
-
if (
|
857
|
+
if (path.isPattern()) {
|
858
|
+
path = this.getPatternParent().path;
|
859
|
+
} else if (!path.isBlockStatement() && !path.isProgram()) {
|
825
860
|
path = this.getBlockParent().path;
|
826
861
|
}
|
827
862
|
|
@@ -888,6 +923,18 @@ class Scope {
|
|
888
923
|
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
|
889
924
|
}
|
890
925
|
|
926
|
+
getPatternParent() {
|
927
|
+
let scope = this;
|
928
|
+
|
929
|
+
do {
|
930
|
+
if (!scope.path.isPattern()) {
|
931
|
+
return scope.getBlockParent();
|
932
|
+
}
|
933
|
+
} while (scope = scope.parent.parent);
|
934
|
+
|
935
|
+
throw new Error("We couldn't find a BlockStatement, For, Switch, Function, Loop or Program...");
|
936
|
+
}
|
937
|
+
|
891
938
|
getAllBindings() {
|
892
939
|
const ids = Object.create(null);
|
893
940
|
let scope = this;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.18.0",
|
4
4
|
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
|
5
5
|
"author": "The Babel Team (https://babel.dev/team)",
|
6
6
|
"homepage": "https://babel.dev/docs/en/next/babel-traverse",
|
@@ -17,13 +17,13 @@
|
|
17
17
|
"main": "./lib/index.js",
|
18
18
|
"dependencies": {
|
19
19
|
"@babel/code-frame": "^7.16.7",
|
20
|
-
"@babel/generator": "^7.
|
20
|
+
"@babel/generator": "^7.18.0",
|
21
21
|
"@babel/helper-environment-visitor": "^7.16.7",
|
22
22
|
"@babel/helper-function-name": "^7.17.9",
|
23
23
|
"@babel/helper-hoist-variables": "^7.16.7",
|
24
24
|
"@babel/helper-split-export-declaration": "^7.16.7",
|
25
|
-
"@babel/parser": "^7.
|
26
|
-
"@babel/types": "^7.
|
25
|
+
"@babel/parser": "^7.18.0",
|
26
|
+
"@babel/types": "^7.18.0",
|
27
27
|
"debug": "^4.1.0",
|
28
28
|
"globals": "^11.1.0"
|
29
29
|
},
|
@@ -24,6 +24,8 @@ export interface NodePathValidators {
|
|
24
24
|
output += `is${type}(opts?: object): this is NodePath<t.${type}>;`;
|
25
25
|
} else if (types /* in VirtualTypeAliases */) {
|
26
26
|
output += `is${type}(opts?: object): this is NodePath<VirtualTypeAliases["${type}"]>;`;
|
27
|
+
} else if (type === "Pure") {
|
28
|
+
output += `isPure(constantsOnly?: boolean): boolean;`;
|
27
29
|
} else {
|
28
30
|
// if it don't have types, then VirtualTypeAliases[type] is t.Node
|
29
31
|
// which TS marked as always true
|