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/expression.js
CHANGED
|
@@ -35,9 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.encodeName = encodeName;
|
|
37
37
|
exports.idIsIValue = idIsIValue;
|
|
38
|
-
exports.idIsLocal = idIsLocal;
|
|
39
38
|
exports.memberIsIValue = memberIsIValue;
|
|
40
|
-
exports.
|
|
39
|
+
exports.exprIsSure = exprIsSure;
|
|
41
40
|
exports.checkNode = checkNode;
|
|
42
41
|
exports.checkOrIgnoreAllExpressions = checkOrIgnoreAllExpressions;
|
|
43
42
|
exports.checkAllExpressions = checkAllExpressions;
|
|
@@ -48,9 +47,9 @@ exports.checkStatements = checkStatements;
|
|
|
48
47
|
exports.checkStatement = checkStatement;
|
|
49
48
|
exports.checkFunction = checkFunction;
|
|
50
49
|
const t = __importStar(require("@babel/types"));
|
|
51
|
-
const bridge_1 = require("./bridge");
|
|
52
50
|
const call_js_1 = require("./call.js");
|
|
53
|
-
const
|
|
51
|
+
const lib_1 = require("./lib");
|
|
52
|
+
const mesh_1 = require("./mesh");
|
|
54
53
|
const router_1 = require("./router");
|
|
55
54
|
const utils_1 = require("./utils");
|
|
56
55
|
function encodeName(name) {
|
|
@@ -62,28 +61,27 @@ function insertName(name, search) {
|
|
|
62
61
|
return id;
|
|
63
62
|
}
|
|
64
63
|
function addIdentifier(path, search) {
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const name = unprefixedName(path.node.name);
|
|
65
|
+
if (!search.found.has(name)) {
|
|
66
|
+
search.found.set(name, path.node);
|
|
67
67
|
}
|
|
68
|
-
path.replaceWith(insertName(
|
|
68
|
+
path.replaceWith(insertName(name, search));
|
|
69
|
+
}
|
|
70
|
+
function unprefixedName(name) {
|
|
71
|
+
return name[0] === "$" ? name.slice(1) : name;
|
|
69
72
|
}
|
|
70
73
|
function extractMemberName(path, search) {
|
|
71
74
|
const names = [];
|
|
72
75
|
let it = path.node;
|
|
73
76
|
while (t.isMemberExpression(it)) {
|
|
74
|
-
|
|
75
|
-
if (name === "$" && it !== path.node) {
|
|
76
|
-
throw path.buildCodeFrameError("Vasille: The reactive/observable value is nested");
|
|
77
|
-
}
|
|
77
|
+
names.push((0, utils_1.stringify)(it.property));
|
|
78
78
|
it = it.object;
|
|
79
|
-
names.push(name);
|
|
80
79
|
}
|
|
81
80
|
names.push((0, utils_1.stringify)(it));
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
throw path.buildCodeFrameError("Vasille: This node cannot be processed, the root of expression is a local variable");
|
|
81
|
+
if (names.filter(name => name.startsWith("$")).length > 1) {
|
|
82
|
+
(0, lib_1.err)(lib_1.Errors.RulesOfVasille, path, "The reactive/observable value is nested", search.external, null);
|
|
85
83
|
}
|
|
86
|
-
return names.reverse().join("_");
|
|
84
|
+
return names.reverse().map(unprefixedName).join("_");
|
|
87
85
|
}
|
|
88
86
|
function addMemberExpr(path, search) {
|
|
89
87
|
const name = extractMemberName(path, search);
|
|
@@ -93,74 +91,64 @@ function addMemberExpr(path, search) {
|
|
|
93
91
|
}
|
|
94
92
|
path.replaceWith(insertName(name, search));
|
|
95
93
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
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("$")));
|
|
94
|
+
function meshIdentifier(path) {
|
|
95
|
+
if (idIsIValue(path)) {
|
|
96
|
+
path.replaceWith(t.memberExpression(path.node, t.identifier("V")));
|
|
106
97
|
}
|
|
107
98
|
}
|
|
108
|
-
function idIsIValue(path
|
|
99
|
+
function idIsIValue(path) {
|
|
109
100
|
const node = path.node;
|
|
110
|
-
return (
|
|
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;
|
|
101
|
+
return node.name.startsWith("$") && (!t.isMemberExpression(path.parent) || path.parent.object === node);
|
|
115
102
|
}
|
|
116
|
-
function memberIsIValue(node
|
|
117
|
-
return ((t.isIdentifier(node.
|
|
118
|
-
(
|
|
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("$$")))));
|
|
103
|
+
function memberIsIValue(node) {
|
|
104
|
+
return ((t.isIdentifier(node.property) && node.property.name.startsWith("$")) ||
|
|
105
|
+
(t.isStringLiteral(node.property) && node.property.value.startsWith("$")));
|
|
130
106
|
}
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
107
|
+
function exprIsSure(path, internal) {
|
|
108
|
+
if (path.isMemberExpression() &&
|
|
109
|
+
path.node.computed &&
|
|
110
|
+
(!t.isStringLiteral(path.node.property) || /^\d+$/.test(path.node.property.value))) {
|
|
111
|
+
return false;
|
|
135
112
|
}
|
|
136
|
-
if (
|
|
137
|
-
return
|
|
138
|
-
(t.isStringLiteral(node.property) && node.property.value.startsWith("$$")));
|
|
113
|
+
if (!path.isMemberExpression() || !(0, utils_1.stringify)(path.node.property).startsWith("$")) {
|
|
114
|
+
return true;
|
|
139
115
|
}
|
|
116
|
+
let it = path.node;
|
|
117
|
+
let names = [];
|
|
118
|
+
while (t.isMemberExpression(it) || t.isOptionalMemberExpression(it)) {
|
|
119
|
+
names.push((0, utils_1.stringify)(it.property));
|
|
120
|
+
it = it.object;
|
|
121
|
+
}
|
|
122
|
+
const reactivityData = t.isIdentifier(it) && internal.stack.get(it.name);
|
|
123
|
+
const propPath = names.reverse().join(".");
|
|
124
|
+
return (reactivityData && reactivityData[propPath]) || t.isMemberExpression(path.parent);
|
|
140
125
|
}
|
|
141
|
-
function meshMember(path
|
|
142
|
-
if (memberIsIValue(path.node
|
|
143
|
-
path.replaceWith(t.memberExpression(path.node, t.identifier("
|
|
126
|
+
function meshMember(path) {
|
|
127
|
+
if (memberIsIValue(path.node)) {
|
|
128
|
+
path.replaceWith(t.memberExpression(path.node, t.identifier("V"), false, true));
|
|
144
129
|
}
|
|
145
130
|
}
|
|
146
131
|
function meshLValue(path, internal) {
|
|
147
|
-
const node = path.node;
|
|
148
132
|
/* istanbul ignore else */
|
|
149
|
-
if (
|
|
150
|
-
meshIdentifier(path
|
|
133
|
+
if (path.isIdentifier()) {
|
|
134
|
+
meshIdentifier(path);
|
|
151
135
|
}
|
|
152
|
-
else if (
|
|
153
|
-
|
|
136
|
+
else if (path.isMemberExpression() || path.isOptionalMemberExpression()) {
|
|
137
|
+
const object = path.get("object");
|
|
138
|
+
meshMember(path);
|
|
139
|
+
if (object.isLVal()) {
|
|
140
|
+
meshLValue(object, internal);
|
|
141
|
+
}
|
|
154
142
|
}
|
|
155
|
-
else if (
|
|
143
|
+
else if (path.isArrayPattern()) {
|
|
156
144
|
for (const item of path.get("elements")) {
|
|
157
145
|
/* istanbul ignore else */
|
|
158
|
-
if (
|
|
146
|
+
if (item.isOptionalMemberExpression() || item.isLVal()) {
|
|
159
147
|
meshLValue(item, internal);
|
|
160
148
|
}
|
|
161
149
|
}
|
|
162
150
|
}
|
|
163
|
-
else if (
|
|
151
|
+
else if (path.isRestElement()) {
|
|
164
152
|
meshLValue(path.get("argument"), internal);
|
|
165
153
|
}
|
|
166
154
|
}
|
|
@@ -172,36 +160,35 @@ function checkNode(path, internal) {
|
|
|
172
160
|
inserted: new Set(),
|
|
173
161
|
stack: internal.stack,
|
|
174
162
|
};
|
|
175
|
-
if (
|
|
176
|
-
if (idIsIValue(path
|
|
163
|
+
if (path.isIdentifier()) {
|
|
164
|
+
if (idIsIValue(path)) {
|
|
177
165
|
search.self = path.node;
|
|
178
166
|
}
|
|
179
167
|
}
|
|
180
|
-
if (
|
|
181
|
-
if (memberIsIValue(path.node
|
|
168
|
+
if (path.isMemberExpression()) {
|
|
169
|
+
if (memberIsIValue(path.node)) {
|
|
182
170
|
search.self = path.node;
|
|
183
171
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
172
|
+
}
|
|
173
|
+
if (path.isExpression() && (0, call_js_1.calls)(path, ["ref"], internal)) {
|
|
174
|
+
(0, mesh_1.meshAllUnknown)(path.get("arguments"), internal);
|
|
175
|
+
search.self = path.node;
|
|
187
176
|
}
|
|
188
177
|
if (search.self) {
|
|
189
178
|
return search;
|
|
190
179
|
}
|
|
191
|
-
internal.stack.fixLocalIndex();
|
|
192
180
|
internal.stack.push();
|
|
193
181
|
/* istanbul ignore else */
|
|
194
|
-
if (
|
|
182
|
+
if (path.isExpression()) {
|
|
195
183
|
checkExpression(path, search);
|
|
196
184
|
}
|
|
197
185
|
internal.stack.pop();
|
|
198
|
-
internal.stack.resetLocalIndex();
|
|
199
186
|
return search;
|
|
200
187
|
}
|
|
201
188
|
function checkOrIgnoreAllExpressions(nodePaths, search) {
|
|
202
189
|
for (const path of nodePaths) {
|
|
203
190
|
/* istanbul ignore else */
|
|
204
|
-
if (
|
|
191
|
+
if (path.isExpression()) {
|
|
205
192
|
checkExpression(path, search);
|
|
206
193
|
}
|
|
207
194
|
}
|
|
@@ -214,21 +201,20 @@ function checkAllExpressions(nodePaths, search) {
|
|
|
214
201
|
function checkAllUnknown(paths, internal) {
|
|
215
202
|
for (const path of paths) {
|
|
216
203
|
/* istanbul ignore else */
|
|
217
|
-
if (
|
|
204
|
+
if (path.isSpreadElement()) {
|
|
218
205
|
checkExpression(path.get("argument"), internal);
|
|
219
206
|
}
|
|
220
|
-
else if (
|
|
207
|
+
else if (path.isExpression()) {
|
|
221
208
|
checkExpression(path, internal);
|
|
222
209
|
}
|
|
223
210
|
}
|
|
224
211
|
}
|
|
225
212
|
function checkOrIgnoreExpression(path, search) {
|
|
226
213
|
/* istanbul ignore else */
|
|
227
|
-
if (
|
|
214
|
+
if (path.isExpression()) {
|
|
228
215
|
checkExpression(path, search);
|
|
229
216
|
}
|
|
230
217
|
}
|
|
231
|
-
const REACTIVE_STATES = [2 /* VariableState.Reactive */, 4 /* VariableState.ReactivePointer */];
|
|
232
218
|
function checkExpression(nodePath, search) {
|
|
233
219
|
const expr = nodePath.node;
|
|
234
220
|
switch (expr && expr.type) {
|
|
@@ -245,9 +231,8 @@ function checkExpression(nodePath, search) {
|
|
|
245
231
|
}
|
|
246
232
|
case "Identifier": {
|
|
247
233
|
/* istanbul ignore else */
|
|
248
|
-
if (expr &&
|
|
249
|
-
if (idIsIValue(nodePath
|
|
250
|
-
!idIsLocal(nodePath, search.external)) {
|
|
234
|
+
if (expr && nodePath.isIdentifier()) {
|
|
235
|
+
if (idIsIValue(nodePath)) {
|
|
251
236
|
addIdentifier(nodePath, search);
|
|
252
237
|
}
|
|
253
238
|
}
|
|
@@ -260,23 +245,17 @@ function checkExpression(nodePath, search) {
|
|
|
260
245
|
}
|
|
261
246
|
case "CallExpression": {
|
|
262
247
|
const path = nodePath;
|
|
263
|
-
|
|
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)) {
|
|
248
|
+
if ((0, call_js_1.calls)(path, ["router"], search.external)) {
|
|
270
249
|
if (!search.external.stateOnly) {
|
|
271
250
|
(0, router_1.routerReplace)(path);
|
|
272
251
|
}
|
|
273
252
|
else {
|
|
274
|
-
|
|
253
|
+
(0, lib_1.err)(lib_1.Errors.IncompatibleContext, path, "The router is not available in stores", search.external, null);
|
|
275
254
|
}
|
|
276
255
|
}
|
|
277
256
|
else {
|
|
278
|
-
if ((0, call_js_1.calls)(path, call_js_1.
|
|
279
|
-
|
|
257
|
+
if ((0, call_js_1.calls)(path, call_js_1.hintFunctions, search.external)) {
|
|
258
|
+
(0, lib_1.err)(lib_1.Errors.IncompatibleContext, path, "Usage of hints is restricted here", search.external, null);
|
|
280
259
|
}
|
|
281
260
|
checkOrIgnoreExpression(path.get("callee"), search);
|
|
282
261
|
checkAllUnknown(path.get("arguments"), search);
|
|
@@ -291,20 +270,30 @@ function checkExpression(nodePath, search) {
|
|
|
291
270
|
}
|
|
292
271
|
case "AssignmentExpression": {
|
|
293
272
|
const path = nodePath;
|
|
294
|
-
|
|
295
|
-
|
|
273
|
+
const left = path.get("left");
|
|
274
|
+
const right = path.get("right");
|
|
275
|
+
if (left.isMemberExpression() && !exprIsSure(left, search.external)) {
|
|
276
|
+
const property = left.node.property;
|
|
277
|
+
(0, mesh_1.meshExpression)(left.get("object"), search.external);
|
|
278
|
+
checkExpression(right, search);
|
|
279
|
+
/* istanbul ignore else */
|
|
280
|
+
if (!t.isPrivateName(property)) {
|
|
281
|
+
path.replaceWith(search.external.set(left.node.object, property, right.node));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
meshLValue(left, search.external);
|
|
286
|
+
checkExpression(right, search);
|
|
287
|
+
}
|
|
296
288
|
break;
|
|
297
289
|
}
|
|
298
290
|
case "MemberExpression":
|
|
299
291
|
case "OptionalMemberExpression": {
|
|
300
292
|
const path = nodePath;
|
|
301
293
|
const node = path.node;
|
|
302
|
-
if (memberIsIValue(node
|
|
294
|
+
if (memberIsIValue(node)) {
|
|
303
295
|
addMemberExpr(path, search);
|
|
304
296
|
}
|
|
305
|
-
else if (t.isIdentifier(node.property) && node.property.name === "$") {
|
|
306
|
-
addExternalIValue(path, search);
|
|
307
|
-
}
|
|
308
297
|
else {
|
|
309
298
|
checkExpression(path.get("object"), search);
|
|
310
299
|
checkOrIgnoreExpression(path.get("property"), search);
|
|
@@ -415,10 +404,12 @@ function checkExpression(nodePath, search) {
|
|
|
415
404
|
break;
|
|
416
405
|
}
|
|
417
406
|
case "JSXFragment": {
|
|
418
|
-
|
|
407
|
+
(0, lib_1.err)(lib_1.Errors.IncompatibleContext, nodePath, "JSX fragment is not allowed here", search.external, null);
|
|
408
|
+
break;
|
|
419
409
|
}
|
|
420
410
|
case "JSXElement": {
|
|
421
|
-
|
|
411
|
+
(0, lib_1.err)(lib_1.Errors.IncompatibleContext, nodePath, "JSX element is not allowed here", search.external, null);
|
|
412
|
+
break;
|
|
422
413
|
}
|
|
423
414
|
}
|
|
424
415
|
}
|
|
@@ -427,40 +418,15 @@ function checkStatements(paths, search) {
|
|
|
427
418
|
checkStatement(path, search);
|
|
428
419
|
}
|
|
429
420
|
}
|
|
430
|
-
function ignoreLocals(
|
|
431
|
-
|
|
432
|
-
if (t.
|
|
433
|
-
|
|
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
|
-
}
|
|
421
|
+
function ignoreLocals(path, search) {
|
|
422
|
+
const val = path.node;
|
|
423
|
+
if (t.isVariableDeclaration(val)) {
|
|
424
|
+
for (const declarator of path.get("declarations")) {
|
|
425
|
+
(0, mesh_1.ignoreParams)(declarator.get("id"), search.external, ["id", "array"]);
|
|
455
426
|
}
|
|
456
427
|
}
|
|
457
|
-
else
|
|
458
|
-
|
|
459
|
-
/* istanbul ignore else */
|
|
460
|
-
if (!t.isVoidPattern(declarator.id)) {
|
|
461
|
-
ignoreLocals(declarator.id, search);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
428
|
+
else {
|
|
429
|
+
(0, mesh_1.ignoreParams)(path, search.external, ["id", "array"]);
|
|
464
430
|
}
|
|
465
431
|
}
|
|
466
432
|
function checkStatement(path, search) {
|
|
@@ -487,7 +453,7 @@ function checkStatement(path, search) {
|
|
|
487
453
|
break;
|
|
488
454
|
case "ForInStatement": {
|
|
489
455
|
const _path = path;
|
|
490
|
-
ignoreLocals(_path.
|
|
456
|
+
ignoreLocals(_path.get("left"), search);
|
|
491
457
|
checkExpression(_path.get("right"), search);
|
|
492
458
|
checkStatement(_path.get("body"), search);
|
|
493
459
|
break;
|
|
@@ -570,7 +536,7 @@ function checkStatement(path, search) {
|
|
|
570
536
|
case "VariableDeclaration": {
|
|
571
537
|
const _path = path;
|
|
572
538
|
for (const declaration of _path.get("declarations")) {
|
|
573
|
-
ignoreLocals(declaration.
|
|
539
|
+
ignoreLocals(declaration.get("id"), search);
|
|
574
540
|
checkExpression(declaration.get("init"), search);
|
|
575
541
|
}
|
|
576
542
|
break;
|
|
@@ -587,9 +553,21 @@ function checkStatement(path, search) {
|
|
|
587
553
|
}
|
|
588
554
|
function checkFunction(path, search) {
|
|
589
555
|
const node = path.node;
|
|
590
|
-
for (const param of
|
|
556
|
+
for (const param of path.get("params")) {
|
|
591
557
|
ignoreLocals(param, search);
|
|
592
558
|
}
|
|
559
|
+
if (path.isFunctionDeclaration() && path.node.id) {
|
|
560
|
+
const idPath = path.get("id");
|
|
561
|
+
/* istanbul ignore else */
|
|
562
|
+
if (idPath.isIdentifier()) {
|
|
563
|
+
search.stack.set(idPath.node.name, {});
|
|
564
|
+
(0, lib_1.checkNonReactiveName)(idPath, search.external);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (t.isFunctionExpression(node) && node.id) {
|
|
568
|
+
search.stack.push();
|
|
569
|
+
search.stack.set(node.id.name, {});
|
|
570
|
+
}
|
|
593
571
|
if (t.isExpression(node.body)) {
|
|
594
572
|
checkExpression(path.get("body"), search);
|
|
595
573
|
}
|
|
@@ -597,4 +575,7 @@ function checkFunction(path, search) {
|
|
|
597
575
|
const bodyPath = path.get("body");
|
|
598
576
|
checkStatement(bodyPath, search);
|
|
599
577
|
}
|
|
578
|
+
if (t.isFunctionExpression(node) && node.id) {
|
|
579
|
+
search.stack.pop();
|
|
580
|
+
}
|
|
600
581
|
}
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,10 @@ function default_1() {
|
|
|
7
7
|
name: "Vasille",
|
|
8
8
|
visitor: {
|
|
9
9
|
Program(path, params) {
|
|
10
|
-
(0, transformer_js_1.
|
|
10
|
+
(0, transformer_js_1.transformProgram)(path, params.file.opts.filename, {
|
|
11
|
+
devMode: params.opts.devMode !== false,
|
|
12
|
+
strictFolders: params.opts.strictFolders !== false,
|
|
13
|
+
});
|
|
11
14
|
},
|
|
12
15
|
},
|
|
13
16
|
};
|
package/lib/internal.js
CHANGED
|
@@ -33,36 +33,21 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ctx = exports.StackedStates =
|
|
36
|
+
exports.ctx = exports.StackedStates = void 0;
|
|
37
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
38
|
class StackedStates {
|
|
39
|
+
maps = [];
|
|
45
40
|
constructor() {
|
|
46
|
-
this.maps = [];
|
|
47
|
-
this.localIndex = -1;
|
|
48
41
|
this.push();
|
|
49
42
|
}
|
|
50
|
-
fixLocalIndex() {
|
|
51
|
-
this.localIndex = this.maps.length;
|
|
52
|
-
}
|
|
53
|
-
resetLocalIndex() {
|
|
54
|
-
this.localIndex = -1;
|
|
55
|
-
}
|
|
56
43
|
push() {
|
|
57
44
|
this.maps.push(new Map());
|
|
58
45
|
}
|
|
59
46
|
pop() {
|
|
60
47
|
this.maps.pop();
|
|
61
48
|
}
|
|
62
|
-
get(name
|
|
63
|
-
for (let i =
|
|
64
|
-
? this.maps.length
|
|
65
|
-
: Math.min(this.maps.length, this.localIndex)) - 1; i >= (this.localIndex === -1 || scope !== VariableScope.Local ? 0 : this.localIndex); i--) {
|
|
49
|
+
get(name) {
|
|
50
|
+
for (let i = this.maps.length - 1; i >= 0; i--) {
|
|
66
51
|
if (this.maps[i].has(name)) {
|
|
67
52
|
return this.maps[i].get(name);
|
|
68
53
|
}
|
package/lib/jsx-detect.js
CHANGED
|
@@ -34,67 +34,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.exprHasJsx = exprHasJsx;
|
|
37
|
-
exports.statementHasJsx = statementHasJsx;
|
|
38
37
|
exports.bodyHasJsx = bodyHasJsx;
|
|
39
38
|
const t = __importStar(require("@babel/types"));
|
|
40
39
|
function exprHasJsx(node) {
|
|
41
|
-
if (t.isBinaryExpression(node)) {
|
|
42
|
-
return (t.isExpression(node.left) && exprHasJsx(node.left)) || exprHasJsx(node.right);
|
|
43
|
-
}
|
|
44
|
-
if (t.isConditionalExpression(node)) {
|
|
45
|
-
return exprHasJsx(node.consequent) || exprHasJsx(node.alternate);
|
|
46
|
-
}
|
|
47
|
-
if (t.isLogicalExpression(node)) {
|
|
48
|
-
return exprHasJsx(node.left) || exprHasJsx(node.right);
|
|
49
|
-
}
|
|
50
40
|
return t.isJSXElement(node) || t.isJSXFragment(node);
|
|
51
41
|
}
|
|
52
|
-
function statementHasJsx(statement) {
|
|
53
|
-
if (t.isExpressionStatement(statement)) {
|
|
54
|
-
return exprHasJsx(statement.expression);
|
|
55
|
-
}
|
|
56
|
-
if (t.isBlockStatement(statement)) {
|
|
57
|
-
return bodyHasJsx(statement);
|
|
58
|
-
}
|
|
59
|
-
if (t.isDoWhileStatement(statement)) {
|
|
60
|
-
return statementHasJsx(statement.body);
|
|
61
|
-
}
|
|
62
|
-
if (t.isForInStatement(statement)) {
|
|
63
|
-
return statementHasJsx(statement.body);
|
|
64
|
-
}
|
|
65
|
-
if (t.isSwitchStatement(statement)) {
|
|
66
|
-
return statement.cases.some(_case => {
|
|
67
|
-
return _case.consequent.some(statementHasJsx);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (t.isWhileStatement(statement)) {
|
|
71
|
-
return statementHasJsx(statement.body);
|
|
72
|
-
}
|
|
73
|
-
if (t.isForOfStatement(statement)) {
|
|
74
|
-
return statementHasJsx(statement.body);
|
|
75
|
-
}
|
|
76
|
-
if (t.isLabeledStatement(statement)) {
|
|
77
|
-
return statementHasJsx(statement.body);
|
|
78
|
-
}
|
|
79
|
-
if (t.isReturnStatement(statement)) {
|
|
80
|
-
return !!statement.argument && exprHasJsx(statement.argument);
|
|
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
|
-
}
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
42
|
function bodyHasJsx(node) {
|
|
96
43
|
if (t.isExpression(node)) {
|
|
97
44
|
return exprHasJsx(node);
|
|
98
45
|
}
|
|
99
|
-
return node.body.some(
|
|
46
|
+
return node.body.some(statement => {
|
|
47
|
+
return t.isExpressionStatement(statement) && exprHasJsx(statement.expression);
|
|
48
|
+
});
|
|
100
49
|
}
|