babel-plugin-vasille 0.99.5 → 3.1.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 +3 -4
- package/lib/call.js +19 -17
- package/lib/css-transformer.js +18 -21
- package/lib/expression.js +107 -100
- package/lib/index.js +1 -1
- package/lib/internal.js +17 -2
- package/lib/jsx-detect.js +11 -9
- package/lib/jsx.js +63 -64
- package/lib/lib.js +67 -49
- package/lib/mesh.js +258 -319
- package/lib/transformer.js +16 -40
- package/lib-node/call.js +38 -26
- package/lib-node/css-transformer.js +38 -31
- package/lib-node/expression.js +129 -108
- package/lib-node/index.js +2 -2
- package/lib-node/internal.js +35 -10
- package/lib-node/jsx-detect.js +28 -16
- package/lib-node/jsx.js +90 -80
- package/lib-node/lib.js +90 -61
- package/lib-node/mesh.js +291 -343
- package/lib-node/transformer.js +36 -50
- package/package.json +21 -17
package/lib-node/expression.js
CHANGED
|
@@ -15,26 +15,41 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
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
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.encodeName = encodeName;
|
|
37
|
+
exports.idIsIValue = idIsIValue;
|
|
38
|
+
exports.idIsLocal = idIsLocal;
|
|
39
|
+
exports.memberIsIValue = memberIsIValue;
|
|
40
|
+
exports.nodeIsReactiveObject = nodeIsReactiveObject;
|
|
27
41
|
exports.checkNode = checkNode;
|
|
28
42
|
exports.checkOrIgnoreAllExpressions = checkOrIgnoreAllExpressions;
|
|
29
43
|
exports.checkAllExpressions = checkAllExpressions;
|
|
30
44
|
exports.checkAllUnknown = checkAllUnknown;
|
|
31
|
-
exports.
|
|
45
|
+
exports.checkOrIgnoreExpression = checkOrIgnoreExpression;
|
|
32
46
|
exports.checkExpression = checkExpression;
|
|
33
47
|
exports.checkStatements = checkStatements;
|
|
34
48
|
exports.checkStatement = checkStatement;
|
|
35
49
|
exports.checkFunction = checkFunction;
|
|
36
50
|
const t = __importStar(require("@babel/types"));
|
|
37
|
-
const
|
|
51
|
+
const call_js_1 = require("./call.js");
|
|
52
|
+
const internal_js_1 = require("./internal.js");
|
|
38
53
|
function encodeName(name) {
|
|
39
54
|
return t.identifier(`Vasille_${name}`);
|
|
40
55
|
}
|
|
@@ -45,16 +60,17 @@ function addIdentifier(path, search) {
|
|
|
45
60
|
path.replaceWith(encodeName(path.node.name));
|
|
46
61
|
}
|
|
47
62
|
function stringify(node) {
|
|
48
|
-
|
|
49
|
-
return node.name;
|
|
50
|
-
}
|
|
63
|
+
let name = "";
|
|
51
64
|
if (t.isStringLiteral(node)) {
|
|
52
|
-
|
|
65
|
+
name = node.value;
|
|
53
66
|
}
|
|
54
67
|
if (t.isPrivateName(node)) {
|
|
55
|
-
|
|
68
|
+
name = node.id.name;
|
|
56
69
|
}
|
|
57
|
-
|
|
70
|
+
if (t.isIdentifier(node)) {
|
|
71
|
+
name = node.name;
|
|
72
|
+
}
|
|
73
|
+
return name;
|
|
58
74
|
}
|
|
59
75
|
function extractMemberName(path, search) {
|
|
60
76
|
const names = [];
|
|
@@ -65,10 +81,11 @@ function extractMemberName(path, search) {
|
|
|
65
81
|
throw path.buildCodeFrameError("Vasille: The reactive/observable value is nested");
|
|
66
82
|
}
|
|
67
83
|
it = it.object;
|
|
68
|
-
names.push();
|
|
84
|
+
names.push(name);
|
|
69
85
|
}
|
|
70
86
|
names.push(stringify(it));
|
|
71
|
-
if (t.isIdentifier(it) &&
|
|
87
|
+
if (t.isIdentifier(it) &&
|
|
88
|
+
search.stack.get(it.name, internal_js_1.VariableScope.Local) === 1 /* VariableState.Ignored */) {
|
|
72
89
|
throw path.buildCodeFrameError("Vasille: This node cannot be processed, the root of expression is a local variable");
|
|
73
90
|
}
|
|
74
91
|
return names.reverse().join("_");
|
|
@@ -88,35 +105,65 @@ function addExternalIValue(path, search) {
|
|
|
88
105
|
path.replaceWith(encodeName(name));
|
|
89
106
|
}
|
|
90
107
|
function meshIdentifier(path, internal) {
|
|
91
|
-
|
|
92
|
-
if (state === 2 /* VariableState.Reactive */ || state === 4 /* VariableState.ReactivePointer */) {
|
|
108
|
+
if (idIsIValue(path, internal)) {
|
|
93
109
|
path.replaceWith(t.memberExpression(path.node, t.identifier("$")));
|
|
94
110
|
}
|
|
95
111
|
}
|
|
112
|
+
function idIsIValue(path, internal, scope) {
|
|
113
|
+
const node = path.node;
|
|
114
|
+
return (REACTIVE_STATES.includes(internal.stack.get(node.name, scope)) &&
|
|
115
|
+
(!t.isMemberExpression(path.parent) || path.parent.object === node));
|
|
116
|
+
}
|
|
117
|
+
function idIsLocal(path, internal) {
|
|
118
|
+
return internal.stack.get(path.node.name, internal_js_1.VariableScope.Local) !== undefined;
|
|
119
|
+
}
|
|
120
|
+
function memberIsIValue(node, internal, scope) {
|
|
121
|
+
return ((t.isIdentifier(node.object) &&
|
|
122
|
+
(internal.stack.get(node.object.name, scope) === 3 /* VariableState.ReactiveObject */ ||
|
|
123
|
+
(t.isIdentifier(node.property) &&
|
|
124
|
+
node.property.name.startsWith("$") &&
|
|
125
|
+
!node.property.name.startsWith("$$") &&
|
|
126
|
+
node.property.name !== "$") ||
|
|
127
|
+
(t.isStringLiteral(node.property) &&
|
|
128
|
+
node.property.value.startsWith("$") &&
|
|
129
|
+
!node.property.value.startsWith("$$") &&
|
|
130
|
+
node.property.value !== "$"))) ||
|
|
131
|
+
(t.isMemberExpression(node.object) &&
|
|
132
|
+
((t.isIdentifier(node.object.property) && node.object.property.name.startsWith("$$")) ||
|
|
133
|
+
(t.isStringLiteral(node.object.property) && node.object.property.value.startsWith("$$")))));
|
|
134
|
+
}
|
|
135
|
+
function nodeIsReactiveObject(path, internal) {
|
|
136
|
+
const node = path.node;
|
|
137
|
+
if (t.isIdentifier(node)) {
|
|
138
|
+
return internal.stack.get(node.name) === 3 /* VariableState.ReactiveObject */;
|
|
139
|
+
}
|
|
140
|
+
if (t.isOptionalMemberExpression(node) || t.isMemberExpression(node)) {
|
|
141
|
+
return ((t.isIdentifier(node.property) && node.property.name.startsWith("$$")) ||
|
|
142
|
+
(t.isStringLiteral(node.property) && node.property.value.startsWith("$$")));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
96
145
|
function meshMember(path, internal) {
|
|
97
|
-
if (
|
|
146
|
+
if (memberIsIValue(path.node, internal)) {
|
|
98
147
|
path.replaceWith(t.memberExpression(path.node, t.identifier("$")));
|
|
99
148
|
}
|
|
100
149
|
}
|
|
101
150
|
function meshLValue(path, internal) {
|
|
102
|
-
|
|
151
|
+
const node = path.node;
|
|
152
|
+
if (t.isIdentifier(node)) {
|
|
103
153
|
meshIdentifier(path, internal);
|
|
104
154
|
}
|
|
105
|
-
else if (t.isMemberExpression(
|
|
155
|
+
else if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
|
106
156
|
meshMember(path, internal);
|
|
107
157
|
}
|
|
108
|
-
else {
|
|
109
|
-
path.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
meshMember(path, internal);
|
|
118
|
-
},
|
|
119
|
-
});
|
|
158
|
+
else if (t.isArrayPattern(node)) {
|
|
159
|
+
for (const item of path.get("elements")) {
|
|
160
|
+
if (t.isOptionalMemberExpression(item.node) || t.isLVal(item.node)) {
|
|
161
|
+
meshLValue(item, internal);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (t.isRestElement(node)) {
|
|
166
|
+
meshLValue(path.get("argument"), internal);
|
|
120
167
|
}
|
|
121
168
|
}
|
|
122
169
|
function checkNode(path, internal) {
|
|
@@ -124,29 +171,31 @@ function checkNode(path, internal) {
|
|
|
124
171
|
external: internal,
|
|
125
172
|
found: new Map(),
|
|
126
173
|
self: null,
|
|
127
|
-
stack:
|
|
174
|
+
stack: internal.stack,
|
|
128
175
|
};
|
|
129
176
|
if (t.isIdentifier(path.node)) {
|
|
130
|
-
|
|
131
|
-
if (state === 2 /* VariableState.Reactive */ || state == 4 /* VariableState.ReactivePointer */) {
|
|
177
|
+
if (idIsIValue(path, internal)) {
|
|
132
178
|
search.self = path.node;
|
|
133
179
|
}
|
|
134
180
|
}
|
|
135
181
|
if (t.isMemberExpression(path.node)) {
|
|
136
|
-
if (
|
|
137
|
-
internal.stack.get(path.node.object.name) === 3 /* VariableState.ReactiveObject */) {
|
|
182
|
+
if (memberIsIValue(path.node, internal)) {
|
|
138
183
|
search.self = path.node;
|
|
139
184
|
}
|
|
140
|
-
if (t.isIdentifier(path.node.property) && path.node.property.name === "$") {
|
|
185
|
+
else if (t.isIdentifier(path.node.property) && path.node.property.name === "$") {
|
|
141
186
|
search.self = path.node.object;
|
|
142
187
|
}
|
|
143
188
|
}
|
|
144
189
|
if (search.self) {
|
|
145
190
|
return search;
|
|
146
191
|
}
|
|
192
|
+
internal.stack.fixLocalIndex();
|
|
193
|
+
internal.stack.push();
|
|
147
194
|
if (t.isExpression(path.node)) {
|
|
148
195
|
checkExpression(path, search);
|
|
149
196
|
}
|
|
197
|
+
internal.stack.pop();
|
|
198
|
+
internal.stack.resetLocalIndex();
|
|
150
199
|
return search;
|
|
151
200
|
}
|
|
152
201
|
function checkOrIgnoreAllExpressions(nodePaths, search) {
|
|
@@ -171,17 +220,15 @@ function checkAllUnknown(paths, internal) {
|
|
|
171
220
|
}
|
|
172
221
|
}
|
|
173
222
|
}
|
|
174
|
-
function
|
|
223
|
+
function checkOrIgnoreExpression(path, search) {
|
|
175
224
|
if (t.isExpression(path.node)) {
|
|
176
225
|
checkExpression(path, search);
|
|
177
226
|
}
|
|
178
227
|
}
|
|
228
|
+
const REACTIVE_STATES = [2 /* VariableState.Reactive */, 4 /* VariableState.ReactivePointer */];
|
|
179
229
|
function checkExpression(nodePath, search) {
|
|
180
230
|
const expr = nodePath.node;
|
|
181
|
-
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
switch (expr.type) {
|
|
231
|
+
switch (expr && expr.type) {
|
|
185
232
|
case "TemplateLiteral": {
|
|
186
233
|
const path = nodePath;
|
|
187
234
|
checkOrIgnoreAllExpressions(path.get("expressions"), search);
|
|
@@ -190,11 +237,13 @@ function checkExpression(nodePath, search) {
|
|
|
190
237
|
case "TaggedTemplateExpression": {
|
|
191
238
|
const path = nodePath;
|
|
192
239
|
checkExpression(path.get("quasi"), search);
|
|
240
|
+
path.get("");
|
|
193
241
|
break;
|
|
194
242
|
}
|
|
195
243
|
case "Identifier": {
|
|
196
|
-
if (
|
|
197
|
-
if (search.external.
|
|
244
|
+
if (expr && t.isIdentifier(expr)) {
|
|
245
|
+
if (idIsIValue(nodePath, search.external, internal_js_1.VariableScope.Global) &&
|
|
246
|
+
!idIsLocal(nodePath, search.external)) {
|
|
198
247
|
addIdentifier(nodePath, search);
|
|
199
248
|
}
|
|
200
249
|
}
|
|
@@ -205,14 +254,12 @@ function checkExpression(nodePath, search) {
|
|
|
205
254
|
checkAllUnknown(path.get("elements"), search);
|
|
206
255
|
break;
|
|
207
256
|
}
|
|
208
|
-
case "TupleExpression": {
|
|
209
|
-
const path = nodePath;
|
|
210
|
-
checkAllUnknown(path.get("elements"), search);
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
257
|
case "CallExpression": {
|
|
214
258
|
const path = nodePath;
|
|
215
|
-
|
|
259
|
+
if ((0, call_js_1.calls)(path.node, call_js_1.composeOnly, search.external)) {
|
|
260
|
+
throw path.buildCodeFrameError("Vasille: Usage of hints is restricted here");
|
|
261
|
+
}
|
|
262
|
+
checkOrIgnoreExpression(path.get("callee"), search);
|
|
216
263
|
checkAllUnknown(path.get("arguments"), search);
|
|
217
264
|
break;
|
|
218
265
|
}
|
|
@@ -232,19 +279,21 @@ function checkExpression(nodePath, search) {
|
|
|
232
279
|
case "OptionalMemberExpression": {
|
|
233
280
|
const path = nodePath;
|
|
234
281
|
const node = path.node;
|
|
235
|
-
|
|
236
|
-
chekOrIgnoreExpression(path.get("property"), search);
|
|
237
|
-
if (t.isIdentifier(node.object) && search.external.stack.get(node.object.name) === 3 /* VariableState.ReactiveObject */) {
|
|
282
|
+
if (memberIsIValue(node, search.external, internal_js_1.VariableScope.Global)) {
|
|
238
283
|
addMemberExpr(path, search);
|
|
239
284
|
}
|
|
240
285
|
else if (t.isIdentifier(node.property) && node.property.name === "$") {
|
|
241
286
|
addExternalIValue(path, search);
|
|
242
287
|
}
|
|
288
|
+
else {
|
|
289
|
+
checkExpression(path.get("object"), search);
|
|
290
|
+
checkOrIgnoreExpression(path.get("property"), search);
|
|
291
|
+
}
|
|
243
292
|
break;
|
|
244
293
|
}
|
|
245
294
|
case "BinaryExpression": {
|
|
246
295
|
const path = nodePath;
|
|
247
|
-
|
|
296
|
+
checkOrIgnoreExpression(path.get("left"), search);
|
|
248
297
|
checkExpression(path.get("right"), search);
|
|
249
298
|
break;
|
|
250
299
|
}
|
|
@@ -263,7 +312,7 @@ function checkExpression(nodePath, search) {
|
|
|
263
312
|
}
|
|
264
313
|
case "NewExpression": {
|
|
265
314
|
const path = nodePath;
|
|
266
|
-
|
|
315
|
+
checkOrIgnoreExpression(path.get("callee"), search);
|
|
267
316
|
checkAllUnknown(path.get("arguments"), search);
|
|
268
317
|
break;
|
|
269
318
|
}
|
|
@@ -272,11 +321,6 @@ function checkExpression(nodePath, search) {
|
|
|
272
321
|
checkAllExpressions(path.get("expressions"), search);
|
|
273
322
|
break;
|
|
274
323
|
}
|
|
275
|
-
case "ParenthesizedExpression": {
|
|
276
|
-
const path = nodePath;
|
|
277
|
-
checkExpression(path.get("expression"), search);
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
324
|
case "UnaryExpression": {
|
|
281
325
|
const path = nodePath;
|
|
282
326
|
checkExpression(path.get("argument"), search);
|
|
@@ -284,7 +328,10 @@ function checkExpression(nodePath, search) {
|
|
|
284
328
|
}
|
|
285
329
|
case "UpdateExpression": {
|
|
286
330
|
const path = nodePath;
|
|
287
|
-
|
|
331
|
+
const arg = path.node.argument;
|
|
332
|
+
if (t.isLVal(arg)) {
|
|
333
|
+
meshLValue(path.get("argument"), search.external);
|
|
334
|
+
}
|
|
288
335
|
break;
|
|
289
336
|
}
|
|
290
337
|
case "YieldExpression": {
|
|
@@ -297,27 +344,6 @@ function checkExpression(nodePath, search) {
|
|
|
297
344
|
checkExpression(path.get("argument"), search);
|
|
298
345
|
break;
|
|
299
346
|
}
|
|
300
|
-
case "TypeCastExpression": {
|
|
301
|
-
const path = nodePath;
|
|
302
|
-
checkExpression(path.get("expression"), search);
|
|
303
|
-
break;
|
|
304
|
-
}
|
|
305
|
-
case "BindExpression": {
|
|
306
|
-
const path = nodePath;
|
|
307
|
-
checkExpression(path.get("callee"), search);
|
|
308
|
-
checkExpression(path.get("object"), search);
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
case "PipelineTopicExpression": {
|
|
312
|
-
const path = nodePath;
|
|
313
|
-
checkExpression(path.get("expression"), search);
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
case "PipelineBareFunction": {
|
|
317
|
-
const path = nodePath;
|
|
318
|
-
checkExpression(path.get("callee"), search);
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
347
|
case "TSInstantiationExpression": {
|
|
322
348
|
const path = nodePath;
|
|
323
349
|
checkExpression(path.get("expression"), search);
|
|
@@ -345,12 +371,10 @@ function checkExpression(nodePath, search) {
|
|
|
345
371
|
if (t.isObjectProperty(prop)) {
|
|
346
372
|
const path = propPath;
|
|
347
373
|
const valuePath = path.get("value");
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
chekOrIgnoreExpression(valuePath, search);
|
|
374
|
+
if (path.node.computed) {
|
|
375
|
+
checkOrIgnoreExpression(path.get("key"), search);
|
|
353
376
|
}
|
|
377
|
+
checkOrIgnoreExpression(valuePath, search);
|
|
354
378
|
}
|
|
355
379
|
else if (t.isObjectMethod(prop)) {
|
|
356
380
|
checkFunction(propPath, search);
|
|
@@ -383,9 +407,6 @@ function checkStatements(paths, search) {
|
|
|
383
407
|
}
|
|
384
408
|
}
|
|
385
409
|
function ignoreLocals(val, search) {
|
|
386
|
-
if (t.isAssignmentPattern(val)) {
|
|
387
|
-
val = val.left;
|
|
388
|
-
}
|
|
389
410
|
if (t.isIdentifier(val)) {
|
|
390
411
|
search.stack.set(val.name, 1 /* VariableState.Ignored */);
|
|
391
412
|
}
|
|
@@ -397,18 +418,23 @@ function ignoreLocals(val, search) {
|
|
|
397
418
|
else if (t.isRestElement(prop) && t.isIdentifier(prop.argument)) {
|
|
398
419
|
search.stack.set(prop.argument.name, 1 /* VariableState.Ignored */);
|
|
399
420
|
}
|
|
421
|
+
else if (t.isObjectProperty(prop) && t.isAssignmentPattern(prop.value)) {
|
|
422
|
+
ignoreLocals(prop.value.left, search);
|
|
423
|
+
}
|
|
400
424
|
}
|
|
401
425
|
}
|
|
402
426
|
else if (t.isArrayPattern(val)) {
|
|
403
427
|
for (const element of val.elements) {
|
|
404
|
-
if (element) {
|
|
428
|
+
if (element && !t.isVoidPattern(element)) {
|
|
405
429
|
ignoreLocals(element, search);
|
|
406
430
|
}
|
|
407
431
|
}
|
|
408
432
|
}
|
|
409
433
|
else if (t.isVariableDeclaration(val)) {
|
|
410
434
|
for (const declarator of val.declarations) {
|
|
411
|
-
|
|
435
|
+
if (!t.isVoidPattern(declarator.id)) {
|
|
436
|
+
ignoreLocals(declarator.id, search);
|
|
437
|
+
}
|
|
412
438
|
}
|
|
413
439
|
}
|
|
414
440
|
}
|
|
@@ -507,12 +533,16 @@ function checkStatement(path, search) {
|
|
|
507
533
|
checkExpression(path.get("argument"), search);
|
|
508
534
|
break;
|
|
509
535
|
case "TryStatement":
|
|
536
|
+
const handlerPath = path.get("handler");
|
|
510
537
|
checkStatement(path.get("block"), search);
|
|
538
|
+
if (handlerPath.node) {
|
|
539
|
+
checkStatement(handlerPath.get("body"), search);
|
|
540
|
+
}
|
|
541
|
+
checkStatement(path.get("finalizer"), search);
|
|
511
542
|
break;
|
|
512
543
|
case "VariableDeclaration": {
|
|
513
544
|
const _path = path;
|
|
514
545
|
for (const declaration of _path.get("declarations")) {
|
|
515
|
-
const expr = declaration.node.init;
|
|
516
546
|
ignoreLocals(declaration.node.id, search);
|
|
517
547
|
checkExpression(declaration.get("init"), search);
|
|
518
548
|
}
|
|
@@ -526,22 +556,13 @@ function checkStatement(path, search) {
|
|
|
526
556
|
search.stack.pop();
|
|
527
557
|
break;
|
|
528
558
|
}
|
|
529
|
-
case "WithStatement": {
|
|
530
|
-
const _path = path;
|
|
531
|
-
checkExpression(_path.get("object"), search);
|
|
532
|
-
search.stack.push();
|
|
533
|
-
checkStatement(_path.get("body"), search);
|
|
534
|
-
search.stack.pop();
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
case "ExportNamedDeclaration": {
|
|
538
|
-
checkStatement(path.get("declaration"), search);
|
|
539
|
-
break;
|
|
540
|
-
}
|
|
541
559
|
}
|
|
542
560
|
}
|
|
543
561
|
function checkFunction(path, search) {
|
|
544
562
|
const node = path.node;
|
|
563
|
+
for (const param of node.params) {
|
|
564
|
+
ignoreLocals(param, search);
|
|
565
|
+
}
|
|
545
566
|
if (t.isExpression(node.body)) {
|
|
546
567
|
checkExpression(path.get("body"), search);
|
|
547
568
|
}
|
package/lib-node/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = default_1;
|
|
4
|
-
const
|
|
4
|
+
const transformer_js_1 = require("./transformer.js");
|
|
5
5
|
function default_1() {
|
|
6
6
|
return {
|
|
7
7
|
name: "Vasille",
|
|
8
8
|
visitor: {
|
|
9
9
|
Program(path, params) {
|
|
10
|
-
(0,
|
|
10
|
+
(0, transformer_js_1.trProgram)(path, params.opts.devMode !== false);
|
|
11
11
|
},
|
|
12
12
|
},
|
|
13
13
|
};
|
package/lib-node/internal.js
CHANGED
|
@@ -15,29 +15,54 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
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
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ctx = exports.StackedStates = void 0;
|
|
36
|
+
exports.ctx = exports.StackedStates = exports.VariableScope = void 0;
|
|
27
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 = {}));
|
|
28
44
|
class StackedStates {
|
|
29
45
|
constructor() {
|
|
30
46
|
this.maps = [];
|
|
47
|
+
this.localIndex = -1;
|
|
31
48
|
this.push();
|
|
32
49
|
}
|
|
50
|
+
fixLocalIndex() {
|
|
51
|
+
this.localIndex = this.maps.length;
|
|
52
|
+
}
|
|
53
|
+
resetLocalIndex() {
|
|
54
|
+
this.localIndex = -1;
|
|
55
|
+
}
|
|
33
56
|
push() {
|
|
34
57
|
this.maps.push(new Map());
|
|
35
58
|
}
|
|
36
59
|
pop() {
|
|
37
60
|
this.maps.pop();
|
|
38
61
|
}
|
|
39
|
-
get(name) {
|
|
40
|
-
for (let i = this.
|
|
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--) {
|
|
41
66
|
if (this.maps[i].has(name)) {
|
|
42
67
|
return this.maps[i].get(name);
|
|
43
68
|
}
|
package/lib-node/jsx-detect.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
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
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.exprHasJsx = exprHasJsx;
|
|
27
37
|
exports.statementHasJsx = statementHasJsx;
|
|
@@ -37,15 +47,6 @@ function exprHasJsx(node) {
|
|
|
37
47
|
if (t.isLogicalExpression(node)) {
|
|
38
48
|
return exprHasJsx(node.left) || exprHasJsx(node.right);
|
|
39
49
|
}
|
|
40
|
-
if (t.isSequenceExpression(node)) {
|
|
41
|
-
return node.expressions.some(item => exprHasJsx(item));
|
|
42
|
-
}
|
|
43
|
-
if (t.isParenthesizedExpression(node)) {
|
|
44
|
-
return exprHasJsx(node.expression);
|
|
45
|
-
}
|
|
46
|
-
if (t.isDoExpression(node)) {
|
|
47
|
-
return bodyHasJsx(node.body);
|
|
48
|
-
}
|
|
49
50
|
return t.isJSXElement(node) || t.isJSXFragment(node);
|
|
50
51
|
}
|
|
51
52
|
function statementHasJsx(statement) {
|
|
@@ -78,6 +79,17 @@ function statementHasJsx(statement) {
|
|
|
78
79
|
if (t.isReturnStatement(statement)) {
|
|
79
80
|
return !!statement.argument && exprHasJsx(statement.argument);
|
|
80
81
|
}
|
|
82
|
+
if (t.isTryStatement(statement)) {
|
|
83
|
+
return (statementHasJsx(statement.block) ||
|
|
84
|
+
(!!statement.handler && statementHasJsx(statement.handler.body)) ||
|
|
85
|
+
(!!statement.finalizer && statementHasJsx(statement.finalizer)));
|
|
86
|
+
}
|
|
87
|
+
if (t.isIfStatement(statement)) {
|
|
88
|
+
return statementHasJsx(statement.consequent) || (!!statement.alternate && statementHasJsx(statement.alternate));
|
|
89
|
+
}
|
|
90
|
+
if (t.isForStatement(statement)) {
|
|
91
|
+
return statementHasJsx(statement.body);
|
|
92
|
+
}
|
|
81
93
|
return false;
|
|
82
94
|
}
|
|
83
95
|
function bodyHasJsx(node) {
|