@babel/traverse 7.8.0 → 7.9.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.
- package/lib/path/comments.js +2 -2
- package/lib/path/removal.js +3 -1
- package/lib/scope/index.js +146 -50
- package/package.json +9 -10
package/lib/path/comments.js
CHANGED
@@ -25,9 +25,9 @@ function shareCommentsWithSiblings() {
|
|
25
25
|
const hasPrev = Boolean(prev.node);
|
26
26
|
const hasNext = Boolean(next.node);
|
27
27
|
|
28
|
-
if (hasPrev && hasNext) {
|
28
|
+
if (hasPrev && !hasNext) {
|
29
29
|
prev.addComments("trailing", trailing);
|
30
|
-
} else if (hasNext) {
|
30
|
+
} else if (hasNext && !hasPrev) {
|
31
31
|
next.addComments("leading", leading);
|
32
32
|
}
|
33
33
|
}
|
package/lib/path/removal.js
CHANGED
package/lib/scope/index.js
CHANGED
@@ -30,37 +30,143 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
30
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31
31
|
|
32
32
|
function gatherNodeParts(node, parts) {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
switch (node == null ? void 0 : node.type) {
|
34
|
+
default:
|
35
|
+
if (t.isModuleDeclaration(node)) {
|
36
|
+
if (node.source) {
|
37
|
+
gatherNodeParts(node.source, parts);
|
38
|
+
} else if (node.specifiers && node.specifiers.length) {
|
39
|
+
for (const e of node.specifiers) gatherNodeParts(e, parts);
|
40
|
+
} else if (node.declaration) {
|
41
|
+
gatherNodeParts(node.declaration, parts);
|
42
|
+
}
|
43
|
+
} else if (t.isModuleSpecifier(node)) {
|
44
|
+
gatherNodeParts(node.local, parts);
|
45
|
+
} else if (t.isLiteral(node)) {
|
46
|
+
parts.push(node.value);
|
47
|
+
}
|
48
|
+
|
49
|
+
break;
|
50
|
+
|
51
|
+
case "MemberExpression":
|
52
|
+
case "OptionalMemberExpression":
|
53
|
+
case "JSXMemberExpression":
|
54
|
+
gatherNodeParts(node.object, parts);
|
55
|
+
gatherNodeParts(node.property, parts);
|
56
|
+
break;
|
57
|
+
|
58
|
+
case "Identifier":
|
59
|
+
case "JSXIdentifier":
|
60
|
+
parts.push(node.name);
|
61
|
+
break;
|
62
|
+
|
63
|
+
case "CallExpression":
|
64
|
+
case "OptionalCallExpression":
|
65
|
+
case "NewExpression":
|
66
|
+
gatherNodeParts(node.callee, parts);
|
67
|
+
break;
|
68
|
+
|
69
|
+
case "ObjectExpression":
|
70
|
+
case "ObjectPattern":
|
71
|
+
for (const e of node.properties) {
|
72
|
+
gatherNodeParts(e, parts);
|
39
73
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
74
|
+
|
75
|
+
break;
|
76
|
+
|
77
|
+
case "SpreadElement":
|
78
|
+
case "RestElement":
|
79
|
+
gatherNodeParts(node.argument, parts);
|
80
|
+
break;
|
81
|
+
|
82
|
+
case "ObjectProperty":
|
83
|
+
case "ObjectMethod":
|
84
|
+
case "ClassProperty":
|
85
|
+
case "ClassMethod":
|
86
|
+
case "ClassPrivateProperty":
|
87
|
+
case "ClassPrivateMethod":
|
88
|
+
gatherNodeParts(node.key, parts);
|
89
|
+
break;
|
90
|
+
|
91
|
+
case "ThisExpression":
|
92
|
+
parts.push("this");
|
93
|
+
break;
|
94
|
+
|
95
|
+
case "Super":
|
96
|
+
parts.push("super");
|
97
|
+
break;
|
98
|
+
|
99
|
+
case "Import":
|
100
|
+
parts.push("import");
|
101
|
+
break;
|
102
|
+
|
103
|
+
case "DoExpression":
|
104
|
+
parts.push("do");
|
105
|
+
break;
|
106
|
+
|
107
|
+
case "YieldExpression":
|
108
|
+
parts.push("yield");
|
109
|
+
gatherNodeParts(node.argument, parts);
|
110
|
+
break;
|
111
|
+
|
112
|
+
case "AwaitExpression":
|
113
|
+
parts.push("await");
|
114
|
+
gatherNodeParts(node.argument, parts);
|
115
|
+
break;
|
116
|
+
|
117
|
+
case "AssignmentExpression":
|
118
|
+
gatherNodeParts(node.left, parts);
|
119
|
+
break;
|
120
|
+
|
121
|
+
case "VariableDeclarator":
|
122
|
+
gatherNodeParts(node.id, parts);
|
123
|
+
break;
|
124
|
+
|
125
|
+
case "FunctionExpression":
|
126
|
+
case "FunctionDeclaration":
|
127
|
+
case "ClassExpression":
|
128
|
+
case "ClassDeclaration":
|
129
|
+
gatherNodeParts(node.id, parts);
|
130
|
+
break;
|
131
|
+
|
132
|
+
case "PrivateName":
|
133
|
+
gatherNodeParts(node.id, parts);
|
134
|
+
break;
|
135
|
+
|
136
|
+
case "ParenthesizedExpression":
|
137
|
+
gatherNodeParts(node.expression, parts);
|
138
|
+
break;
|
139
|
+
|
140
|
+
case "UnaryExpression":
|
141
|
+
case "UpdateExpression":
|
142
|
+
gatherNodeParts(node.argument, parts);
|
143
|
+
break;
|
144
|
+
|
145
|
+
case "MetaProperty":
|
146
|
+
gatherNodeParts(node.meta, parts);
|
147
|
+
gatherNodeParts(node.property, parts);
|
148
|
+
break;
|
149
|
+
|
150
|
+
case "JSXElement":
|
151
|
+
gatherNodeParts(node.openingElement, parts);
|
152
|
+
break;
|
153
|
+
|
154
|
+
case "JSXOpeningElement":
|
155
|
+
parts.push(node.name);
|
156
|
+
break;
|
157
|
+
|
158
|
+
case "JSXFragment":
|
159
|
+
gatherNodeParts(node.openingFragment, parts);
|
160
|
+
break;
|
161
|
+
|
162
|
+
case "JSXOpeningFragment":
|
163
|
+
parts.push("Fragment");
|
164
|
+
break;
|
165
|
+
|
166
|
+
case "JSXNamespacedName":
|
167
|
+
gatherNodeParts(node.namespace, parts);
|
168
|
+
gatherNodeParts(node.name, parts);
|
169
|
+
break;
|
64
170
|
}
|
65
171
|
}
|
66
172
|
|
@@ -146,14 +252,14 @@ const collectorVisitor = {
|
|
146
252
|
BlockScoped(path) {
|
147
253
|
let scope = path.scope;
|
148
254
|
if (scope.path === path) scope = scope.parent;
|
149
|
-
scope.getBlockParent()
|
150
|
-
|
255
|
+
const parent = scope.getBlockParent();
|
256
|
+
parent.registerDeclaration(path);
|
151
257
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
258
|
+
if (path.isClassDeclaration() && path.node.id) {
|
259
|
+
const id = path.node.id;
|
260
|
+
const name = id.name;
|
261
|
+
path.scope.bindings[name] = path.scope.parent.getBinding(name);
|
262
|
+
}
|
157
263
|
},
|
158
264
|
|
159
265
|
Block(path) {
|
@@ -240,17 +346,7 @@ class Scope {
|
|
240
346
|
return `_${id}`;
|
241
347
|
}
|
242
348
|
|
243
|
-
generateUidBasedOnNode(
|
244
|
-
let node = parent;
|
245
|
-
|
246
|
-
if (t.isAssignmentExpression(parent)) {
|
247
|
-
node = parent.left;
|
248
|
-
} else if (t.isVariableDeclarator(parent)) {
|
249
|
-
node = parent.id;
|
250
|
-
} else if (t.isObjectProperty(node) || t.isObjectMethod(node)) {
|
251
|
-
node = node.key;
|
252
|
-
}
|
253
|
-
|
349
|
+
generateUidBasedOnNode(node, defaultName) {
|
254
350
|
const parts = [];
|
255
351
|
gatherNodeParts(node, parts);
|
256
352
|
let id = parts.join("$");
|
@@ -258,8 +354,8 @@ class Scope {
|
|
258
354
|
return this.generateUid(id.slice(0, 20));
|
259
355
|
}
|
260
356
|
|
261
|
-
generateUidIdentifierBasedOnNode(
|
262
|
-
return t.identifier(this.generateUidBasedOnNode(
|
357
|
+
generateUidIdentifierBasedOnNode(node, defaultName) {
|
358
|
+
return t.identifier(this.generateUidBasedOnNode(node, defaultName));
|
263
359
|
}
|
264
360
|
|
265
361
|
isStatic(node) {
|
package/package.json
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.9.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": "Sebastian McKenzie <sebmck@gmail.com>",
|
6
6
|
"homepage": "https://babeljs.io/",
|
7
7
|
"license": "MIT",
|
8
|
-
"type": "commonjs",
|
9
8
|
"publishConfig": {
|
10
9
|
"access": "public"
|
11
10
|
},
|
12
11
|
"repository": "https://github.com/babel/babel/tree/master/packages/babel-traverse",
|
13
12
|
"main": "lib/index.js",
|
14
13
|
"dependencies": {
|
15
|
-
"@babel/code-frame": "^7.8.
|
16
|
-
"@babel/generator": "^7.
|
17
|
-
"@babel/helper-function-name": "^7.8.
|
18
|
-
"@babel/helper-split-export-declaration": "^7.8.
|
19
|
-
"@babel/parser": "^7.
|
20
|
-
"@babel/types": "^7.
|
14
|
+
"@babel/code-frame": "^7.8.3",
|
15
|
+
"@babel/generator": "^7.9.0",
|
16
|
+
"@babel/helper-function-name": "^7.8.3",
|
17
|
+
"@babel/helper-split-export-declaration": "^7.8.3",
|
18
|
+
"@babel/parser": "^7.9.0",
|
19
|
+
"@babel/types": "^7.9.0",
|
21
20
|
"debug": "^4.1.0",
|
22
21
|
"globals": "^11.1.0",
|
23
22
|
"lodash": "^4.17.13"
|
24
23
|
},
|
25
24
|
"devDependencies": {
|
26
|
-
"@babel/helper-plugin-test-runner": "^7.8.
|
25
|
+
"@babel/helper-plugin-test-runner": "^7.8.3"
|
27
26
|
},
|
28
|
-
"gitHead": "
|
27
|
+
"gitHead": "8d5e422be27251cfaadf8dd2536b31b4a5024b02"
|
29
28
|
}
|