babel-plugin-vasille 0.99.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.
@@ -0,0 +1,552 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.encodeName = encodeName;
27
+ exports.checkNode = checkNode;
28
+ exports.checkOrIgnoreAllExpressions = checkOrIgnoreAllExpressions;
29
+ exports.checkAllExpressions = checkAllExpressions;
30
+ exports.checkAllUnknown = checkAllUnknown;
31
+ exports.chekOrIgnoreExpression = chekOrIgnoreExpression;
32
+ exports.checkExpression = checkExpression;
33
+ exports.checkStatements = checkStatements;
34
+ exports.checkStatement = checkStatement;
35
+ exports.checkFunction = checkFunction;
36
+ const t = __importStar(require("@babel/types"));
37
+ const internal_js_1 = require("./internal.js");
38
+ function encodeName(name) {
39
+ return t.identifier(`Vasille_${name}`);
40
+ }
41
+ function addIdentifier(path, search) {
42
+ if (!search.found.has(path.node.name)) {
43
+ search.found.set(path.node.name, path.node);
44
+ }
45
+ path.replaceWith(encodeName(path.node.name));
46
+ }
47
+ function stringify(node) {
48
+ if (t.isIdentifier(node)) {
49
+ return node.name;
50
+ }
51
+ if (t.isStringLiteral(node)) {
52
+ return node.value;
53
+ }
54
+ if (t.isPrivateName(node)) {
55
+ return node.id.name;
56
+ }
57
+ return "$";
58
+ }
59
+ function extractMemberName(path, search) {
60
+ const names = [];
61
+ let it = path.node;
62
+ while (t.isMemberExpression(it)) {
63
+ const name = stringify(it.property);
64
+ if (name === "$" && it !== path.node) {
65
+ throw path.buildCodeFrameError("Vasille: The reactive/observable value is nested");
66
+ }
67
+ it = it.object;
68
+ names.push();
69
+ }
70
+ names.push(stringify(it));
71
+ if (t.isIdentifier(it) && search.stack.get(it.name) === 1 /* VariableState.Ignored */) {
72
+ throw path.buildCodeFrameError("Vasille: This node cannot be processed, the root of expression is a local variable");
73
+ }
74
+ return names.reverse().join("_");
75
+ }
76
+ function addMemberExpr(path, search) {
77
+ const name = extractMemberName(path, search);
78
+ if (!search.found.has(name)) {
79
+ search.found.set(name, path.node);
80
+ }
81
+ path.replaceWith(encodeName(name));
82
+ }
83
+ function addExternalIValue(path, search) {
84
+ const name = extractMemberName(path, search);
85
+ if (!search.found.has(name)) {
86
+ search.found.set(name, path.node.object);
87
+ }
88
+ path.replaceWith(encodeName(name));
89
+ }
90
+ function meshIdentifier(path, internal) {
91
+ const state = internal.stack.get(path.node.name);
92
+ if (state === 2 /* VariableState.Reactive */ || state === 4 /* VariableState.ReactivePointer */) {
93
+ path.replaceWith(t.memberExpression(path.node, t.identifier("$")));
94
+ }
95
+ }
96
+ function meshMember(path, internal) {
97
+ if (t.isIdentifier(path.node.object) && internal.stack.get(path.node.object.name) === 3 /* VariableState.ReactiveObject */) {
98
+ path.replaceWith(t.memberExpression(path.node, t.identifier("$")));
99
+ }
100
+ }
101
+ function meshLValue(path, internal) {
102
+ if (t.isIdentifier(path.node)) {
103
+ meshIdentifier(path, internal);
104
+ }
105
+ else if (t.isMemberExpression(path.node) || t.isOptionalMemberExpression(path.node)) {
106
+ meshMember(path, internal);
107
+ }
108
+ else {
109
+ path.traverse({
110
+ Identifier(path) {
111
+ meshIdentifier(path, internal);
112
+ },
113
+ MemberExpression(path) {
114
+ meshMember(path, internal);
115
+ },
116
+ OptionalMemberExpression(path) {
117
+ meshMember(path, internal);
118
+ },
119
+ });
120
+ }
121
+ }
122
+ function checkNode(path, internal) {
123
+ const search = {
124
+ external: internal,
125
+ found: new Map(),
126
+ self: null,
127
+ stack: new internal_js_1.StackedStates(),
128
+ };
129
+ if (t.isIdentifier(path.node)) {
130
+ const state = internal.stack.get(path.node.name);
131
+ if (state === 2 /* VariableState.Reactive */ || state == 4 /* VariableState.ReactivePointer */) {
132
+ search.self = path.node;
133
+ }
134
+ }
135
+ if (t.isMemberExpression(path.node)) {
136
+ if (t.isIdentifier(path.node.object) &&
137
+ internal.stack.get(path.node.object.name) === 3 /* VariableState.ReactiveObject */) {
138
+ search.self = path.node;
139
+ }
140
+ if (t.isIdentifier(path.node.property) && path.node.property.name === "$") {
141
+ search.self = path.node.object;
142
+ }
143
+ }
144
+ if (search.self) {
145
+ return search;
146
+ }
147
+ if (t.isExpression(path.node)) {
148
+ checkExpression(path, search);
149
+ }
150
+ return search;
151
+ }
152
+ function checkOrIgnoreAllExpressions(nodePaths, search) {
153
+ for (const path of nodePaths) {
154
+ if (t.isExpression(path.node)) {
155
+ checkExpression(path, search);
156
+ }
157
+ }
158
+ }
159
+ function checkAllExpressions(nodePaths, search) {
160
+ for (const path of nodePaths) {
161
+ checkExpression(path, search);
162
+ }
163
+ }
164
+ function checkAllUnknown(paths, internal) {
165
+ for (const path of paths) {
166
+ if (t.isSpreadElement(path.node)) {
167
+ checkExpression(path.get("argument"), internal);
168
+ }
169
+ else if (t.isExpression(path.node)) {
170
+ checkExpression(path, internal);
171
+ }
172
+ }
173
+ }
174
+ function chekOrIgnoreExpression(path, search) {
175
+ if (t.isExpression(path.node)) {
176
+ checkExpression(path, search);
177
+ }
178
+ }
179
+ function checkExpression(nodePath, search) {
180
+ const expr = nodePath.node;
181
+ if (!expr) {
182
+ return;
183
+ }
184
+ switch (expr.type) {
185
+ case "TemplateLiteral": {
186
+ const path = nodePath;
187
+ checkOrIgnoreAllExpressions(path.get("expressions"), search);
188
+ break;
189
+ }
190
+ case "TaggedTemplateExpression": {
191
+ const path = nodePath;
192
+ checkExpression(path.get("quasi"), search);
193
+ break;
194
+ }
195
+ case "Identifier": {
196
+ if (search.stack.get(expr.name) !== 1 /* VariableState.Ignored */) {
197
+ if (search.external.stack.get(expr.name) === 2 /* VariableState.Reactive */) {
198
+ addIdentifier(nodePath, search);
199
+ }
200
+ }
201
+ break;
202
+ }
203
+ case "ArrayExpression": {
204
+ const path = nodePath;
205
+ checkAllUnknown(path.get("elements"), search);
206
+ break;
207
+ }
208
+ case "TupleExpression": {
209
+ const path = nodePath;
210
+ checkAllUnknown(path.get("elements"), search);
211
+ break;
212
+ }
213
+ case "CallExpression": {
214
+ const path = nodePath;
215
+ chekOrIgnoreExpression(path.get("callee"), search);
216
+ checkAllUnknown(path.get("arguments"), search);
217
+ break;
218
+ }
219
+ case "OptionalCallExpression": {
220
+ const path = nodePath;
221
+ checkExpression(path.get("callee"), search);
222
+ checkAllUnknown(path.get("arguments"), search);
223
+ break;
224
+ }
225
+ case "AssignmentExpression": {
226
+ const path = nodePath;
227
+ meshLValue(path.get("left"), search.external);
228
+ checkExpression(path.get("right"), search);
229
+ break;
230
+ }
231
+ case "MemberExpression":
232
+ case "OptionalMemberExpression": {
233
+ const path = nodePath;
234
+ const node = path.node;
235
+ checkExpression(path.get("object"), search);
236
+ chekOrIgnoreExpression(path.get("property"), search);
237
+ if (t.isIdentifier(node.object) && search.external.stack.get(node.object.name) === 3 /* VariableState.ReactiveObject */) {
238
+ addMemberExpr(path, search);
239
+ }
240
+ else if (t.isIdentifier(node.property) && node.property.name === "$") {
241
+ addExternalIValue(path, search);
242
+ }
243
+ break;
244
+ }
245
+ case "BinaryExpression": {
246
+ const path = nodePath;
247
+ chekOrIgnoreExpression(path.get("left"), search);
248
+ checkExpression(path.get("right"), search);
249
+ break;
250
+ }
251
+ case "ConditionalExpression": {
252
+ const path = nodePath;
253
+ checkExpression(path.get("test"), search);
254
+ checkExpression(path.get("consequent"), search);
255
+ checkExpression(path.get("alternate"), search);
256
+ break;
257
+ }
258
+ case "LogicalExpression": {
259
+ const path = nodePath;
260
+ checkExpression(path.get("left"), search);
261
+ checkExpression(path.get("right"), search);
262
+ break;
263
+ }
264
+ case "NewExpression": {
265
+ const path = nodePath;
266
+ chekOrIgnoreExpression(path.get("callee"), search);
267
+ checkAllUnknown(path.get("arguments"), search);
268
+ break;
269
+ }
270
+ case "SequenceExpression": {
271
+ const path = nodePath;
272
+ checkAllExpressions(path.get("expressions"), search);
273
+ break;
274
+ }
275
+ case "ParenthesizedExpression": {
276
+ const path = nodePath;
277
+ checkExpression(path.get("expression"), search);
278
+ break;
279
+ }
280
+ case "UnaryExpression": {
281
+ const path = nodePath;
282
+ checkExpression(path.get("argument"), search);
283
+ break;
284
+ }
285
+ case "UpdateExpression": {
286
+ const path = nodePath;
287
+ checkExpression(path.get("argument"), search);
288
+ break;
289
+ }
290
+ case "YieldExpression": {
291
+ const path = nodePath;
292
+ checkExpression(path.get("argument"), search);
293
+ break;
294
+ }
295
+ case "AwaitExpression": {
296
+ const path = nodePath;
297
+ checkExpression(path.get("argument"), search);
298
+ break;
299
+ }
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
+ case "TSInstantiationExpression": {
322
+ const path = nodePath;
323
+ checkExpression(path.get("expression"), search);
324
+ break;
325
+ }
326
+ case "TSAsExpression": {
327
+ const path = nodePath;
328
+ checkExpression(path.get("expression"), search);
329
+ break;
330
+ }
331
+ case "TSSatisfiesExpression": {
332
+ const path = nodePath;
333
+ checkExpression(path.get("expression"), search);
334
+ break;
335
+ }
336
+ case "TSTypeAssertion": {
337
+ const path = nodePath;
338
+ checkExpression(path.get("expression"), search);
339
+ break;
340
+ }
341
+ case "ObjectExpression": {
342
+ const path = nodePath;
343
+ for (const propPath of path.get("properties")) {
344
+ const prop = propPath.node;
345
+ if (t.isObjectProperty(prop)) {
346
+ const path = propPath;
347
+ const valuePath = path.get("value");
348
+ if (valuePath instanceof Array) {
349
+ checkAllExpressions(valuePath, search);
350
+ }
351
+ else {
352
+ chekOrIgnoreExpression(valuePath, search);
353
+ }
354
+ }
355
+ else if (t.isObjectMethod(prop)) {
356
+ checkFunction(propPath, search);
357
+ }
358
+ else {
359
+ checkAllUnknown([propPath], search);
360
+ }
361
+ }
362
+ break;
363
+ }
364
+ case "FunctionExpression": {
365
+ checkFunction(nodePath, search);
366
+ break;
367
+ }
368
+ case "ArrowFunctionExpression": {
369
+ checkFunction(nodePath, search);
370
+ break;
371
+ }
372
+ case "JSXFragment": {
373
+ throw nodePath.buildCodeFrameError("Vasille: JSX fragment is not allowed here");
374
+ }
375
+ case "JSXElement": {
376
+ throw nodePath.buildCodeFrameError("Vasille: JSX element is not allowed here");
377
+ }
378
+ }
379
+ }
380
+ function checkStatements(paths, search) {
381
+ for (const path of paths) {
382
+ checkStatement(path, search);
383
+ }
384
+ }
385
+ function ignoreLocals(val, search) {
386
+ if (t.isAssignmentPattern(val)) {
387
+ val = val.left;
388
+ }
389
+ if (t.isIdentifier(val)) {
390
+ search.stack.set(val.name, 1 /* VariableState.Ignored */);
391
+ }
392
+ else if (t.isObjectPattern(val)) {
393
+ for (const prop of val.properties) {
394
+ if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
395
+ search.stack.set(prop.value.name, 1 /* VariableState.Ignored */);
396
+ }
397
+ else if (t.isRestElement(prop) && t.isIdentifier(prop.argument)) {
398
+ search.stack.set(prop.argument.name, 1 /* VariableState.Ignored */);
399
+ }
400
+ }
401
+ }
402
+ else if (t.isArrayPattern(val)) {
403
+ for (const element of val.elements) {
404
+ if (element) {
405
+ ignoreLocals(element, search);
406
+ }
407
+ }
408
+ }
409
+ else if (t.isVariableDeclaration(val)) {
410
+ for (const declarator of val.declarations) {
411
+ ignoreLocals(declarator.id, search);
412
+ }
413
+ }
414
+ }
415
+ function checkStatement(path, search) {
416
+ const statement = path.node;
417
+ if (!statement) {
418
+ return;
419
+ }
420
+ switch (statement.type) {
421
+ case "BlockStatement":
422
+ search.stack.push();
423
+ checkStatements(path.get("body"), search);
424
+ search.stack.pop();
425
+ break;
426
+ case "DoWhileStatement": {
427
+ const _path = path;
428
+ checkExpression(_path.get("test"), search);
429
+ search.stack.push();
430
+ checkStatement(_path.get("body"), search);
431
+ search.stack.pop();
432
+ break;
433
+ }
434
+ case "ExpressionStatement":
435
+ checkExpression(path.get("expression"), search);
436
+ break;
437
+ case "ForInStatement": {
438
+ const _path = path;
439
+ ignoreLocals(_path.node.left, search);
440
+ checkExpression(_path.get("right"), search);
441
+ checkStatement(_path.get("body"), search);
442
+ break;
443
+ }
444
+ case "ForOfStatement": {
445
+ const _path = path;
446
+ checkExpression(_path.get("right"), search);
447
+ search.stack.push();
448
+ checkStatement(_path.get("body"), search);
449
+ search.stack.pop();
450
+ break;
451
+ }
452
+ case "ForStatement": {
453
+ const _path = path;
454
+ const node = _path.node;
455
+ if (node.init) {
456
+ if (t.isExpression(node.init)) {
457
+ checkExpression(_path.get("init"), search);
458
+ }
459
+ else {
460
+ const variablePath = _path.get("init");
461
+ for (const declarationPath of variablePath.get("declarations")) {
462
+ checkExpression(declarationPath.get("init"), search);
463
+ }
464
+ }
465
+ }
466
+ checkExpression(_path.get("test"), search);
467
+ checkExpression(_path.get("update"), search);
468
+ search.stack.push();
469
+ checkStatement(_path.get("body"), search);
470
+ search.stack.pop();
471
+ break;
472
+ }
473
+ case "FunctionDeclaration":
474
+ checkFunction(path, search);
475
+ break;
476
+ case "IfStatement": {
477
+ const _path = path;
478
+ checkExpression(_path.get("test"), search);
479
+ search.stack.push();
480
+ checkStatement(_path.get("consequent"), search);
481
+ search.stack.pop();
482
+ search.stack.push();
483
+ checkStatement(_path.get("alternate"), search);
484
+ search.stack.pop();
485
+ break;
486
+ }
487
+ case "LabeledStatement":
488
+ search.stack.push();
489
+ checkStatement(path.get("body"), search);
490
+ search.stack.pop();
491
+ break;
492
+ case "ReturnStatement":
493
+ checkExpression(path.get("argument"), search);
494
+ break;
495
+ case "SwitchStatement": {
496
+ const _path = path;
497
+ checkExpression(_path.get("discriminant"), search);
498
+ search.stack.push();
499
+ for (const _case of _path.get("cases")) {
500
+ checkExpression(_case.get("test"), search);
501
+ checkStatements(_case.get("consequent"), search);
502
+ }
503
+ search.stack.pop();
504
+ break;
505
+ }
506
+ case "ThrowStatement":
507
+ checkExpression(path.get("argument"), search);
508
+ break;
509
+ case "TryStatement":
510
+ checkStatement(path.get("block"), search);
511
+ break;
512
+ case "VariableDeclaration": {
513
+ const _path = path;
514
+ for (const declaration of _path.get("declarations")) {
515
+ const expr = declaration.node.init;
516
+ ignoreLocals(declaration.node.id, search);
517
+ checkExpression(declaration.get("init"), search);
518
+ }
519
+ break;
520
+ }
521
+ case "WhileStatement": {
522
+ const _path = path;
523
+ checkExpression(_path.get("test"), search);
524
+ search.stack.push();
525
+ checkStatement(_path.get("body"), search);
526
+ search.stack.pop();
527
+ break;
528
+ }
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
+ }
542
+ }
543
+ function checkFunction(path, search) {
544
+ const node = path.node;
545
+ if (t.isExpression(node.body)) {
546
+ checkExpression(path.get("body"), search);
547
+ }
548
+ else {
549
+ const bodyPath = path.get("body");
550
+ checkStatement(bodyPath, search);
551
+ }
552
+ }
@@ -0,0 +1,14 @@
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.devMode !== false);
11
+ },
12
+ },
13
+ };
14
+ }
@@ -0,0 +1,52 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ctx = exports.StackedStates = void 0;
27
+ const t = __importStar(require("@babel/types"));
28
+ class StackedStates {
29
+ constructor() {
30
+ this.maps = [];
31
+ this.push();
32
+ }
33
+ push() {
34
+ this.maps.push(new Map());
35
+ }
36
+ pop() {
37
+ this.maps.pop();
38
+ }
39
+ get(name) {
40
+ for (let i = this.maps.length - 1; i >= 0; i--) {
41
+ if (this.maps[i].has(name)) {
42
+ return this.maps[i].get(name);
43
+ }
44
+ }
45
+ return undefined;
46
+ }
47
+ set(name, state) {
48
+ this.maps[this.maps.length - 1].set(name, state);
49
+ }
50
+ }
51
+ exports.StackedStates = StackedStates;
52
+ exports.ctx = t.identifier("Vasille");
@@ -0,0 +1,88 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.exprHasJsx = exprHasJsx;
27
+ exports.statementHasJsx = statementHasJsx;
28
+ exports.bodyHasJsx = bodyHasJsx;
29
+ const t = __importStar(require("@babel/types"));
30
+ function exprHasJsx(node) {
31
+ if (t.isBinaryExpression(node)) {
32
+ return (t.isExpression(node.left) && exprHasJsx(node.left)) || exprHasJsx(node.right);
33
+ }
34
+ if (t.isConditionalExpression(node)) {
35
+ return exprHasJsx(node.consequent) || exprHasJsx(node.alternate);
36
+ }
37
+ if (t.isLogicalExpression(node)) {
38
+ return exprHasJsx(node.left) || exprHasJsx(node.right);
39
+ }
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
+ return t.isJSXElement(node) || t.isJSXFragment(node);
50
+ }
51
+ function statementHasJsx(statement) {
52
+ if (t.isExpressionStatement(statement)) {
53
+ return exprHasJsx(statement.expression);
54
+ }
55
+ if (t.isBlockStatement(statement)) {
56
+ return bodyHasJsx(statement);
57
+ }
58
+ if (t.isDoWhileStatement(statement)) {
59
+ return statementHasJsx(statement.body);
60
+ }
61
+ if (t.isForInStatement(statement)) {
62
+ return statementHasJsx(statement.body);
63
+ }
64
+ if (t.isSwitchStatement(statement)) {
65
+ return statement.cases.some(_case => {
66
+ return _case.consequent.some(statementHasJsx);
67
+ });
68
+ }
69
+ if (t.isWhileStatement(statement)) {
70
+ return statementHasJsx(statement.body);
71
+ }
72
+ if (t.isForOfStatement(statement)) {
73
+ return statementHasJsx(statement.body);
74
+ }
75
+ if (t.isLabeledStatement(statement)) {
76
+ return statementHasJsx(statement.body);
77
+ }
78
+ if (t.isReturnStatement(statement)) {
79
+ return !!statement.argument && exprHasJsx(statement.argument);
80
+ }
81
+ return false;
82
+ }
83
+ function bodyHasJsx(node) {
84
+ if (t.isExpression(node)) {
85
+ return exprHasJsx(node);
86
+ }
87
+ return node.body.some(statementHasJsx);
88
+ }