babel-plugin-vasille 3.1.5 → 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.
@@ -1,573 +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 call_js_1 = require("./call.js");
52
- const internal_js_1 = require("./internal.js");
53
- function encodeName(name) {
54
- return t.identifier(`Vasille_${name}`);
55
- }
56
- function addIdentifier(path, search) {
57
- if (!search.found.has(path.node.name)) {
58
- search.found.set(path.node.name, path.node);
59
- }
60
- path.replaceWith(encodeName(path.node.name));
61
- }
62
- function stringify(node) {
63
- let name = "";
64
- if (t.isStringLiteral(node)) {
65
- name = node.value;
66
- }
67
- if (t.isPrivateName(node)) {
68
- name = node.id.name;
69
- }
70
- if (t.isIdentifier(node)) {
71
- name = node.name;
72
- }
73
- return name;
74
- }
75
- function extractMemberName(path, search) {
76
- const names = [];
77
- let it = path.node;
78
- while (t.isMemberExpression(it)) {
79
- const name = stringify(it.property);
80
- if (name === "$" && it !== path.node) {
81
- throw path.buildCodeFrameError("Vasille: The reactive/observable value is nested");
82
- }
83
- it = it.object;
84
- names.push(name);
85
- }
86
- names.push(stringify(it));
87
- if (t.isIdentifier(it) &&
88
- search.stack.get(it.name, internal_js_1.VariableScope.Local) === 1 /* VariableState.Ignored */) {
89
- throw path.buildCodeFrameError("Vasille: This node cannot be processed, the root of expression is a local variable");
90
- }
91
- return names.reverse().join("_");
92
- }
93
- function addMemberExpr(path, search) {
94
- const name = extractMemberName(path, search);
95
- if (!search.found.has(name)) {
96
- search.found.set(name, path.node);
97
- }
98
- path.replaceWith(encodeName(name));
99
- }
100
- function addExternalIValue(path, search) {
101
- const name = extractMemberName(path, search);
102
- if (!search.found.has(name)) {
103
- search.found.set(name, path.node.object);
104
- }
105
- path.replaceWith(encodeName(name));
106
- }
107
- function meshIdentifier(path, internal) {
108
- if (idIsIValue(path, internal)) {
109
- path.replaceWith(t.memberExpression(path.node, t.identifier("$")));
110
- }
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
- }
145
- function meshMember(path, internal) {
146
- if (memberIsIValue(path.node, internal)) {
147
- path.replaceWith(t.memberExpression(path.node, t.identifier("$")));
148
- }
149
- }
150
- function meshLValue(path, internal) {
151
- const node = path.node;
152
- if (t.isIdentifier(node)) {
153
- meshIdentifier(path, internal);
154
- }
155
- else if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
156
- meshMember(path, internal);
157
- }
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);
167
- }
168
- }
169
- function checkNode(path, internal) {
170
- const search = {
171
- external: internal,
172
- found: new Map(),
173
- self: null,
174
- stack: internal.stack,
175
- };
176
- if (t.isIdentifier(path.node)) {
177
- if (idIsIValue(path, internal)) {
178
- search.self = path.node;
179
- }
180
- }
181
- if (t.isMemberExpression(path.node)) {
182
- if (memberIsIValue(path.node, internal)) {
183
- search.self = path.node;
184
- }
185
- else if (t.isIdentifier(path.node.property) && path.node.property.name === "$") {
186
- search.self = path.node.object;
187
- }
188
- }
189
- if (search.self) {
190
- return search;
191
- }
192
- internal.stack.fixLocalIndex();
193
- internal.stack.push();
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
- if (t.isExpression(path.node)) {
204
- checkExpression(path, search);
205
- }
206
- }
207
- }
208
- function checkAllExpressions(nodePaths, search) {
209
- for (const path of nodePaths) {
210
- checkExpression(path, search);
211
- }
212
- }
213
- function checkAllUnknown(paths, internal) {
214
- for (const path of paths) {
215
- if (t.isSpreadElement(path.node)) {
216
- checkExpression(path.get("argument"), internal);
217
- }
218
- else if (t.isExpression(path.node)) {
219
- checkExpression(path, internal);
220
- }
221
- }
222
- }
223
- function checkOrIgnoreExpression(path, search) {
224
- if (t.isExpression(path.node)) {
225
- checkExpression(path, search);
226
- }
227
- }
228
- const REACTIVE_STATES = [2 /* VariableState.Reactive */, 4 /* VariableState.ReactivePointer */];
229
- function checkExpression(nodePath, search) {
230
- const expr = nodePath.node;
231
- switch (expr && expr.type) {
232
- case "TemplateLiteral": {
233
- const path = nodePath;
234
- checkOrIgnoreAllExpressions(path.get("expressions"), search);
235
- break;
236
- }
237
- case "TaggedTemplateExpression": {
238
- const path = nodePath;
239
- checkExpression(path.get("quasi"), search);
240
- path.get("");
241
- break;
242
- }
243
- case "Identifier": {
244
- if (expr && t.isIdentifier(expr)) {
245
- if (idIsIValue(nodePath, search.external, internal_js_1.VariableScope.Global) &&
246
- !idIsLocal(nodePath, search.external)) {
247
- addIdentifier(nodePath, search);
248
- }
249
- }
250
- break;
251
- }
252
- case "ArrayExpression": {
253
- const path = nodePath;
254
- checkAllUnknown(path.get("elements"), search);
255
- break;
256
- }
257
- case "CallExpression": {
258
- const path = nodePath;
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);
263
- checkAllUnknown(path.get("arguments"), search);
264
- break;
265
- }
266
- case "OptionalCallExpression": {
267
- const path = nodePath;
268
- checkExpression(path.get("callee"), search);
269
- checkAllUnknown(path.get("arguments"), search);
270
- break;
271
- }
272
- case "AssignmentExpression": {
273
- const path = nodePath;
274
- meshLValue(path.get("left"), search.external);
275
- checkExpression(path.get("right"), search);
276
- break;
277
- }
278
- case "MemberExpression":
279
- case "OptionalMemberExpression": {
280
- const path = nodePath;
281
- const node = path.node;
282
- if (memberIsIValue(node, search.external, internal_js_1.VariableScope.Global)) {
283
- addMemberExpr(path, search);
284
- }
285
- else if (t.isIdentifier(node.property) && node.property.name === "$") {
286
- addExternalIValue(path, search);
287
- }
288
- else {
289
- checkExpression(path.get("object"), search);
290
- checkOrIgnoreExpression(path.get("property"), search);
291
- }
292
- break;
293
- }
294
- case "BinaryExpression": {
295
- const path = nodePath;
296
- checkOrIgnoreExpression(path.get("left"), search);
297
- checkExpression(path.get("right"), search);
298
- break;
299
- }
300
- case "ConditionalExpression": {
301
- const path = nodePath;
302
- checkExpression(path.get("test"), search);
303
- checkExpression(path.get("consequent"), search);
304
- checkExpression(path.get("alternate"), search);
305
- break;
306
- }
307
- case "LogicalExpression": {
308
- const path = nodePath;
309
- checkExpression(path.get("left"), search);
310
- checkExpression(path.get("right"), search);
311
- break;
312
- }
313
- case "NewExpression": {
314
- const path = nodePath;
315
- checkOrIgnoreExpression(path.get("callee"), search);
316
- checkAllUnknown(path.get("arguments"), search);
317
- break;
318
- }
319
- case "SequenceExpression": {
320
- const path = nodePath;
321
- checkAllExpressions(path.get("expressions"), search);
322
- break;
323
- }
324
- case "UnaryExpression": {
325
- const path = nodePath;
326
- checkExpression(path.get("argument"), search);
327
- break;
328
- }
329
- case "UpdateExpression": {
330
- const path = nodePath;
331
- const arg = path.node.argument;
332
- if (t.isLVal(arg)) {
333
- meshLValue(path.get("argument"), search.external);
334
- }
335
- break;
336
- }
337
- case "YieldExpression": {
338
- const path = nodePath;
339
- checkExpression(path.get("argument"), search);
340
- break;
341
- }
342
- case "AwaitExpression": {
343
- const path = nodePath;
344
- checkExpression(path.get("argument"), search);
345
- break;
346
- }
347
- case "TSInstantiationExpression": {
348
- const path = nodePath;
349
- checkExpression(path.get("expression"), search);
350
- break;
351
- }
352
- case "TSAsExpression": {
353
- const path = nodePath;
354
- checkExpression(path.get("expression"), search);
355
- break;
356
- }
357
- case "TSSatisfiesExpression": {
358
- const path = nodePath;
359
- checkExpression(path.get("expression"), search);
360
- break;
361
- }
362
- case "TSTypeAssertion": {
363
- const path = nodePath;
364
- checkExpression(path.get("expression"), search);
365
- break;
366
- }
367
- case "ObjectExpression": {
368
- const path = nodePath;
369
- for (const propPath of path.get("properties")) {
370
- const prop = propPath.node;
371
- if (t.isObjectProperty(prop)) {
372
- const path = propPath;
373
- const valuePath = path.get("value");
374
- if (path.node.computed) {
375
- checkOrIgnoreExpression(path.get("key"), search);
376
- }
377
- checkOrIgnoreExpression(valuePath, search);
378
- }
379
- else if (t.isObjectMethod(prop)) {
380
- checkFunction(propPath, search);
381
- }
382
- else {
383
- checkAllUnknown([propPath], search);
384
- }
385
- }
386
- break;
387
- }
388
- case "FunctionExpression": {
389
- checkFunction(nodePath, search);
390
- break;
391
- }
392
- case "ArrowFunctionExpression": {
393
- checkFunction(nodePath, search);
394
- break;
395
- }
396
- case "JSXFragment": {
397
- throw nodePath.buildCodeFrameError("Vasille: JSX fragment is not allowed here");
398
- }
399
- case "JSXElement": {
400
- throw nodePath.buildCodeFrameError("Vasille: JSX element is not allowed here");
401
- }
402
- }
403
- }
404
- function checkStatements(paths, search) {
405
- for (const path of paths) {
406
- checkStatement(path, search);
407
- }
408
- }
409
- function ignoreLocals(val, search) {
410
- if (t.isIdentifier(val)) {
411
- search.stack.set(val.name, 1 /* VariableState.Ignored */);
412
- }
413
- else if (t.isObjectPattern(val)) {
414
- for (const prop of val.properties) {
415
- if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
416
- search.stack.set(prop.value.name, 1 /* VariableState.Ignored */);
417
- }
418
- else if (t.isRestElement(prop) && t.isIdentifier(prop.argument)) {
419
- search.stack.set(prop.argument.name, 1 /* VariableState.Ignored */);
420
- }
421
- else if (t.isObjectProperty(prop) && t.isAssignmentPattern(prop.value)) {
422
- ignoreLocals(prop.value.left, search);
423
- }
424
- }
425
- }
426
- else if (t.isArrayPattern(val)) {
427
- for (const element of val.elements) {
428
- if (element && !t.isVoidPattern(element)) {
429
- ignoreLocals(element, search);
430
- }
431
- }
432
- }
433
- else if (t.isVariableDeclaration(val)) {
434
- for (const declarator of val.declarations) {
435
- if (!t.isVoidPattern(declarator.id)) {
436
- ignoreLocals(declarator.id, search);
437
- }
438
- }
439
- }
440
- }
441
- function checkStatement(path, search) {
442
- const statement = path.node;
443
- if (!statement) {
444
- return;
445
- }
446
- switch (statement.type) {
447
- case "BlockStatement":
448
- search.stack.push();
449
- checkStatements(path.get("body"), search);
450
- search.stack.pop();
451
- break;
452
- case "DoWhileStatement": {
453
- const _path = path;
454
- checkExpression(_path.get("test"), search);
455
- search.stack.push();
456
- checkStatement(_path.get("body"), search);
457
- search.stack.pop();
458
- break;
459
- }
460
- case "ExpressionStatement":
461
- checkExpression(path.get("expression"), search);
462
- break;
463
- case "ForInStatement": {
464
- const _path = path;
465
- ignoreLocals(_path.node.left, search);
466
- checkExpression(_path.get("right"), search);
467
- checkStatement(_path.get("body"), search);
468
- break;
469
- }
470
- case "ForOfStatement": {
471
- const _path = path;
472
- checkExpression(_path.get("right"), search);
473
- search.stack.push();
474
- checkStatement(_path.get("body"), search);
475
- search.stack.pop();
476
- break;
477
- }
478
- case "ForStatement": {
479
- const _path = path;
480
- const node = _path.node;
481
- if (node.init) {
482
- if (t.isExpression(node.init)) {
483
- checkExpression(_path.get("init"), search);
484
- }
485
- else {
486
- const variablePath = _path.get("init");
487
- for (const declarationPath of variablePath.get("declarations")) {
488
- checkExpression(declarationPath.get("init"), search);
489
- }
490
- }
491
- }
492
- checkExpression(_path.get("test"), search);
493
- checkExpression(_path.get("update"), search);
494
- search.stack.push();
495
- checkStatement(_path.get("body"), search);
496
- search.stack.pop();
497
- break;
498
- }
499
- case "FunctionDeclaration":
500
- checkFunction(path, search);
501
- break;
502
- case "IfStatement": {
503
- const _path = path;
504
- checkExpression(_path.get("test"), search);
505
- search.stack.push();
506
- checkStatement(_path.get("consequent"), search);
507
- search.stack.pop();
508
- search.stack.push();
509
- checkStatement(_path.get("alternate"), search);
510
- search.stack.pop();
511
- break;
512
- }
513
- case "LabeledStatement":
514
- search.stack.push();
515
- checkStatement(path.get("body"), search);
516
- search.stack.pop();
517
- break;
518
- case "ReturnStatement":
519
- checkExpression(path.get("argument"), search);
520
- break;
521
- case "SwitchStatement": {
522
- const _path = path;
523
- checkExpression(_path.get("discriminant"), search);
524
- search.stack.push();
525
- for (const _case of _path.get("cases")) {
526
- checkExpression(_case.get("test"), search);
527
- checkStatements(_case.get("consequent"), search);
528
- }
529
- search.stack.pop();
530
- break;
531
- }
532
- case "ThrowStatement":
533
- checkExpression(path.get("argument"), search);
534
- break;
535
- case "TryStatement":
536
- const handlerPath = path.get("handler");
537
- checkStatement(path.get("block"), search);
538
- if (handlerPath.node) {
539
- checkStatement(handlerPath.get("body"), search);
540
- }
541
- checkStatement(path.get("finalizer"), search);
542
- break;
543
- case "VariableDeclaration": {
544
- const _path = path;
545
- for (const declaration of _path.get("declarations")) {
546
- ignoreLocals(declaration.node.id, search);
547
- checkExpression(declaration.get("init"), search);
548
- }
549
- break;
550
- }
551
- case "WhileStatement": {
552
- const _path = path;
553
- checkExpression(_path.get("test"), search);
554
- search.stack.push();
555
- checkStatement(_path.get("body"), search);
556
- search.stack.pop();
557
- break;
558
- }
559
- }
560
- }
561
- function checkFunction(path, search) {
562
- const node = path.node;
563
- for (const param of node.params) {
564
- ignoreLocals(param, search);
565
- }
566
- if (t.isExpression(node.body)) {
567
- checkExpression(path.get("body"), search);
568
- }
569
- else {
570
- const bodyPath = path.get("body");
571
- checkStatement(bodyPath, search);
572
- }
573
- }
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
- }
@@ -1,100 +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.exprHasJsx = exprHasJsx;
37
- exports.statementHasJsx = statementHasJsx;
38
- exports.bodyHasJsx = bodyHasJsx;
39
- const t = __importStar(require("@babel/types"));
40
- 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
- return t.isJSXElement(node) || t.isJSXFragment(node);
51
- }
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
- function bodyHasJsx(node) {
96
- if (t.isExpression(node)) {
97
- return exprHasJsx(node);
98
- }
99
- return node.body.some(statementHasJsx);
100
- }