babel-plugin-vasille 3.2.1 → 4.0.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.
- package/README.md +5 -14
- package/lib/call.js +30 -30
- package/lib/css-transformer.js +42 -44
- package/lib/expression.js +116 -135
- package/lib/index.js +4 -1
- package/lib/internal.js +4 -19
- package/lib/jsx-detect.js +3 -54
- package/lib/jsx.js +244 -128
- package/lib/lib.js +103 -73
- package/lib/mesh.js +542 -494
- package/lib/order-check.js +48 -0
- package/lib/transformer.js +119 -79
- package/package.json +6 -7
- package/lib/bridge.js +0 -173
- package/lib-node/bridge.js +0 -173
- package/lib-node/call.js +0 -115
- package/lib-node/css-transformer.js +0 -248
- package/lib-node/expression.js +0 -600
- package/lib-node/index.js +0 -14
- package/lib-node/internal.js +0 -77
- package/lib-node/jsx-detect.js +0 -100
- package/lib-node/jsx.js +0 -453
- package/lib-node/lib.js +0 -159
- package/lib-node/mesh.js +0 -1051
- package/lib-node/router.js +0 -41
- package/lib-node/transformer.js +0 -150
- package/lib-node/utils.js +0 -50
package/lib-node/expression.js
DELETED
|
@@ -1,600 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.encodeName = encodeName;
|
|
37
|
-
exports.idIsIValue = idIsIValue;
|
|
38
|
-
exports.idIsLocal = idIsLocal;
|
|
39
|
-
exports.memberIsIValue = memberIsIValue;
|
|
40
|
-
exports.nodeIsReactiveObject = nodeIsReactiveObject;
|
|
41
|
-
exports.checkNode = checkNode;
|
|
42
|
-
exports.checkOrIgnoreAllExpressions = checkOrIgnoreAllExpressions;
|
|
43
|
-
exports.checkAllExpressions = checkAllExpressions;
|
|
44
|
-
exports.checkAllUnknown = checkAllUnknown;
|
|
45
|
-
exports.checkOrIgnoreExpression = checkOrIgnoreExpression;
|
|
46
|
-
exports.checkExpression = checkExpression;
|
|
47
|
-
exports.checkStatements = checkStatements;
|
|
48
|
-
exports.checkStatement = checkStatement;
|
|
49
|
-
exports.checkFunction = checkFunction;
|
|
50
|
-
const t = __importStar(require("@babel/types"));
|
|
51
|
-
const bridge_1 = require("./bridge");
|
|
52
|
-
const call_js_1 = require("./call.js");
|
|
53
|
-
const internal_js_1 = require("./internal.js");
|
|
54
|
-
const router_1 = require("./router");
|
|
55
|
-
const utils_1 = require("./utils");
|
|
56
|
-
function encodeName(name) {
|
|
57
|
-
return insertName(name);
|
|
58
|
-
}
|
|
59
|
-
function insertName(name, search) {
|
|
60
|
-
const id = t.identifier(`Vasille_${name}`);
|
|
61
|
-
search === null || search === void 0 ? void 0 : search.inserted.add(id);
|
|
62
|
-
return id;
|
|
63
|
-
}
|
|
64
|
-
function addIdentifier(path, search) {
|
|
65
|
-
if (!search.found.has(path.node.name)) {
|
|
66
|
-
search.found.set(path.node.name, path.node);
|
|
67
|
-
}
|
|
68
|
-
path.replaceWith(insertName(path.node.name, search));
|
|
69
|
-
}
|
|
70
|
-
function extractMemberName(path, search) {
|
|
71
|
-
const names = [];
|
|
72
|
-
let it = path.node;
|
|
73
|
-
while (t.isMemberExpression(it)) {
|
|
74
|
-
const name = (0, utils_1.stringify)(it.property);
|
|
75
|
-
if (name === "$" && it !== path.node) {
|
|
76
|
-
throw path.buildCodeFrameError("Vasille: The reactive/observable value is nested");
|
|
77
|
-
}
|
|
78
|
-
it = it.object;
|
|
79
|
-
names.push(name);
|
|
80
|
-
}
|
|
81
|
-
names.push((0, utils_1.stringify)(it));
|
|
82
|
-
if (t.isIdentifier(it) &&
|
|
83
|
-
search.stack.get(it.name, internal_js_1.VariableScope.Local) === 1 /* VariableState.Ignored */) {
|
|
84
|
-
throw path.buildCodeFrameError("Vasille: This node cannot be processed, the root of expression is a local variable");
|
|
85
|
-
}
|
|
86
|
-
return names.reverse().join("_");
|
|
87
|
-
}
|
|
88
|
-
function addMemberExpr(path, search) {
|
|
89
|
-
const name = extractMemberName(path, search);
|
|
90
|
-
/* istanbul ignore else */
|
|
91
|
-
if (!search.found.has(name)) {
|
|
92
|
-
search.found.set(name, path.node);
|
|
93
|
-
}
|
|
94
|
-
path.replaceWith(insertName(name, search));
|
|
95
|
-
}
|
|
96
|
-
function addExternalIValue(path, search) {
|
|
97
|
-
const name = extractMemberName(path, search);
|
|
98
|
-
if (!search.found.has(name)) {
|
|
99
|
-
search.found.set(name, path.node.object);
|
|
100
|
-
}
|
|
101
|
-
path.replaceWith(insertName(name, search));
|
|
102
|
-
}
|
|
103
|
-
function meshIdentifier(path, internal) {
|
|
104
|
-
if (idIsIValue(path, internal)) {
|
|
105
|
-
path.replaceWith(t.memberExpression(path.node, t.identifier("$")));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function idIsIValue(path, internal, scope) {
|
|
109
|
-
const node = path.node;
|
|
110
|
-
return (REACTIVE_STATES.includes(internal.stack.get(node.name, scope)) &&
|
|
111
|
-
(!t.isMemberExpression(path.parent) || path.parent.object === node));
|
|
112
|
-
}
|
|
113
|
-
function idIsLocal(path, internal) {
|
|
114
|
-
return internal.stack.get(path.node.name, internal_js_1.VariableScope.Local) !== undefined;
|
|
115
|
-
}
|
|
116
|
-
function memberIsIValue(node, internal, scope) {
|
|
117
|
-
return ((t.isIdentifier(node.object) &&
|
|
118
|
-
(internal.stack.get(node.object.name, scope) === 3 /* VariableState.ReactiveObject */ ||
|
|
119
|
-
(t.isIdentifier(node.property) &&
|
|
120
|
-
node.property.name.startsWith("$") &&
|
|
121
|
-
!node.property.name.startsWith("$$") &&
|
|
122
|
-
node.property.name !== "$") ||
|
|
123
|
-
(t.isStringLiteral(node.property) &&
|
|
124
|
-
node.property.value.startsWith("$") &&
|
|
125
|
-
!node.property.value.startsWith("$$") &&
|
|
126
|
-
node.property.value !== "$"))) ||
|
|
127
|
-
(t.isMemberExpression(node.object) &&
|
|
128
|
-
((t.isIdentifier(node.object.property) && node.object.property.name.startsWith("$$")) ||
|
|
129
|
-
(t.isStringLiteral(node.object.property) && node.object.property.value.startsWith("$$")))));
|
|
130
|
-
}
|
|
131
|
-
function nodeIsReactiveObject(path, internal) {
|
|
132
|
-
const node = path.node;
|
|
133
|
-
if (t.isIdentifier(node)) {
|
|
134
|
-
return internal.stack.get(node.name) === 3 /* VariableState.ReactiveObject */;
|
|
135
|
-
}
|
|
136
|
-
if (t.isOptionalMemberExpression(node) || t.isMemberExpression(node)) {
|
|
137
|
-
return ((t.isIdentifier(node.property) && node.property.name.startsWith("$$")) ||
|
|
138
|
-
(t.isStringLiteral(node.property) && node.property.value.startsWith("$$")));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function meshMember(path, internal) {
|
|
142
|
-
if (memberIsIValue(path.node, internal)) {
|
|
143
|
-
path.replaceWith(t.memberExpression(path.node, t.identifier("$")));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function meshLValue(path, internal) {
|
|
147
|
-
const node = path.node;
|
|
148
|
-
/* istanbul ignore else */
|
|
149
|
-
if (t.isIdentifier(node)) {
|
|
150
|
-
meshIdentifier(path, internal);
|
|
151
|
-
}
|
|
152
|
-
else if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
|
153
|
-
meshMember(path, internal);
|
|
154
|
-
}
|
|
155
|
-
else if (t.isArrayPattern(node)) {
|
|
156
|
-
for (const item of path.get("elements")) {
|
|
157
|
-
/* istanbul ignore else */
|
|
158
|
-
if (t.isOptionalMemberExpression(item.node) || t.isLVal(item.node)) {
|
|
159
|
-
meshLValue(item, internal);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
else if (t.isRestElement(node)) {
|
|
164
|
-
meshLValue(path.get("argument"), internal);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function checkNode(path, internal) {
|
|
168
|
-
const search = {
|
|
169
|
-
external: internal,
|
|
170
|
-
found: new Map(),
|
|
171
|
-
self: null,
|
|
172
|
-
inserted: new Set(),
|
|
173
|
-
stack: internal.stack,
|
|
174
|
-
};
|
|
175
|
-
if (t.isIdentifier(path.node)) {
|
|
176
|
-
if (idIsIValue(path, internal)) {
|
|
177
|
-
search.self = path.node;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (t.isMemberExpression(path.node)) {
|
|
181
|
-
if (memberIsIValue(path.node, internal)) {
|
|
182
|
-
search.self = path.node;
|
|
183
|
-
}
|
|
184
|
-
else if (t.isIdentifier(path.node.property) && path.node.property.name === "$") {
|
|
185
|
-
search.self = path.node.object;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (search.self) {
|
|
189
|
-
return search;
|
|
190
|
-
}
|
|
191
|
-
internal.stack.fixLocalIndex();
|
|
192
|
-
internal.stack.push();
|
|
193
|
-
/* istanbul ignore else */
|
|
194
|
-
if (t.isExpression(path.node)) {
|
|
195
|
-
checkExpression(path, search);
|
|
196
|
-
}
|
|
197
|
-
internal.stack.pop();
|
|
198
|
-
internal.stack.resetLocalIndex();
|
|
199
|
-
return search;
|
|
200
|
-
}
|
|
201
|
-
function checkOrIgnoreAllExpressions(nodePaths, search) {
|
|
202
|
-
for (const path of nodePaths) {
|
|
203
|
-
/* istanbul ignore else */
|
|
204
|
-
if (t.isExpression(path.node)) {
|
|
205
|
-
checkExpression(path, search);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
function checkAllExpressions(nodePaths, search) {
|
|
210
|
-
for (const path of nodePaths) {
|
|
211
|
-
checkExpression(path, search);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function checkAllUnknown(paths, internal) {
|
|
215
|
-
for (const path of paths) {
|
|
216
|
-
/* istanbul ignore else */
|
|
217
|
-
if (t.isSpreadElement(path.node)) {
|
|
218
|
-
checkExpression(path.get("argument"), internal);
|
|
219
|
-
}
|
|
220
|
-
else if (t.isExpression(path.node)) {
|
|
221
|
-
checkExpression(path, internal);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function checkOrIgnoreExpression(path, search) {
|
|
226
|
-
/* istanbul ignore else */
|
|
227
|
-
if (t.isExpression(path.node)) {
|
|
228
|
-
checkExpression(path, search);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
const REACTIVE_STATES = [2 /* VariableState.Reactive */, 4 /* VariableState.ReactivePointer */];
|
|
232
|
-
function checkExpression(nodePath, search) {
|
|
233
|
-
const expr = nodePath.node;
|
|
234
|
-
switch (expr && expr.type) {
|
|
235
|
-
case "TemplateLiteral": {
|
|
236
|
-
const path = nodePath;
|
|
237
|
-
checkOrIgnoreAllExpressions(path.get("expressions"), search);
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case "TaggedTemplateExpression": {
|
|
241
|
-
const path = nodePath;
|
|
242
|
-
checkExpression(path.get("quasi"), search);
|
|
243
|
-
path.get("");
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
case "Identifier": {
|
|
247
|
-
/* istanbul ignore else */
|
|
248
|
-
if (expr && t.isIdentifier(expr)) {
|
|
249
|
-
if (idIsIValue(nodePath, search.external, internal_js_1.VariableScope.Global) &&
|
|
250
|
-
!idIsLocal(nodePath, search.external)) {
|
|
251
|
-
addIdentifier(nodePath, search);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
case "ArrayExpression": {
|
|
257
|
-
const path = nodePath;
|
|
258
|
-
checkAllUnknown(path.get("elements"), search);
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
case "CallExpression": {
|
|
262
|
-
const path = nodePath;
|
|
263
|
-
const bridge = (0, bridge_1.processBridgeCall)(path, search.external, search);
|
|
264
|
-
if (bridge) {
|
|
265
|
-
if (bridge === "value") {
|
|
266
|
-
addMemberExpr(nodePath, search);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
else if ((0, call_js_1.calls)(path, ["router"], search.external)) {
|
|
270
|
-
if (!search.external.stateOnly) {
|
|
271
|
-
(0, router_1.routerReplace)(path);
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
throw path.buildCodeFrameError("Vasille: The router is not available in stores");
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
if ((0, call_js_1.calls)(path, call_js_1.composeOnly, search.external)) {
|
|
279
|
-
throw path.buildCodeFrameError("Vasille: Usage of hints is restricted here");
|
|
280
|
-
}
|
|
281
|
-
checkOrIgnoreExpression(path.get("callee"), search);
|
|
282
|
-
checkAllUnknown(path.get("arguments"), search);
|
|
283
|
-
}
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
case "OptionalCallExpression": {
|
|
287
|
-
const path = nodePath;
|
|
288
|
-
checkExpression(path.get("callee"), search);
|
|
289
|
-
checkAllUnknown(path.get("arguments"), search);
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
case "AssignmentExpression": {
|
|
293
|
-
const path = nodePath;
|
|
294
|
-
meshLValue(path.get("left"), search.external);
|
|
295
|
-
checkExpression(path.get("right"), search);
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
case "MemberExpression":
|
|
299
|
-
case "OptionalMemberExpression": {
|
|
300
|
-
const path = nodePath;
|
|
301
|
-
const node = path.node;
|
|
302
|
-
if (memberIsIValue(node, search.external, internal_js_1.VariableScope.Global)) {
|
|
303
|
-
addMemberExpr(path, search);
|
|
304
|
-
}
|
|
305
|
-
else if (t.isIdentifier(node.property) && node.property.name === "$") {
|
|
306
|
-
addExternalIValue(path, search);
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
checkExpression(path.get("object"), search);
|
|
310
|
-
checkOrIgnoreExpression(path.get("property"), search);
|
|
311
|
-
}
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
case "BinaryExpression": {
|
|
315
|
-
const path = nodePath;
|
|
316
|
-
checkOrIgnoreExpression(path.get("left"), search);
|
|
317
|
-
checkExpression(path.get("right"), search);
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
case "ConditionalExpression": {
|
|
321
|
-
const path = nodePath;
|
|
322
|
-
checkExpression(path.get("test"), search);
|
|
323
|
-
checkExpression(path.get("consequent"), search);
|
|
324
|
-
checkExpression(path.get("alternate"), search);
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
case "LogicalExpression": {
|
|
328
|
-
const path = nodePath;
|
|
329
|
-
checkExpression(path.get("left"), search);
|
|
330
|
-
checkExpression(path.get("right"), search);
|
|
331
|
-
break;
|
|
332
|
-
}
|
|
333
|
-
case "NewExpression": {
|
|
334
|
-
const path = nodePath;
|
|
335
|
-
checkOrIgnoreExpression(path.get("callee"), search);
|
|
336
|
-
checkAllUnknown(path.get("arguments"), search);
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
case "SequenceExpression": {
|
|
340
|
-
const path = nodePath;
|
|
341
|
-
checkAllExpressions(path.get("expressions"), search);
|
|
342
|
-
break;
|
|
343
|
-
}
|
|
344
|
-
case "UnaryExpression": {
|
|
345
|
-
const path = nodePath;
|
|
346
|
-
checkExpression(path.get("argument"), search);
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
case "UpdateExpression": {
|
|
350
|
-
const path = nodePath;
|
|
351
|
-
const arg = path.node.argument;
|
|
352
|
-
/* istanbul ignore else */
|
|
353
|
-
if (t.isLVal(arg)) {
|
|
354
|
-
meshLValue(path.get("argument"), search.external);
|
|
355
|
-
}
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
case "YieldExpression": {
|
|
359
|
-
const path = nodePath;
|
|
360
|
-
checkExpression(path.get("argument"), search);
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
|
-
case "AwaitExpression": {
|
|
364
|
-
const path = nodePath;
|
|
365
|
-
checkExpression(path.get("argument"), search);
|
|
366
|
-
break;
|
|
367
|
-
}
|
|
368
|
-
case "TSInstantiationExpression": {
|
|
369
|
-
const path = nodePath;
|
|
370
|
-
checkExpression(path.get("expression"), search);
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
case "TSAsExpression": {
|
|
374
|
-
const path = nodePath;
|
|
375
|
-
checkExpression(path.get("expression"), search);
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
case "TSSatisfiesExpression": {
|
|
379
|
-
const path = nodePath;
|
|
380
|
-
checkExpression(path.get("expression"), search);
|
|
381
|
-
break;
|
|
382
|
-
}
|
|
383
|
-
case "TSTypeAssertion": {
|
|
384
|
-
const path = nodePath;
|
|
385
|
-
checkExpression(path.get("expression"), search);
|
|
386
|
-
break;
|
|
387
|
-
}
|
|
388
|
-
case "ObjectExpression": {
|
|
389
|
-
const path = nodePath;
|
|
390
|
-
for (const propPath of path.get("properties")) {
|
|
391
|
-
const prop = propPath.node;
|
|
392
|
-
if (t.isObjectProperty(prop)) {
|
|
393
|
-
const path = propPath;
|
|
394
|
-
const valuePath = path.get("value");
|
|
395
|
-
if (path.node.computed) {
|
|
396
|
-
checkOrIgnoreExpression(path.get("key"), search);
|
|
397
|
-
}
|
|
398
|
-
checkOrIgnoreExpression(valuePath, search);
|
|
399
|
-
}
|
|
400
|
-
else if (t.isObjectMethod(prop)) {
|
|
401
|
-
checkFunction(propPath, search);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
checkAllUnknown([propPath], search);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
case "FunctionExpression": {
|
|
410
|
-
checkFunction(nodePath, search);
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
case "ArrowFunctionExpression": {
|
|
414
|
-
checkFunction(nodePath, search);
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
case "JSXFragment": {
|
|
418
|
-
throw nodePath.buildCodeFrameError("Vasille: JSX fragment is not allowed here");
|
|
419
|
-
}
|
|
420
|
-
case "JSXElement": {
|
|
421
|
-
throw nodePath.buildCodeFrameError("Vasille: JSX element is not allowed here");
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
function checkStatements(paths, search) {
|
|
426
|
-
for (const path of paths) {
|
|
427
|
-
checkStatement(path, search);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
function ignoreLocals(val, search) {
|
|
431
|
-
/* istanbul ignore else */
|
|
432
|
-
if (t.isIdentifier(val)) {
|
|
433
|
-
search.stack.set(val.name, 1 /* VariableState.Ignored */);
|
|
434
|
-
}
|
|
435
|
-
else if (t.isObjectPattern(val)) {
|
|
436
|
-
for (const prop of val.properties) {
|
|
437
|
-
/* istanbul ignore else */
|
|
438
|
-
if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
|
|
439
|
-
search.stack.set(prop.value.name, 1 /* VariableState.Ignored */);
|
|
440
|
-
}
|
|
441
|
-
else if (t.isRestElement(prop) && t.isIdentifier(prop.argument)) {
|
|
442
|
-
search.stack.set(prop.argument.name, 1 /* VariableState.Ignored */);
|
|
443
|
-
}
|
|
444
|
-
else if (t.isObjectProperty(prop) && t.isAssignmentPattern(prop.value)) {
|
|
445
|
-
ignoreLocals(prop.value.left, search);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
else if (t.isArrayPattern(val)) {
|
|
450
|
-
for (const element of val.elements) {
|
|
451
|
-
/* istanbul ignore else */
|
|
452
|
-
if (element && !t.isVoidPattern(element)) {
|
|
453
|
-
ignoreLocals(element, search);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
else if (t.isVariableDeclaration(val)) {
|
|
458
|
-
for (const declarator of val.declarations) {
|
|
459
|
-
/* istanbul ignore else */
|
|
460
|
-
if (!t.isVoidPattern(declarator.id)) {
|
|
461
|
-
ignoreLocals(declarator.id, search);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
function checkStatement(path, search) {
|
|
467
|
-
const statement = path.node;
|
|
468
|
-
if (!statement) {
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
switch (statement.type) {
|
|
472
|
-
case "BlockStatement":
|
|
473
|
-
search.stack.push();
|
|
474
|
-
checkStatements(path.get("body"), search);
|
|
475
|
-
search.stack.pop();
|
|
476
|
-
break;
|
|
477
|
-
case "DoWhileStatement": {
|
|
478
|
-
const _path = path;
|
|
479
|
-
checkExpression(_path.get("test"), search);
|
|
480
|
-
search.stack.push();
|
|
481
|
-
checkStatement(_path.get("body"), search);
|
|
482
|
-
search.stack.pop();
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
case "ExpressionStatement":
|
|
486
|
-
checkExpression(path.get("expression"), search);
|
|
487
|
-
break;
|
|
488
|
-
case "ForInStatement": {
|
|
489
|
-
const _path = path;
|
|
490
|
-
ignoreLocals(_path.node.left, search);
|
|
491
|
-
checkExpression(_path.get("right"), search);
|
|
492
|
-
checkStatement(_path.get("body"), search);
|
|
493
|
-
break;
|
|
494
|
-
}
|
|
495
|
-
case "ForOfStatement": {
|
|
496
|
-
const _path = path;
|
|
497
|
-
checkExpression(_path.get("right"), search);
|
|
498
|
-
search.stack.push();
|
|
499
|
-
checkStatement(_path.get("body"), search);
|
|
500
|
-
search.stack.pop();
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
case "ForStatement": {
|
|
504
|
-
const _path = path;
|
|
505
|
-
const node = _path.node;
|
|
506
|
-
/* istanbul ignore else */
|
|
507
|
-
if (node.init) {
|
|
508
|
-
if (t.isExpression(node.init)) {
|
|
509
|
-
checkExpression(_path.get("init"), search);
|
|
510
|
-
}
|
|
511
|
-
else {
|
|
512
|
-
const variablePath = _path.get("init");
|
|
513
|
-
for (const declarationPath of variablePath.get("declarations")) {
|
|
514
|
-
checkExpression(declarationPath.get("init"), search);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
checkExpression(_path.get("test"), search);
|
|
519
|
-
checkExpression(_path.get("update"), search);
|
|
520
|
-
search.stack.push();
|
|
521
|
-
checkStatement(_path.get("body"), search);
|
|
522
|
-
search.stack.pop();
|
|
523
|
-
break;
|
|
524
|
-
}
|
|
525
|
-
case "FunctionDeclaration":
|
|
526
|
-
checkFunction(path, search);
|
|
527
|
-
break;
|
|
528
|
-
case "IfStatement": {
|
|
529
|
-
const _path = path;
|
|
530
|
-
checkExpression(_path.get("test"), search);
|
|
531
|
-
search.stack.push();
|
|
532
|
-
checkStatement(_path.get("consequent"), search);
|
|
533
|
-
search.stack.pop();
|
|
534
|
-
search.stack.push();
|
|
535
|
-
checkStatement(_path.get("alternate"), search);
|
|
536
|
-
search.stack.pop();
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
case "LabeledStatement":
|
|
540
|
-
search.stack.push();
|
|
541
|
-
checkStatement(path.get("body"), search);
|
|
542
|
-
search.stack.pop();
|
|
543
|
-
break;
|
|
544
|
-
case "ReturnStatement":
|
|
545
|
-
checkExpression(path.get("argument"), search);
|
|
546
|
-
break;
|
|
547
|
-
case "SwitchStatement": {
|
|
548
|
-
const _path = path;
|
|
549
|
-
checkExpression(_path.get("discriminant"), search);
|
|
550
|
-
search.stack.push();
|
|
551
|
-
for (const _case of _path.get("cases")) {
|
|
552
|
-
checkExpression(_case.get("test"), search);
|
|
553
|
-
checkStatements(_case.get("consequent"), search);
|
|
554
|
-
}
|
|
555
|
-
search.stack.pop();
|
|
556
|
-
break;
|
|
557
|
-
}
|
|
558
|
-
case "ThrowStatement":
|
|
559
|
-
checkExpression(path.get("argument"), search);
|
|
560
|
-
break;
|
|
561
|
-
case "TryStatement":
|
|
562
|
-
const handlerPath = path.get("handler");
|
|
563
|
-
checkStatement(path.get("block"), search);
|
|
564
|
-
/* istanbul ignore else */
|
|
565
|
-
if (handlerPath.node) {
|
|
566
|
-
checkStatement(handlerPath.get("body"), search);
|
|
567
|
-
}
|
|
568
|
-
checkStatement(path.get("finalizer"), search);
|
|
569
|
-
break;
|
|
570
|
-
case "VariableDeclaration": {
|
|
571
|
-
const _path = path;
|
|
572
|
-
for (const declaration of _path.get("declarations")) {
|
|
573
|
-
ignoreLocals(declaration.node.id, search);
|
|
574
|
-
checkExpression(declaration.get("init"), search);
|
|
575
|
-
}
|
|
576
|
-
break;
|
|
577
|
-
}
|
|
578
|
-
case "WhileStatement": {
|
|
579
|
-
const _path = path;
|
|
580
|
-
checkExpression(_path.get("test"), search);
|
|
581
|
-
search.stack.push();
|
|
582
|
-
checkStatement(_path.get("body"), search);
|
|
583
|
-
search.stack.pop();
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
function checkFunction(path, search) {
|
|
589
|
-
const node = path.node;
|
|
590
|
-
for (const param of node.params) {
|
|
591
|
-
ignoreLocals(param, search);
|
|
592
|
-
}
|
|
593
|
-
if (t.isExpression(node.body)) {
|
|
594
|
-
checkExpression(path.get("body"), search);
|
|
595
|
-
}
|
|
596
|
-
else {
|
|
597
|
-
const bodyPath = path.get("body");
|
|
598
|
-
checkStatement(bodyPath, search);
|
|
599
|
-
}
|
|
600
|
-
}
|
package/lib-node/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = default_1;
|
|
4
|
-
const transformer_js_1 = require("./transformer.js");
|
|
5
|
-
function default_1() {
|
|
6
|
-
return {
|
|
7
|
-
name: "Vasille",
|
|
8
|
-
visitor: {
|
|
9
|
-
Program(path, params) {
|
|
10
|
-
(0, transformer_js_1.trProgram)(path, params.opts.devMode !== false);
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
package/lib-node/internal.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ctx = exports.StackedStates = exports.VariableScope = void 0;
|
|
37
|
-
const t = __importStar(require("@babel/types"));
|
|
38
|
-
var VariableScope;
|
|
39
|
-
(function (VariableScope) {
|
|
40
|
-
VariableScope[VariableScope["Any"] = 0] = "Any";
|
|
41
|
-
VariableScope[VariableScope["Local"] = 1] = "Local";
|
|
42
|
-
VariableScope[VariableScope["Global"] = 2] = "Global";
|
|
43
|
-
})(VariableScope || (exports.VariableScope = VariableScope = {}));
|
|
44
|
-
class StackedStates {
|
|
45
|
-
constructor() {
|
|
46
|
-
this.maps = [];
|
|
47
|
-
this.localIndex = -1;
|
|
48
|
-
this.push();
|
|
49
|
-
}
|
|
50
|
-
fixLocalIndex() {
|
|
51
|
-
this.localIndex = this.maps.length;
|
|
52
|
-
}
|
|
53
|
-
resetLocalIndex() {
|
|
54
|
-
this.localIndex = -1;
|
|
55
|
-
}
|
|
56
|
-
push() {
|
|
57
|
-
this.maps.push(new Map());
|
|
58
|
-
}
|
|
59
|
-
pop() {
|
|
60
|
-
this.maps.pop();
|
|
61
|
-
}
|
|
62
|
-
get(name, scope) {
|
|
63
|
-
for (let i = (this.localIndex === -1 || scope !== VariableScope.Global
|
|
64
|
-
? this.maps.length
|
|
65
|
-
: Math.min(this.maps.length, this.localIndex)) - 1; i >= (this.localIndex === -1 || scope !== VariableScope.Local ? 0 : this.localIndex); i--) {
|
|
66
|
-
if (this.maps[i].has(name)) {
|
|
67
|
-
return this.maps[i].get(name);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
set(name, state) {
|
|
73
|
-
this.maps[this.maps.length - 1].set(name, state);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.StackedStates = StackedStates;
|
|
77
|
-
exports.ctx = t.identifier("Vasille");
|