@babel/traverse 7.0.0-beta.5 → 7.0.0-beta.53
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/README.md +9 -23
- package/lib/cache.js +5 -3
- package/lib/context.js +55 -91
- package/lib/hub.js +9 -4
- package/lib/index.js +36 -33
- package/lib/path/ancestry.js +37 -41
- package/lib/path/comments.js +22 -12
- package/lib/path/context.js +24 -48
- package/lib/path/conversion.js +170 -150
- package/lib/path/evaluation.js +108 -150
- package/lib/path/family.js +40 -43
- package/lib/path/index.js +99 -80
- package/lib/path/inference/index.js +39 -33
- package/lib/path/inference/inferer-reference.js +55 -49
- package/lib/path/inference/inferers.js +61 -49
- package/lib/path/introspection.js +105 -96
- package/lib/path/lib/hoister.js +63 -61
- package/lib/path/lib/removal-hooks.js +5 -3
- package/lib/path/lib/virtual-types.js +106 -66
- package/lib/path/modification.js +70 -68
- package/lib/path/removal.js +12 -5
- package/lib/path/replacement.js +76 -69
- package/lib/scope/binding.js +23 -23
- package/lib/scope/index.js +389 -487
- package/lib/scope/lib/renamer.js +71 -61
- package/lib/visitors.js +84 -124
- package/package.json +11 -10
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
exports
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
4
6
|
exports.VariableDeclarator = VariableDeclarator;
|
5
7
|
exports.TypeCastExpression = TypeCastExpression;
|
6
8
|
exports.NewExpression = NewExpression;
|
@@ -25,24 +27,32 @@ exports.CallExpression = CallExpression;
|
|
25
27
|
exports.TaggedTemplateExpression = TaggedTemplateExpression;
|
26
28
|
Object.defineProperty(exports, "Identifier", {
|
27
29
|
enumerable: true,
|
28
|
-
get: function
|
30
|
+
get: function () {
|
29
31
|
return _infererReference.default;
|
30
32
|
}
|
31
33
|
});
|
32
34
|
|
33
|
-
|
35
|
+
function t() {
|
36
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
37
|
+
|
38
|
+
t = function () {
|
39
|
+
return data;
|
40
|
+
};
|
41
|
+
|
42
|
+
return data;
|
43
|
+
}
|
34
44
|
|
35
45
|
var _infererReference = _interopRequireDefault(require("./inferer-reference"));
|
36
46
|
|
37
47
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
38
48
|
|
39
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
49
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
40
50
|
|
41
51
|
function VariableDeclarator() {
|
42
|
-
|
52
|
+
const id = this.get("id");
|
43
53
|
if (!id.isIdentifier()) return;
|
44
|
-
|
45
|
-
|
54
|
+
const init = this.get("init");
|
55
|
+
let type = init.getTypeAnnotation();
|
46
56
|
|
47
57
|
if (type && type.type === "AnyTypeAnnotation") {
|
48
58
|
if (init.isCallExpression() && init.get("callee").isIdentifier({
|
@@ -63,55 +73,55 @@ TypeCastExpression.validParent = true;
|
|
63
73
|
|
64
74
|
function NewExpression(node) {
|
65
75
|
if (this.get("callee").isIdentifier()) {
|
66
|
-
return t.genericTypeAnnotation(node.callee);
|
76
|
+
return t().genericTypeAnnotation(node.callee);
|
67
77
|
}
|
68
78
|
}
|
69
79
|
|
70
80
|
function TemplateLiteral() {
|
71
|
-
return t.stringTypeAnnotation();
|
81
|
+
return t().stringTypeAnnotation();
|
72
82
|
}
|
73
83
|
|
74
84
|
function UnaryExpression(node) {
|
75
|
-
|
85
|
+
const operator = node.operator;
|
76
86
|
|
77
87
|
if (operator === "void") {
|
78
|
-
return t.voidTypeAnnotation();
|
79
|
-
} else if (t.NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
80
|
-
return t.numberTypeAnnotation();
|
81
|
-
} else if (t.STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
82
|
-
return t.stringTypeAnnotation();
|
83
|
-
} else if (t.BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
84
|
-
return t.booleanTypeAnnotation();
|
88
|
+
return t().voidTypeAnnotation();
|
89
|
+
} else if (t().NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
90
|
+
return t().numberTypeAnnotation();
|
91
|
+
} else if (t().STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
92
|
+
return t().stringTypeAnnotation();
|
93
|
+
} else if (t().BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
94
|
+
return t().booleanTypeAnnotation();
|
85
95
|
}
|
86
96
|
}
|
87
97
|
|
88
98
|
function BinaryExpression(node) {
|
89
|
-
|
99
|
+
const operator = node.operator;
|
90
100
|
|
91
|
-
if (t.NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
92
|
-
return t.numberTypeAnnotation();
|
93
|
-
} else if (t.BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
94
|
-
return t.booleanTypeAnnotation();
|
101
|
+
if (t().NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
102
|
+
return t().numberTypeAnnotation();
|
103
|
+
} else if (t().BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
104
|
+
return t().booleanTypeAnnotation();
|
95
105
|
} else if (operator === "+") {
|
96
|
-
|
97
|
-
|
106
|
+
const right = this.get("right");
|
107
|
+
const left = this.get("left");
|
98
108
|
|
99
109
|
if (left.isBaseType("number") && right.isBaseType("number")) {
|
100
|
-
return t.numberTypeAnnotation();
|
110
|
+
return t().numberTypeAnnotation();
|
101
111
|
} else if (left.isBaseType("string") || right.isBaseType("string")) {
|
102
|
-
return t.stringTypeAnnotation();
|
112
|
+
return t().stringTypeAnnotation();
|
103
113
|
}
|
104
114
|
|
105
|
-
return t.unionTypeAnnotation([t.stringTypeAnnotation(), t.numberTypeAnnotation()]);
|
115
|
+
return t().unionTypeAnnotation([t().stringTypeAnnotation(), t().numberTypeAnnotation()]);
|
106
116
|
}
|
107
117
|
}
|
108
118
|
|
109
119
|
function LogicalExpression() {
|
110
|
-
return t.createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]);
|
120
|
+
return t().createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]);
|
111
121
|
}
|
112
122
|
|
113
123
|
function ConditionalExpression() {
|
114
|
-
return t.createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]);
|
124
|
+
return t().createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]);
|
115
125
|
}
|
116
126
|
|
117
127
|
function SequenceExpression() {
|
@@ -123,39 +133,39 @@ function AssignmentExpression() {
|
|
123
133
|
}
|
124
134
|
|
125
135
|
function UpdateExpression(node) {
|
126
|
-
|
136
|
+
const operator = node.operator;
|
127
137
|
|
128
138
|
if (operator === "++" || operator === "--") {
|
129
|
-
return t.numberTypeAnnotation();
|
139
|
+
return t().numberTypeAnnotation();
|
130
140
|
}
|
131
141
|
}
|
132
142
|
|
133
143
|
function StringLiteral() {
|
134
|
-
return t.stringTypeAnnotation();
|
144
|
+
return t().stringTypeAnnotation();
|
135
145
|
}
|
136
146
|
|
137
147
|
function NumericLiteral() {
|
138
|
-
return t.numberTypeAnnotation();
|
148
|
+
return t().numberTypeAnnotation();
|
139
149
|
}
|
140
150
|
|
141
151
|
function BooleanLiteral() {
|
142
|
-
return t.booleanTypeAnnotation();
|
152
|
+
return t().booleanTypeAnnotation();
|
143
153
|
}
|
144
154
|
|
145
155
|
function NullLiteral() {
|
146
|
-
return t.nullLiteralTypeAnnotation();
|
156
|
+
return t().nullLiteralTypeAnnotation();
|
147
157
|
}
|
148
158
|
|
149
159
|
function RegExpLiteral() {
|
150
|
-
return t.genericTypeAnnotation(t.identifier("RegExp"));
|
160
|
+
return t().genericTypeAnnotation(t().identifier("RegExp"));
|
151
161
|
}
|
152
162
|
|
153
163
|
function ObjectExpression() {
|
154
|
-
return t.genericTypeAnnotation(t.identifier("Object"));
|
164
|
+
return t().genericTypeAnnotation(t().identifier("Object"));
|
155
165
|
}
|
156
166
|
|
157
167
|
function ArrayExpression() {
|
158
|
-
return t.genericTypeAnnotation(t.identifier("Array"));
|
168
|
+
return t().genericTypeAnnotation(t().identifier("Array"));
|
159
169
|
}
|
160
170
|
|
161
171
|
function RestElement() {
|
@@ -165,23 +175,25 @@ function RestElement() {
|
|
165
175
|
RestElement.validParent = true;
|
166
176
|
|
167
177
|
function Func() {
|
168
|
-
return t.genericTypeAnnotation(t.identifier("Function"));
|
178
|
+
return t().genericTypeAnnotation(t().identifier("Function"));
|
169
179
|
}
|
170
180
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
181
|
+
const isArrayFrom = t().buildMatchMemberExpression("Array.from");
|
182
|
+
const isObjectKeys = t().buildMatchMemberExpression("Object.keys");
|
183
|
+
const isObjectValues = t().buildMatchMemberExpression("Object.values");
|
184
|
+
const isObjectEntries = t().buildMatchMemberExpression("Object.entries");
|
175
185
|
|
176
186
|
function CallExpression() {
|
177
|
-
|
187
|
+
const {
|
188
|
+
callee
|
189
|
+
} = this.node;
|
178
190
|
|
179
191
|
if (isObjectKeys(callee)) {
|
180
|
-
return t.arrayTypeAnnotation(t.stringTypeAnnotation());
|
192
|
+
return t().arrayTypeAnnotation(t().stringTypeAnnotation());
|
181
193
|
} else if (isArrayFrom(callee) || isObjectValues(callee)) {
|
182
|
-
return t.arrayTypeAnnotation(t.anyTypeAnnotation());
|
194
|
+
return t().arrayTypeAnnotation(t().anyTypeAnnotation());
|
183
195
|
} else if (isObjectEntries(callee)) {
|
184
|
-
return t.arrayTypeAnnotation(t.tupleTypeAnnotation([t.stringTypeAnnotation(), t.anyTypeAnnotation()]));
|
196
|
+
return t().arrayTypeAnnotation(t().tupleTypeAnnotation([t().stringTypeAnnotation(), t().anyTypeAnnotation()]));
|
185
197
|
}
|
186
198
|
|
187
199
|
return resolveCall(this.get("callee"));
|
@@ -197,9 +209,9 @@ function resolveCall(callee) {
|
|
197
209
|
if (callee.isFunction()) {
|
198
210
|
if (callee.is("async")) {
|
199
211
|
if (callee.is("generator")) {
|
200
|
-
return t.genericTypeAnnotation(t.identifier("AsyncIterator"));
|
212
|
+
return t().genericTypeAnnotation(t().identifier("AsyncIterator"));
|
201
213
|
} else {
|
202
|
-
return t.genericTypeAnnotation(t.identifier("Promise"));
|
214
|
+
return t().genericTypeAnnotation(t().identifier("Promise"));
|
203
215
|
}
|
204
216
|
} else {
|
205
217
|
if (callee.node.returnType) {
|
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
exports
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
4
6
|
exports.matchesPattern = matchesPattern;
|
5
7
|
exports.has = has;
|
6
8
|
exports.isStatic = isStatic;
|
@@ -19,22 +21,39 @@ exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatu
|
|
19
21
|
exports.resolve = resolve;
|
20
22
|
exports._resolve = _resolve;
|
21
23
|
exports.isConstantExpression = isConstantExpression;
|
24
|
+
exports.isInStrictMode = isInStrictMode;
|
22
25
|
exports.is = void 0;
|
23
26
|
|
24
|
-
|
27
|
+
function _includes() {
|
28
|
+
const data = _interopRequireDefault(require("lodash/includes"));
|
25
29
|
|
26
|
-
|
30
|
+
_includes = function () {
|
31
|
+
return data;
|
32
|
+
};
|
27
33
|
|
28
|
-
|
34
|
+
return data;
|
35
|
+
}
|
36
|
+
|
37
|
+
function t() {
|
38
|
+
const data = _interopRequireWildcard(require("@babel/types"));
|
39
|
+
|
40
|
+
t = function () {
|
41
|
+
return data;
|
42
|
+
};
|
43
|
+
|
44
|
+
return data;
|
45
|
+
}
|
46
|
+
|
47
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
29
48
|
|
30
49
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31
50
|
|
32
51
|
function matchesPattern(pattern, allowPartial) {
|
33
|
-
return t.matchesPattern(this.node, pattern, allowPartial);
|
52
|
+
return t().matchesPattern(this.node, pattern, allowPartial);
|
34
53
|
}
|
35
54
|
|
36
55
|
function has(key) {
|
37
|
-
|
56
|
+
const val = this.node && this.node[key];
|
38
57
|
|
39
58
|
if (val && Array.isArray(val)) {
|
40
59
|
return !!val.length;
|
@@ -47,7 +66,7 @@ function isStatic() {
|
|
47
66
|
return this.scope.isStatic(this.node);
|
48
67
|
}
|
49
68
|
|
50
|
-
|
69
|
+
const is = has;
|
51
70
|
exports.is = is;
|
52
71
|
|
53
72
|
function isnt(key) {
|
@@ -59,7 +78,7 @@ function equals(key, value) {
|
|
59
78
|
}
|
60
79
|
|
61
80
|
function isNodeType(type) {
|
62
|
-
return t.isType(this.type, type);
|
81
|
+
return t().isType(this.type, type);
|
63
82
|
}
|
64
83
|
|
65
84
|
function canHaveVariableDeclarationOrExpression() {
|
@@ -72,20 +91,20 @@ function canSwapBetweenExpressionAndStatement(replacement) {
|
|
72
91
|
}
|
73
92
|
|
74
93
|
if (this.isExpression()) {
|
75
|
-
return t.isBlockStatement(replacement);
|
94
|
+
return t().isBlockStatement(replacement);
|
76
95
|
} else if (this.isBlockStatement()) {
|
77
|
-
return t.isExpression(replacement);
|
96
|
+
return t().isExpression(replacement);
|
78
97
|
}
|
79
98
|
|
80
99
|
return false;
|
81
100
|
}
|
82
101
|
|
83
102
|
function isCompletionRecord(allowInsideFunction) {
|
84
|
-
|
85
|
-
|
103
|
+
let path = this;
|
104
|
+
let first = true;
|
86
105
|
|
87
106
|
do {
|
88
|
-
|
107
|
+
const container = path.container;
|
89
108
|
|
90
109
|
if (path.isFunction() && !first) {
|
91
110
|
return !!allowInsideFunction;
|
@@ -102,19 +121,19 @@ function isCompletionRecord(allowInsideFunction) {
|
|
102
121
|
}
|
103
122
|
|
104
123
|
function isStatementOrBlock() {
|
105
|
-
if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) {
|
124
|
+
if (this.parentPath.isLabeledStatement() || t().isBlockStatement(this.container)) {
|
106
125
|
return false;
|
107
126
|
} else {
|
108
|
-
return (0, _includes.default)(t.STATEMENT_OR_BLOCK_KEYS, this.key);
|
127
|
+
return (0, _includes().default)(t().STATEMENT_OR_BLOCK_KEYS, this.key);
|
109
128
|
}
|
110
129
|
}
|
111
130
|
|
112
131
|
function referencesImport(moduleSource, importName) {
|
113
132
|
if (!this.isReferencedIdentifier()) return false;
|
114
|
-
|
133
|
+
const binding = this.scope.getBinding(this.node.name);
|
115
134
|
if (!binding || binding.kind !== "module") return false;
|
116
|
-
|
117
|
-
|
135
|
+
const path = binding.path;
|
136
|
+
const parent = path.parentPath;
|
118
137
|
if (!parent.isImportDeclaration()) return false;
|
119
138
|
|
120
139
|
if (parent.node.source.value === moduleSource) {
|
@@ -139,7 +158,7 @@ function referencesImport(moduleSource, importName) {
|
|
139
158
|
}
|
140
159
|
|
141
160
|
function getSource() {
|
142
|
-
|
161
|
+
const node = this.node;
|
143
162
|
|
144
163
|
if (node.end) {
|
145
164
|
return this.hub.file.code.slice(node.start, node.end);
|
@@ -153,11 +172,11 @@ function willIMaybeExecuteBefore(target) {
|
|
153
172
|
}
|
154
173
|
|
155
174
|
function _guessExecutionStatusRelativeTo(target) {
|
156
|
-
|
157
|
-
|
175
|
+
const targetFuncParent = target.scope.getFunctionParent() || target.scope.getProgramParent();
|
176
|
+
const selfFuncParent = this.scope.getFunctionParent() || target.scope.getProgramParent();
|
158
177
|
|
159
178
|
if (targetFuncParent.node !== selfFuncParent.node) {
|
160
|
-
|
179
|
+
const status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent);
|
161
180
|
|
162
181
|
if (status) {
|
163
182
|
return status;
|
@@ -166,15 +185,15 @@ function _guessExecutionStatusRelativeTo(target) {
|
|
166
185
|
}
|
167
186
|
}
|
168
187
|
|
169
|
-
|
188
|
+
const targetPaths = target.getAncestry();
|
170
189
|
if (targetPaths.indexOf(this) >= 0) return "after";
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
190
|
+
const selfPaths = this.getAncestry();
|
191
|
+
let commonPath;
|
192
|
+
let targetIndex;
|
193
|
+
let selfIndex;
|
175
194
|
|
176
195
|
for (selfIndex = 0; selfIndex < selfPaths.length; selfIndex++) {
|
177
|
-
|
196
|
+
const selfPath = selfPaths[selfIndex];
|
178
197
|
targetIndex = targetPaths.indexOf(selfPath);
|
179
198
|
|
180
199
|
if (targetIndex >= 0) {
|
@@ -187,8 +206,8 @@ function _guessExecutionStatusRelativeTo(target) {
|
|
187
206
|
return "before";
|
188
207
|
}
|
189
208
|
|
190
|
-
|
191
|
-
|
209
|
+
const targetRelationship = targetPaths[targetIndex - 1];
|
210
|
+
const selfRelationship = selfPaths[selfIndex - 1];
|
192
211
|
|
193
212
|
if (!targetRelationship || !selfRelationship) {
|
194
213
|
return "before";
|
@@ -198,59 +217,32 @@ function _guessExecutionStatusRelativeTo(target) {
|
|
198
217
|
return targetRelationship.key > selfRelationship.key ? "before" : "after";
|
199
218
|
}
|
200
219
|
|
201
|
-
|
202
|
-
|
203
|
-
|
220
|
+
const keys = t().VISITOR_KEYS[commonPath.type];
|
221
|
+
const targetKeyPosition = keys.indexOf(targetRelationship.key);
|
222
|
+
const selfKeyPosition = keys.indexOf(selfRelationship.key);
|
204
223
|
return targetKeyPosition > selfKeyPosition ? "before" : "after";
|
205
224
|
}
|
206
225
|
|
207
226
|
function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent) {
|
208
|
-
|
227
|
+
const targetFuncPath = targetFuncParent.path;
|
209
228
|
if (!targetFuncPath.isFunctionDeclaration()) return;
|
210
|
-
|
229
|
+
const binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name);
|
211
230
|
if (!binding.references) return "before";
|
212
|
-
|
213
|
-
|
214
|
-
for (var _iterator = referencePaths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
215
|
-
var _ref;
|
231
|
+
const referencePaths = binding.referencePaths;
|
216
232
|
|
217
|
-
|
218
|
-
|
219
|
-
_ref = _iterator[_i++];
|
220
|
-
} else {
|
221
|
-
_i = _iterator.next();
|
222
|
-
if (_i.done) break;
|
223
|
-
_ref = _i.value;
|
224
|
-
}
|
225
|
-
|
226
|
-
var _path2 = _ref;
|
227
|
-
|
228
|
-
if (_path2.key !== "callee" || !_path2.parentPath.isCallExpression()) {
|
233
|
+
for (const path of referencePaths) {
|
234
|
+
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
|
229
235
|
return;
|
230
236
|
}
|
231
237
|
}
|
232
238
|
|
233
|
-
|
234
|
-
|
235
|
-
for (var _iterator2 = referencePaths, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
236
|
-
var _ref2;
|
237
|
-
|
238
|
-
if (_isArray2) {
|
239
|
-
if (_i2 >= _iterator2.length) break;
|
240
|
-
_ref2 = _iterator2[_i2++];
|
241
|
-
} else {
|
242
|
-
_i2 = _iterator2.next();
|
243
|
-
if (_i2.done) break;
|
244
|
-
_ref2 = _i2.value;
|
245
|
-
}
|
239
|
+
let allStatus;
|
246
240
|
|
247
|
-
|
248
|
-
|
249
|
-
return path.node === targetFuncPath.node;
|
250
|
-
});
|
241
|
+
for (const path of referencePaths) {
|
242
|
+
const childOfFunction = !!path.find(path => path.node === targetFuncPath.node);
|
251
243
|
if (childOfFunction) continue;
|
252
244
|
|
253
|
-
|
245
|
+
const status = this._guessExecutionStatusRelativeTo(path);
|
254
246
|
|
255
247
|
if (allStatus) {
|
256
248
|
if (allStatus !== status) return;
|
@@ -276,35 +268,31 @@ function _resolve(dangerous, resolved) {
|
|
276
268
|
return this.get("init").resolve(dangerous, resolved);
|
277
269
|
} else {}
|
278
270
|
} else if (this.isReferencedIdentifier()) {
|
279
|
-
|
271
|
+
const binding = this.scope.getBinding(this.node.name);
|
280
272
|
if (!binding) return;
|
281
273
|
if (!binding.constant) return;
|
282
274
|
if (binding.kind === "module") return;
|
283
275
|
|
284
276
|
if (binding.path !== this) {
|
285
|
-
|
286
|
-
if (this.find(
|
287
|
-
return parent.node === ret.node;
|
288
|
-
})) return;
|
277
|
+
const ret = binding.path.resolve(dangerous, resolved);
|
278
|
+
if (this.find(parent => parent.node === ret.node)) return;
|
289
279
|
return ret;
|
290
280
|
}
|
291
281
|
} else if (this.isTypeCastExpression()) {
|
292
282
|
return this.get("expression").resolve(dangerous, resolved);
|
293
283
|
} else if (dangerous && this.isMemberExpression()) {
|
294
|
-
|
295
|
-
if (!t.isLiteral(targetKey)) return;
|
296
|
-
|
297
|
-
|
284
|
+
const targetKey = this.toComputedKey();
|
285
|
+
if (!t().isLiteral(targetKey)) return;
|
286
|
+
const targetName = targetKey.value;
|
287
|
+
const target = this.get("object").resolve(dangerous, resolved);
|
298
288
|
|
299
289
|
if (target.isObjectExpression()) {
|
300
|
-
|
301
|
-
var _arr = props;
|
290
|
+
const props = target.get("properties");
|
302
291
|
|
303
|
-
for (
|
304
|
-
var prop = _arr[_i3];
|
292
|
+
for (const prop of props) {
|
305
293
|
if (!prop.isProperty()) continue;
|
306
|
-
|
307
|
-
|
294
|
+
const key = prop.get("key");
|
295
|
+
let match = prop.isnt("computed") && key.isIdentifier({
|
308
296
|
name: targetName
|
309
297
|
});
|
310
298
|
match = match || key.isLiteral({
|
@@ -313,8 +301,8 @@ function _resolve(dangerous, resolved) {
|
|
313
301
|
if (match) return prop.get("value").resolve(dangerous, resolved);
|
314
302
|
}
|
315
303
|
} else if (target.isArrayExpression() && !isNaN(+targetName)) {
|
316
|
-
|
317
|
-
|
304
|
+
const elems = target.get("elements");
|
305
|
+
const elem = elems[targetName];
|
318
306
|
if (elem) return elem.resolve(dangerous, resolved);
|
319
307
|
}
|
320
308
|
}
|
@@ -322,13 +310,9 @@ function _resolve(dangerous, resolved) {
|
|
322
310
|
|
323
311
|
function isConstantExpression() {
|
324
312
|
if (this.isIdentifier()) {
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
return false;
|
329
|
-
}
|
330
|
-
|
331
|
-
return binding.constant && binding.path.get("init").isConstantExpression();
|
313
|
+
const binding = this.scope.getBinding(this.node.name);
|
314
|
+
if (!binding) return false;
|
315
|
+
return binding.constant;
|
332
316
|
}
|
333
317
|
|
334
318
|
if (this.isLiteral()) {
|
@@ -337,9 +321,7 @@ function isConstantExpression() {
|
|
337
321
|
}
|
338
322
|
|
339
323
|
if (this.isTemplateLiteral()) {
|
340
|
-
return this.get("expressions").every(
|
341
|
-
return expression.isConstantExpression();
|
342
|
-
});
|
324
|
+
return this.get("expressions").every(expression => expression.isConstantExpression());
|
343
325
|
}
|
344
326
|
|
345
327
|
return true;
|
@@ -358,4 +340,31 @@ function isConstantExpression() {
|
|
358
340
|
}
|
359
341
|
|
360
342
|
return false;
|
343
|
+
}
|
344
|
+
|
345
|
+
function isInStrictMode() {
|
346
|
+
const start = this.isProgram() ? this : this.parentPath;
|
347
|
+
const strictParent = start.find(path => {
|
348
|
+
if (path.isProgram({
|
349
|
+
sourceType: "module"
|
350
|
+
})) return true;
|
351
|
+
if (path.isClass()) return true;
|
352
|
+
if (!path.isProgram() && !path.isFunction()) return false;
|
353
|
+
|
354
|
+
if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
|
355
|
+
return false;
|
356
|
+
}
|
357
|
+
|
358
|
+
let {
|
359
|
+
node
|
360
|
+
} = path;
|
361
|
+
if (path.isFunction()) node = node.body;
|
362
|
+
|
363
|
+
for (const directive of node.directives) {
|
364
|
+
if (directive.value.value === "use strict") {
|
365
|
+
return true;
|
366
|
+
}
|
367
|
+
}
|
368
|
+
});
|
369
|
+
return !!strictParent;
|
361
370
|
}
|