@tachybase/module-cloud-component 0.23.22 → 0.23.40
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/dist/client/index.js +1 -1
- package/dist/externalVersion.js +7 -7
- package/dist/node_modules/@babel/core/lib/index.js +76 -76
- package/dist/node_modules/@babel/core/node_modules/.bin/parser +4 -4
- package/dist/node_modules/@babel/core/package.json +1 -1
- package/dist/node_modules/@babel/parser/LICENSE +19 -0
- package/dist/node_modules/@babel/parser/bin/babel-parser.js +15 -0
- package/dist/node_modules/@babel/parser/index.cjs +5 -0
- package/dist/node_modules/@babel/parser/lib/index.js +1 -0
- package/dist/node_modules/@babel/parser/package.json +1 -0
- package/dist/node_modules/@babel/parser/typings/babel-parser.d.ts +267 -0
- package/dist/node_modules/@babel/traverse/LICENSE +22 -0
- package/dist/node_modules/@babel/traverse/lib/cache.js +44 -0
- package/dist/node_modules/@babel/traverse/lib/context.js +119 -0
- package/dist/node_modules/@babel/traverse/lib/hub.js +19 -0
- package/dist/node_modules/@babel/traverse/lib/index.js +13 -0
- package/dist/node_modules/@babel/traverse/lib/path/ancestry.js +141 -0
- package/dist/node_modules/@babel/traverse/lib/path/comments.js +52 -0
- package/dist/node_modules/@babel/traverse/lib/path/context.js +242 -0
- package/dist/node_modules/@babel/traverse/lib/path/conversion.js +609 -0
- package/dist/node_modules/@babel/traverse/lib/path/evaluation.js +347 -0
- package/dist/node_modules/@babel/traverse/lib/path/family.js +340 -0
- package/dist/node_modules/@babel/traverse/lib/path/index.js +292 -0
- package/dist/node_modules/@babel/traverse/lib/path/inference/index.js +149 -0
- package/dist/node_modules/@babel/traverse/lib/path/inference/inferer-reference.js +151 -0
- package/dist/node_modules/@babel/traverse/lib/path/inference/inferers.js +207 -0
- package/dist/node_modules/@babel/traverse/lib/path/inference/util.js +30 -0
- package/dist/node_modules/@babel/traverse/lib/path/introspection.js +398 -0
- package/dist/node_modules/@babel/traverse/lib/path/lib/hoister.js +171 -0
- package/dist/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js +37 -0
- package/dist/node_modules/@babel/traverse/lib/path/lib/virtual-types-validator.js +163 -0
- package/dist/node_modules/@babel/traverse/lib/path/lib/virtual-types.js +26 -0
- package/dist/node_modules/@babel/traverse/lib/path/modification.js +229 -0
- package/dist/node_modules/@babel/traverse/lib/path/removal.js +69 -0
- package/dist/node_modules/@babel/traverse/lib/path/replacement.js +263 -0
- package/dist/node_modules/@babel/traverse/lib/scope/binding.js +83 -0
- package/dist/node_modules/@babel/traverse/lib/scope/index.js +981 -0
- package/dist/node_modules/@babel/traverse/lib/scope/lib/renamer.js +131 -0
- package/dist/node_modules/@babel/traverse/lib/traverse-node.js +29 -0
- package/dist/node_modules/@babel/traverse/lib/types.js +3 -0
- package/dist/node_modules/@babel/traverse/lib/visitors.js +258 -0
- package/dist/node_modules/@babel/traverse/node_modules/.bin/parser +17 -0
- package/dist/node_modules/@babel/traverse/package.json +1 -0
- package/dist/node_modules/@hapi/topo/lib/index.d.ts +60 -0
- package/dist/node_modules/@hapi/topo/lib/index.js +1 -0
- package/dist/node_modules/@hapi/topo/package.json +1 -0
- package/dist/server/services/cloud-libraries-service.js +36 -1
- package/package.json +13 -9
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ArrayExpression = ArrayExpression;
|
|
7
|
+
exports.AssignmentExpression = AssignmentExpression;
|
|
8
|
+
exports.BinaryExpression = BinaryExpression;
|
|
9
|
+
exports.BooleanLiteral = BooleanLiteral;
|
|
10
|
+
exports.CallExpression = CallExpression;
|
|
11
|
+
exports.ConditionalExpression = ConditionalExpression;
|
|
12
|
+
exports.ClassDeclaration = exports.ClassExpression = exports.FunctionDeclaration = exports.ArrowFunctionExpression = exports.FunctionExpression = Func;
|
|
13
|
+
Object.defineProperty(exports, "Identifier", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _infererReference.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
exports.LogicalExpression = LogicalExpression;
|
|
20
|
+
exports.NewExpression = NewExpression;
|
|
21
|
+
exports.NullLiteral = NullLiteral;
|
|
22
|
+
exports.NumericLiteral = NumericLiteral;
|
|
23
|
+
exports.ObjectExpression = ObjectExpression;
|
|
24
|
+
exports.ParenthesizedExpression = ParenthesizedExpression;
|
|
25
|
+
exports.RegExpLiteral = RegExpLiteral;
|
|
26
|
+
exports.RestElement = RestElement;
|
|
27
|
+
exports.SequenceExpression = SequenceExpression;
|
|
28
|
+
exports.StringLiteral = StringLiteral;
|
|
29
|
+
exports.TSAsExpression = TSAsExpression;
|
|
30
|
+
exports.TSNonNullExpression = TSNonNullExpression;
|
|
31
|
+
exports.TaggedTemplateExpression = TaggedTemplateExpression;
|
|
32
|
+
exports.TemplateLiteral = TemplateLiteral;
|
|
33
|
+
exports.TypeCastExpression = TypeCastExpression;
|
|
34
|
+
exports.UnaryExpression = UnaryExpression;
|
|
35
|
+
exports.UpdateExpression = UpdateExpression;
|
|
36
|
+
exports.VariableDeclarator = VariableDeclarator;
|
|
37
|
+
var _t = require("@babel/types");
|
|
38
|
+
var _infererReference = require("./inferer-reference.js");
|
|
39
|
+
var _util = require("./util.js");
|
|
40
|
+
const {
|
|
41
|
+
BOOLEAN_BINARY_OPERATORS,
|
|
42
|
+
BOOLEAN_UNARY_OPERATORS,
|
|
43
|
+
NUMBER_BINARY_OPERATORS,
|
|
44
|
+
NUMBER_UNARY_OPERATORS,
|
|
45
|
+
STRING_UNARY_OPERATORS,
|
|
46
|
+
anyTypeAnnotation,
|
|
47
|
+
arrayTypeAnnotation,
|
|
48
|
+
booleanTypeAnnotation,
|
|
49
|
+
buildMatchMemberExpression,
|
|
50
|
+
genericTypeAnnotation,
|
|
51
|
+
identifier,
|
|
52
|
+
nullLiteralTypeAnnotation,
|
|
53
|
+
numberTypeAnnotation,
|
|
54
|
+
stringTypeAnnotation,
|
|
55
|
+
tupleTypeAnnotation,
|
|
56
|
+
unionTypeAnnotation,
|
|
57
|
+
voidTypeAnnotation,
|
|
58
|
+
isIdentifier
|
|
59
|
+
} = _t;
|
|
60
|
+
function VariableDeclarator() {
|
|
61
|
+
if (!this.get("id").isIdentifier()) return;
|
|
62
|
+
return this.get("init").getTypeAnnotation();
|
|
63
|
+
}
|
|
64
|
+
function TypeCastExpression(node) {
|
|
65
|
+
return node.typeAnnotation;
|
|
66
|
+
}
|
|
67
|
+
TypeCastExpression.validParent = true;
|
|
68
|
+
function TSAsExpression(node) {
|
|
69
|
+
return node.typeAnnotation;
|
|
70
|
+
}
|
|
71
|
+
TSAsExpression.validParent = true;
|
|
72
|
+
function TSNonNullExpression() {
|
|
73
|
+
return this.get("expression").getTypeAnnotation();
|
|
74
|
+
}
|
|
75
|
+
function NewExpression(node) {
|
|
76
|
+
if (node.callee.type === "Identifier") {
|
|
77
|
+
return genericTypeAnnotation(node.callee);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function TemplateLiteral() {
|
|
81
|
+
return stringTypeAnnotation();
|
|
82
|
+
}
|
|
83
|
+
function UnaryExpression(node) {
|
|
84
|
+
const operator = node.operator;
|
|
85
|
+
if (operator === "void") {
|
|
86
|
+
return voidTypeAnnotation();
|
|
87
|
+
} else if (NUMBER_UNARY_OPERATORS.includes(operator)) {
|
|
88
|
+
return numberTypeAnnotation();
|
|
89
|
+
} else if (STRING_UNARY_OPERATORS.includes(operator)) {
|
|
90
|
+
return stringTypeAnnotation();
|
|
91
|
+
} else if (BOOLEAN_UNARY_OPERATORS.includes(operator)) {
|
|
92
|
+
return booleanTypeAnnotation();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function BinaryExpression(node) {
|
|
96
|
+
const operator = node.operator;
|
|
97
|
+
if (NUMBER_BINARY_OPERATORS.includes(operator)) {
|
|
98
|
+
return numberTypeAnnotation();
|
|
99
|
+
} else if (BOOLEAN_BINARY_OPERATORS.includes(operator)) {
|
|
100
|
+
return booleanTypeAnnotation();
|
|
101
|
+
} else if (operator === "+") {
|
|
102
|
+
const right = this.get("right");
|
|
103
|
+
const left = this.get("left");
|
|
104
|
+
if (left.isBaseType("number") && right.isBaseType("number")) {
|
|
105
|
+
return numberTypeAnnotation();
|
|
106
|
+
} else if (left.isBaseType("string") || right.isBaseType("string")) {
|
|
107
|
+
return stringTypeAnnotation();
|
|
108
|
+
}
|
|
109
|
+
return unionTypeAnnotation([stringTypeAnnotation(), numberTypeAnnotation()]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function LogicalExpression() {
|
|
113
|
+
const argumentTypes = [this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()];
|
|
114
|
+
return (0, _util.createUnionType)(argumentTypes);
|
|
115
|
+
}
|
|
116
|
+
function ConditionalExpression() {
|
|
117
|
+
const argumentTypes = [this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()];
|
|
118
|
+
return (0, _util.createUnionType)(argumentTypes);
|
|
119
|
+
}
|
|
120
|
+
function SequenceExpression() {
|
|
121
|
+
return this.get("expressions").pop().getTypeAnnotation();
|
|
122
|
+
}
|
|
123
|
+
function ParenthesizedExpression() {
|
|
124
|
+
return this.get("expression").getTypeAnnotation();
|
|
125
|
+
}
|
|
126
|
+
function AssignmentExpression() {
|
|
127
|
+
return this.get("right").getTypeAnnotation();
|
|
128
|
+
}
|
|
129
|
+
function UpdateExpression(node) {
|
|
130
|
+
const operator = node.operator;
|
|
131
|
+
if (operator === "++" || operator === "--") {
|
|
132
|
+
return numberTypeAnnotation();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function StringLiteral() {
|
|
136
|
+
return stringTypeAnnotation();
|
|
137
|
+
}
|
|
138
|
+
function NumericLiteral() {
|
|
139
|
+
return numberTypeAnnotation();
|
|
140
|
+
}
|
|
141
|
+
function BooleanLiteral() {
|
|
142
|
+
return booleanTypeAnnotation();
|
|
143
|
+
}
|
|
144
|
+
function NullLiteral() {
|
|
145
|
+
return nullLiteralTypeAnnotation();
|
|
146
|
+
}
|
|
147
|
+
function RegExpLiteral() {
|
|
148
|
+
return genericTypeAnnotation(identifier("RegExp"));
|
|
149
|
+
}
|
|
150
|
+
function ObjectExpression() {
|
|
151
|
+
return genericTypeAnnotation(identifier("Object"));
|
|
152
|
+
}
|
|
153
|
+
function ArrayExpression() {
|
|
154
|
+
return genericTypeAnnotation(identifier("Array"));
|
|
155
|
+
}
|
|
156
|
+
function RestElement() {
|
|
157
|
+
return ArrayExpression();
|
|
158
|
+
}
|
|
159
|
+
RestElement.validParent = true;
|
|
160
|
+
function Func() {
|
|
161
|
+
return genericTypeAnnotation(identifier("Function"));
|
|
162
|
+
}
|
|
163
|
+
const isArrayFrom = buildMatchMemberExpression("Array.from");
|
|
164
|
+
const isObjectKeys = buildMatchMemberExpression("Object.keys");
|
|
165
|
+
const isObjectValues = buildMatchMemberExpression("Object.values");
|
|
166
|
+
const isObjectEntries = buildMatchMemberExpression("Object.entries");
|
|
167
|
+
function CallExpression() {
|
|
168
|
+
const {
|
|
169
|
+
callee
|
|
170
|
+
} = this.node;
|
|
171
|
+
if (isObjectKeys(callee)) {
|
|
172
|
+
return arrayTypeAnnotation(stringTypeAnnotation());
|
|
173
|
+
} else if (isArrayFrom(callee) || isObjectValues(callee) || isIdentifier(callee, {
|
|
174
|
+
name: "Array"
|
|
175
|
+
})) {
|
|
176
|
+
return arrayTypeAnnotation(anyTypeAnnotation());
|
|
177
|
+
} else if (isObjectEntries(callee)) {
|
|
178
|
+
return arrayTypeAnnotation(tupleTypeAnnotation([stringTypeAnnotation(), anyTypeAnnotation()]));
|
|
179
|
+
}
|
|
180
|
+
return resolveCall(this.get("callee"));
|
|
181
|
+
}
|
|
182
|
+
function TaggedTemplateExpression() {
|
|
183
|
+
return resolveCall(this.get("tag"));
|
|
184
|
+
}
|
|
185
|
+
function resolveCall(callee) {
|
|
186
|
+
callee = callee.resolve();
|
|
187
|
+
if (callee.isFunction()) {
|
|
188
|
+
const {
|
|
189
|
+
node
|
|
190
|
+
} = callee;
|
|
191
|
+
if (node.async) {
|
|
192
|
+
if (node.generator) {
|
|
193
|
+
return genericTypeAnnotation(identifier("AsyncIterator"));
|
|
194
|
+
} else {
|
|
195
|
+
return genericTypeAnnotation(identifier("Promise"));
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
if (node.generator) {
|
|
199
|
+
return genericTypeAnnotation(identifier("Iterator"));
|
|
200
|
+
} else if (callee.node.returnType) {
|
|
201
|
+
return callee.node.returnType;
|
|
202
|
+
} else {}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
//# sourceMappingURL=inferers.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createUnionType = createUnionType;
|
|
7
|
+
var _t = require("@babel/types");
|
|
8
|
+
const {
|
|
9
|
+
createFlowUnionType,
|
|
10
|
+
createTSUnionType,
|
|
11
|
+
createUnionTypeAnnotation,
|
|
12
|
+
isFlowType,
|
|
13
|
+
isTSType
|
|
14
|
+
} = _t;
|
|
15
|
+
function createUnionType(types) {
|
|
16
|
+
{
|
|
17
|
+
if (types.every(v => isFlowType(v))) {
|
|
18
|
+
if (createFlowUnionType) {
|
|
19
|
+
return createFlowUnionType(types);
|
|
20
|
+
}
|
|
21
|
+
return createUnionTypeAnnotation(types);
|
|
22
|
+
} else if (types.every(v => isTSType(v))) {
|
|
23
|
+
if (createTSUnionType) {
|
|
24
|
+
return createTSUnionType(types);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports._guessExecutionStatusRelativeTo = _guessExecutionStatusRelativeTo;
|
|
7
|
+
exports._resolve = _resolve;
|
|
8
|
+
exports.canHaveVariableDeclarationOrExpression = canHaveVariableDeclarationOrExpression;
|
|
9
|
+
exports.canSwapBetweenExpressionAndStatement = canSwapBetweenExpressionAndStatement;
|
|
10
|
+
exports.getSource = getSource;
|
|
11
|
+
exports.isCompletionRecord = isCompletionRecord;
|
|
12
|
+
exports.isConstantExpression = isConstantExpression;
|
|
13
|
+
exports.isInStrictMode = isInStrictMode;
|
|
14
|
+
exports.isNodeType = isNodeType;
|
|
15
|
+
exports.isStatementOrBlock = isStatementOrBlock;
|
|
16
|
+
exports.isStatic = isStatic;
|
|
17
|
+
exports.matchesPattern = matchesPattern;
|
|
18
|
+
exports.referencesImport = referencesImport;
|
|
19
|
+
exports.resolve = resolve;
|
|
20
|
+
exports.willIMaybeExecuteBefore = willIMaybeExecuteBefore;
|
|
21
|
+
var _t = require("@babel/types");
|
|
22
|
+
const {
|
|
23
|
+
STATEMENT_OR_BLOCK_KEYS,
|
|
24
|
+
VISITOR_KEYS,
|
|
25
|
+
isBlockStatement,
|
|
26
|
+
isExpression,
|
|
27
|
+
isIdentifier,
|
|
28
|
+
isLiteral,
|
|
29
|
+
isStringLiteral,
|
|
30
|
+
isType,
|
|
31
|
+
matchesPattern: _matchesPattern
|
|
32
|
+
} = _t;
|
|
33
|
+
function matchesPattern(pattern, allowPartial) {
|
|
34
|
+
return _matchesPattern(this.node, pattern, allowPartial);
|
|
35
|
+
}
|
|
36
|
+
{
|
|
37
|
+
exports.has = function has(key) {
|
|
38
|
+
var _this$node;
|
|
39
|
+
const val = (_this$node = this.node) == null ? void 0 : _this$node[key];
|
|
40
|
+
if (val && Array.isArray(val)) {
|
|
41
|
+
return !!val.length;
|
|
42
|
+
} else {
|
|
43
|
+
return !!val;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function isStatic() {
|
|
48
|
+
return this.scope.isStatic(this.node);
|
|
49
|
+
}
|
|
50
|
+
{
|
|
51
|
+
exports.is = exports.has;
|
|
52
|
+
exports.isnt = function isnt(key) {
|
|
53
|
+
return !this.has(key);
|
|
54
|
+
};
|
|
55
|
+
exports.equals = function equals(key, value) {
|
|
56
|
+
return this.node[key] === value;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function isNodeType(type) {
|
|
60
|
+
return isType(this.type, type);
|
|
61
|
+
}
|
|
62
|
+
function canHaveVariableDeclarationOrExpression() {
|
|
63
|
+
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
|
|
64
|
+
}
|
|
65
|
+
function canSwapBetweenExpressionAndStatement(replacement) {
|
|
66
|
+
if (this.key !== "body" || !this.parentPath.isArrowFunctionExpression()) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (this.isExpression()) {
|
|
70
|
+
return isBlockStatement(replacement);
|
|
71
|
+
} else if (this.isBlockStatement()) {
|
|
72
|
+
return isExpression(replacement);
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function isCompletionRecord(allowInsideFunction) {
|
|
77
|
+
let path = this;
|
|
78
|
+
let first = true;
|
|
79
|
+
do {
|
|
80
|
+
const {
|
|
81
|
+
type,
|
|
82
|
+
container
|
|
83
|
+
} = path;
|
|
84
|
+
if (!first && (path.isFunction() || type === "StaticBlock")) {
|
|
85
|
+
return !!allowInsideFunction;
|
|
86
|
+
}
|
|
87
|
+
first = false;
|
|
88
|
+
if (Array.isArray(container) && path.key !== container.length - 1) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
} while ((path = path.parentPath) && !path.isProgram() && !path.isDoExpression());
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
function isStatementOrBlock() {
|
|
95
|
+
if (this.parentPath.isLabeledStatement() || isBlockStatement(this.container)) {
|
|
96
|
+
return false;
|
|
97
|
+
} else {
|
|
98
|
+
return STATEMENT_OR_BLOCK_KEYS.includes(this.key);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function referencesImport(moduleSource, importName) {
|
|
102
|
+
if (!this.isReferencedIdentifier()) {
|
|
103
|
+
if (this.isJSXMemberExpression() && this.node.property.name === importName || (this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? isStringLiteral(this.node.property, {
|
|
104
|
+
value: importName
|
|
105
|
+
}) : this.node.property.name === importName)) {
|
|
106
|
+
const object = this.get("object");
|
|
107
|
+
return object.isReferencedIdentifier() && object.referencesImport(moduleSource, "*");
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
const binding = this.scope.getBinding(this.node.name);
|
|
112
|
+
if (!binding || binding.kind !== "module") return false;
|
|
113
|
+
const path = binding.path;
|
|
114
|
+
const parent = path.parentPath;
|
|
115
|
+
if (!parent.isImportDeclaration()) return false;
|
|
116
|
+
if (parent.node.source.value === moduleSource) {
|
|
117
|
+
if (!importName) return true;
|
|
118
|
+
} else {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (path.isImportDefaultSpecifier() && importName === "default") {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (path.isImportNamespaceSpecifier() && importName === "*") {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
if (path.isImportSpecifier() && isIdentifier(path.node.imported, {
|
|
128
|
+
name: importName
|
|
129
|
+
})) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
function getSource() {
|
|
135
|
+
const node = this.node;
|
|
136
|
+
if (node.end) {
|
|
137
|
+
const code = this.hub.getCode();
|
|
138
|
+
if (code) return code.slice(node.start, node.end);
|
|
139
|
+
}
|
|
140
|
+
return "";
|
|
141
|
+
}
|
|
142
|
+
function willIMaybeExecuteBefore(target) {
|
|
143
|
+
return this._guessExecutionStatusRelativeTo(target) !== "after";
|
|
144
|
+
}
|
|
145
|
+
function getOuterFunction(path) {
|
|
146
|
+
return path.isProgram() ? path : (path.parentPath.scope.getFunctionParent() || path.parentPath.scope.getProgramParent()).path;
|
|
147
|
+
}
|
|
148
|
+
function isExecutionUncertain(type, key) {
|
|
149
|
+
switch (type) {
|
|
150
|
+
case "LogicalExpression":
|
|
151
|
+
return key === "right";
|
|
152
|
+
case "ConditionalExpression":
|
|
153
|
+
case "IfStatement":
|
|
154
|
+
return key === "consequent" || key === "alternate";
|
|
155
|
+
case "WhileStatement":
|
|
156
|
+
case "DoWhileStatement":
|
|
157
|
+
case "ForInStatement":
|
|
158
|
+
case "ForOfStatement":
|
|
159
|
+
return key === "body";
|
|
160
|
+
case "ForStatement":
|
|
161
|
+
return key === "body" || key === "update";
|
|
162
|
+
case "SwitchStatement":
|
|
163
|
+
return key === "cases";
|
|
164
|
+
case "TryStatement":
|
|
165
|
+
return key === "handler";
|
|
166
|
+
case "AssignmentPattern":
|
|
167
|
+
return key === "right";
|
|
168
|
+
case "OptionalMemberExpression":
|
|
169
|
+
return key === "property";
|
|
170
|
+
case "OptionalCallExpression":
|
|
171
|
+
return key === "arguments";
|
|
172
|
+
default:
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function isExecutionUncertainInList(paths, maxIndex) {
|
|
177
|
+
for (let i = 0; i < maxIndex; i++) {
|
|
178
|
+
const path = paths[i];
|
|
179
|
+
if (isExecutionUncertain(path.parent.type, path.parentKey)) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const SYMBOL_CHECKING = Symbol();
|
|
186
|
+
function _guessExecutionStatusRelativeTo(target) {
|
|
187
|
+
return _guessExecutionStatusRelativeToCached(this, target, new Map());
|
|
188
|
+
}
|
|
189
|
+
function _guessExecutionStatusRelativeToCached(base, target, cache) {
|
|
190
|
+
const funcParent = {
|
|
191
|
+
this: getOuterFunction(base),
|
|
192
|
+
target: getOuterFunction(target)
|
|
193
|
+
};
|
|
194
|
+
if (funcParent.target.node !== funcParent.this.node) {
|
|
195
|
+
return _guessExecutionStatusRelativeToDifferentFunctionsCached(base, funcParent.target, cache);
|
|
196
|
+
}
|
|
197
|
+
const paths = {
|
|
198
|
+
target: target.getAncestry(),
|
|
199
|
+
this: base.getAncestry()
|
|
200
|
+
};
|
|
201
|
+
if (paths.target.includes(base)) return "after";
|
|
202
|
+
if (paths.this.includes(target)) return "before";
|
|
203
|
+
let commonPath;
|
|
204
|
+
const commonIndex = {
|
|
205
|
+
target: 0,
|
|
206
|
+
this: 0
|
|
207
|
+
};
|
|
208
|
+
while (!commonPath && commonIndex.this < paths.this.length) {
|
|
209
|
+
const path = paths.this[commonIndex.this];
|
|
210
|
+
commonIndex.target = paths.target.indexOf(path);
|
|
211
|
+
if (commonIndex.target >= 0) {
|
|
212
|
+
commonPath = path;
|
|
213
|
+
} else {
|
|
214
|
+
commonIndex.this++;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (!commonPath) {
|
|
218
|
+
throw new Error("Internal Babel error - The two compared nodes" + " don't appear to belong to the same program.");
|
|
219
|
+
}
|
|
220
|
+
if (isExecutionUncertainInList(paths.this, commonIndex.this - 1) || isExecutionUncertainInList(paths.target, commonIndex.target - 1)) {
|
|
221
|
+
return "unknown";
|
|
222
|
+
}
|
|
223
|
+
const divergence = {
|
|
224
|
+
this: paths.this[commonIndex.this - 1],
|
|
225
|
+
target: paths.target[commonIndex.target - 1]
|
|
226
|
+
};
|
|
227
|
+
if (divergence.target.listKey && divergence.this.listKey && divergence.target.container === divergence.this.container) {
|
|
228
|
+
return divergence.target.key > divergence.this.key ? "before" : "after";
|
|
229
|
+
}
|
|
230
|
+
const keys = VISITOR_KEYS[commonPath.type];
|
|
231
|
+
const keyPosition = {
|
|
232
|
+
this: keys.indexOf(divergence.this.parentKey),
|
|
233
|
+
target: keys.indexOf(divergence.target.parentKey)
|
|
234
|
+
};
|
|
235
|
+
return keyPosition.target > keyPosition.this ? "before" : "after";
|
|
236
|
+
}
|
|
237
|
+
function _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache) {
|
|
238
|
+
if (!target.isFunctionDeclaration()) {
|
|
239
|
+
if (_guessExecutionStatusRelativeToCached(base, target, cache) === "before") {
|
|
240
|
+
return "before";
|
|
241
|
+
}
|
|
242
|
+
return "unknown";
|
|
243
|
+
} else if (target.parentPath.isExportDeclaration()) {
|
|
244
|
+
return "unknown";
|
|
245
|
+
}
|
|
246
|
+
const binding = target.scope.getBinding(target.node.id.name);
|
|
247
|
+
if (!binding.references) return "before";
|
|
248
|
+
const referencePaths = binding.referencePaths;
|
|
249
|
+
let allStatus;
|
|
250
|
+
for (const path of referencePaths) {
|
|
251
|
+
const childOfFunction = !!path.find(path => path.node === target.node);
|
|
252
|
+
if (childOfFunction) continue;
|
|
253
|
+
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
|
|
254
|
+
return "unknown";
|
|
255
|
+
}
|
|
256
|
+
const status = _guessExecutionStatusRelativeToCached(base, path, cache);
|
|
257
|
+
if (allStatus && allStatus !== status) {
|
|
258
|
+
return "unknown";
|
|
259
|
+
} else {
|
|
260
|
+
allStatus = status;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return allStatus;
|
|
264
|
+
}
|
|
265
|
+
function _guessExecutionStatusRelativeToDifferentFunctionsCached(base, target, cache) {
|
|
266
|
+
let nodeMap = cache.get(base.node);
|
|
267
|
+
let cached;
|
|
268
|
+
if (!nodeMap) {
|
|
269
|
+
cache.set(base.node, nodeMap = new Map());
|
|
270
|
+
} else if (cached = nodeMap.get(target.node)) {
|
|
271
|
+
if (cached === SYMBOL_CHECKING) {
|
|
272
|
+
return "unknown";
|
|
273
|
+
}
|
|
274
|
+
return cached;
|
|
275
|
+
}
|
|
276
|
+
nodeMap.set(target.node, SYMBOL_CHECKING);
|
|
277
|
+
const result = _guessExecutionStatusRelativeToDifferentFunctionsInternal(base, target, cache);
|
|
278
|
+
nodeMap.set(target.node, result);
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
function resolve(dangerous, resolved) {
|
|
282
|
+
return _resolve.call(this, dangerous, resolved) || this;
|
|
283
|
+
}
|
|
284
|
+
function _resolve(dangerous, resolved) {
|
|
285
|
+
var _resolved;
|
|
286
|
+
if ((_resolved = resolved) != null && _resolved.includes(this)) return;
|
|
287
|
+
resolved = resolved || [];
|
|
288
|
+
resolved.push(this);
|
|
289
|
+
if (this.isVariableDeclarator()) {
|
|
290
|
+
if (this.get("id").isIdentifier()) {
|
|
291
|
+
return this.get("init").resolve(dangerous, resolved);
|
|
292
|
+
} else {}
|
|
293
|
+
} else if (this.isReferencedIdentifier()) {
|
|
294
|
+
const binding = this.scope.getBinding(this.node.name);
|
|
295
|
+
if (!binding) return;
|
|
296
|
+
if (!binding.constant) return;
|
|
297
|
+
if (binding.kind === "module") return;
|
|
298
|
+
if (binding.path !== this) {
|
|
299
|
+
const ret = binding.path.resolve(dangerous, resolved);
|
|
300
|
+
if (this.find(parent => parent.node === ret.node)) return;
|
|
301
|
+
return ret;
|
|
302
|
+
}
|
|
303
|
+
} else if (this.isTypeCastExpression()) {
|
|
304
|
+
return this.get("expression").resolve(dangerous, resolved);
|
|
305
|
+
} else if (dangerous && this.isMemberExpression()) {
|
|
306
|
+
const targetKey = this.toComputedKey();
|
|
307
|
+
if (!isLiteral(targetKey)) return;
|
|
308
|
+
const targetName = targetKey.value;
|
|
309
|
+
const target = this.get("object").resolve(dangerous, resolved);
|
|
310
|
+
if (target.isObjectExpression()) {
|
|
311
|
+
const props = target.get("properties");
|
|
312
|
+
for (const prop of props) {
|
|
313
|
+
if (!prop.isProperty()) continue;
|
|
314
|
+
const key = prop.get("key");
|
|
315
|
+
let match = prop.isnt("computed") && key.isIdentifier({
|
|
316
|
+
name: targetName
|
|
317
|
+
});
|
|
318
|
+
match = match || key.isLiteral({
|
|
319
|
+
value: targetName
|
|
320
|
+
});
|
|
321
|
+
if (match) return prop.get("value").resolve(dangerous, resolved);
|
|
322
|
+
}
|
|
323
|
+
} else if (target.isArrayExpression() && !isNaN(+targetName)) {
|
|
324
|
+
const elems = target.get("elements");
|
|
325
|
+
const elem = elems[targetName];
|
|
326
|
+
if (elem) return elem.resolve(dangerous, resolved);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function isConstantExpression() {
|
|
331
|
+
if (this.isIdentifier()) {
|
|
332
|
+
const binding = this.scope.getBinding(this.node.name);
|
|
333
|
+
if (!binding) return false;
|
|
334
|
+
return binding.constant;
|
|
335
|
+
}
|
|
336
|
+
if (this.isLiteral()) {
|
|
337
|
+
if (this.isRegExpLiteral()) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
if (this.isTemplateLiteral()) {
|
|
341
|
+
return this.get("expressions").every(expression => expression.isConstantExpression());
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
if (this.isUnaryExpression()) {
|
|
346
|
+
if (this.node.operator !== "void") {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
return this.get("argument").isConstantExpression();
|
|
350
|
+
}
|
|
351
|
+
if (this.isBinaryExpression()) {
|
|
352
|
+
const {
|
|
353
|
+
operator
|
|
354
|
+
} = this.node;
|
|
355
|
+
return operator !== "in" && operator !== "instanceof" && this.get("left").isConstantExpression() && this.get("right").isConstantExpression();
|
|
356
|
+
}
|
|
357
|
+
if (this.isMemberExpression()) {
|
|
358
|
+
return !this.node.computed && this.get("object").isIdentifier({
|
|
359
|
+
name: "Symbol"
|
|
360
|
+
}) && !this.scope.hasBinding("Symbol", {
|
|
361
|
+
noGlobals: true
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
if (this.isCallExpression()) {
|
|
365
|
+
return this.node.arguments.length === 1 && this.get("callee").matchesPattern("Symbol.for") && !this.scope.hasBinding("Symbol", {
|
|
366
|
+
noGlobals: true
|
|
367
|
+
}) && this.get("arguments")[0].isStringLiteral();
|
|
368
|
+
}
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
function isInStrictMode() {
|
|
372
|
+
const start = this.isProgram() ? this : this.parentPath;
|
|
373
|
+
const strictParent = start.find(path => {
|
|
374
|
+
if (path.isProgram({
|
|
375
|
+
sourceType: "module"
|
|
376
|
+
})) return true;
|
|
377
|
+
if (path.isClass()) return true;
|
|
378
|
+
if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
let body;
|
|
382
|
+
if (path.isFunction()) {
|
|
383
|
+
body = path.node.body;
|
|
384
|
+
} else if (path.isProgram()) {
|
|
385
|
+
body = path.node;
|
|
386
|
+
} else {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
for (const directive of body.directives) {
|
|
390
|
+
if (directive.value.value === "use strict") {
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
return !!strictParent;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
//# sourceMappingURL=introspection.js.map
|