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.
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.nodeIsReactiveObject = nodeIsReactiveObject;
39
+ exports.exprIsSure = exprIsSure;
41
40
  exports.checkNode = checkNode;
42
41
  exports.checkOrIgnoreAllExpressions = checkOrIgnoreAllExpressions;
43
42
  exports.checkAllExpressions = checkAllExpressions;
@@ -49,120 +48,107 @@ exports.checkStatement = checkStatement;
49
48
  exports.checkFunction = checkFunction;
50
49
  const t = __importStar(require("@babel/types"));
51
50
  const call_js_1 = require("./call.js");
52
- const internal_js_1 = require("./internal.js");
51
+ const lib_1 = require("./lib");
52
+ const mesh_1 = require("./mesh");
53
+ const router_1 = require("./router");
54
+ const utils_1 = require("./utils");
53
55
  function encodeName(name) {
54
- return t.identifier(`Vasille_${name}`);
56
+ return insertName(name);
57
+ }
58
+ function insertName(name, search) {
59
+ const id = t.identifier(`Vasille_${name}`);
60
+ search?.inserted.add(id);
61
+ return id;
55
62
  }
56
63
  function addIdentifier(path, search) {
57
- if (!search.found.has(path.node.name)) {
58
- search.found.set(path.node.name, path.node);
64
+ const name = unprefixedName(path.node.name);
65
+ if (!search.found.has(name)) {
66
+ search.found.set(name, path.node);
59
67
  }
60
- path.replaceWith(encodeName(path.node.name));
68
+ path.replaceWith(insertName(name, search));
61
69
  }
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;
70
+ function unprefixedName(name) {
71
+ return name[0] === "$" ? name.slice(1) : name;
74
72
  }
75
73
  function extractMemberName(path, search) {
76
74
  const names = [];
77
75
  let it = path.node;
78
76
  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
- }
77
+ names.push((0, utils_1.stringify)(it.property));
83
78
  it = it.object;
84
- names.push(name);
85
79
  }
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");
80
+ names.push((0, utils_1.stringify)(it));
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);
90
83
  }
91
- return names.reverse().join("_");
84
+ return names.reverse().map(unprefixedName).join("_");
92
85
  }
93
86
  function addMemberExpr(path, search) {
94
87
  const name = extractMemberName(path, search);
88
+ /* istanbul ignore else */
95
89
  if (!search.found.has(name)) {
96
90
  search.found.set(name, path.node);
97
91
  }
98
- path.replaceWith(encodeName(name));
92
+ path.replaceWith(insertName(name, search));
99
93
  }
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("$")));
94
+ function meshIdentifier(path) {
95
+ if (idIsIValue(path)) {
96
+ path.replaceWith(t.memberExpression(path.node, t.identifier("V")));
110
97
  }
111
98
  }
112
- function idIsIValue(path, internal, scope) {
99
+ function idIsIValue(path) {
113
100
  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;
101
+ return node.name.startsWith("$") && (!t.isMemberExpression(path.parent) || path.parent.object === node);
119
102
  }
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("$$")))));
103
+ function memberIsIValue(node) {
104
+ return ((t.isIdentifier(node.property) && node.property.name.startsWith("$")) ||
105
+ (t.isStringLiteral(node.property) && node.property.value.startsWith("$")));
134
106
  }
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 */;
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;
139
112
  }
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("$$")));
113
+ if (!path.isMemberExpression() || !(0, utils_1.stringify)(path.node.property).startsWith("$")) {
114
+ return true;
143
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);
144
125
  }
145
- function meshMember(path, internal) {
146
- if (memberIsIValue(path.node, internal)) {
147
- 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));
148
129
  }
149
130
  }
150
131
  function meshLValue(path, internal) {
151
- const node = path.node;
152
- if (t.isIdentifier(node)) {
153
- meshIdentifier(path, internal);
132
+ /* istanbul ignore else */
133
+ if (path.isIdentifier()) {
134
+ meshIdentifier(path);
154
135
  }
155
- else if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
156
- meshMember(path, internal);
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
+ }
157
142
  }
158
- else if (t.isArrayPattern(node)) {
143
+ else if (path.isArrayPattern()) {
159
144
  for (const item of path.get("elements")) {
160
- if (t.isOptionalMemberExpression(item.node) || t.isLVal(item.node)) {
145
+ /* istanbul ignore else */
146
+ if (item.isOptionalMemberExpression() || item.isLVal()) {
161
147
  meshLValue(item, internal);
162
148
  }
163
149
  }
164
150
  }
165
- else if (t.isRestElement(node)) {
151
+ else if (path.isRestElement()) {
166
152
  meshLValue(path.get("argument"), internal);
167
153
  }
168
154
  }
@@ -171,36 +157,38 @@ function checkNode(path, internal) {
171
157
  external: internal,
172
158
  found: new Map(),
173
159
  self: null,
160
+ inserted: new Set(),
174
161
  stack: internal.stack,
175
162
  };
176
- if (t.isIdentifier(path.node)) {
177
- if (idIsIValue(path, internal)) {
163
+ if (path.isIdentifier()) {
164
+ if (idIsIValue(path)) {
178
165
  search.self = path.node;
179
166
  }
180
167
  }
181
- if (t.isMemberExpression(path.node)) {
182
- if (memberIsIValue(path.node, internal)) {
168
+ if (path.isMemberExpression()) {
169
+ if (memberIsIValue(path.node)) {
183
170
  search.self = path.node;
184
171
  }
185
- else if (t.isIdentifier(path.node.property) && path.node.property.name === "$") {
186
- search.self = path.node.object;
187
- }
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;
188
176
  }
189
177
  if (search.self) {
190
178
  return search;
191
179
  }
192
- internal.stack.fixLocalIndex();
193
180
  internal.stack.push();
194
- if (t.isExpression(path.node)) {
181
+ /* istanbul ignore else */
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
- if (t.isExpression(path.node)) {
190
+ /* istanbul ignore else */
191
+ if (path.isExpression()) {
204
192
  checkExpression(path, search);
205
193
  }
206
194
  }
@@ -212,20 +200,21 @@ function checkAllExpressions(nodePaths, search) {
212
200
  }
213
201
  function checkAllUnknown(paths, internal) {
214
202
  for (const path of paths) {
215
- if (t.isSpreadElement(path.node)) {
203
+ /* istanbul ignore else */
204
+ if (path.isSpreadElement()) {
216
205
  checkExpression(path.get("argument"), internal);
217
206
  }
218
- else if (t.isExpression(path.node)) {
207
+ else if (path.isExpression()) {
219
208
  checkExpression(path, internal);
220
209
  }
221
210
  }
222
211
  }
223
212
  function checkOrIgnoreExpression(path, search) {
224
- if (t.isExpression(path.node)) {
213
+ /* istanbul ignore else */
214
+ if (path.isExpression()) {
225
215
  checkExpression(path, search);
226
216
  }
227
217
  }
228
- const REACTIVE_STATES = [2 /* VariableState.Reactive */, 4 /* VariableState.ReactivePointer */];
229
218
  function checkExpression(nodePath, search) {
230
219
  const expr = nodePath.node;
231
220
  switch (expr && expr.type) {
@@ -241,9 +230,9 @@ function checkExpression(nodePath, search) {
241
230
  break;
242
231
  }
243
232
  case "Identifier": {
244
- if (expr && t.isIdentifier(expr)) {
245
- if (idIsIValue(nodePath, search.external, internal_js_1.VariableScope.Global) &&
246
- !idIsLocal(nodePath, search.external)) {
233
+ /* istanbul ignore else */
234
+ if (expr && nodePath.isIdentifier()) {
235
+ if (idIsIValue(nodePath)) {
247
236
  addIdentifier(nodePath, search);
248
237
  }
249
238
  }
@@ -256,11 +245,21 @@ function checkExpression(nodePath, search) {
256
245
  }
257
246
  case "CallExpression": {
258
247
  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");
248
+ if ((0, call_js_1.calls)(path, ["router"], search.external)) {
249
+ if (!search.external.stateOnly) {
250
+ (0, router_1.routerReplace)(path);
251
+ }
252
+ else {
253
+ (0, lib_1.err)(lib_1.Errors.IncompatibleContext, path, "The router is not available in stores", search.external, null);
254
+ }
255
+ }
256
+ else {
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);
259
+ }
260
+ checkOrIgnoreExpression(path.get("callee"), search);
261
+ checkAllUnknown(path.get("arguments"), search);
261
262
  }
262
- checkOrIgnoreExpression(path.get("callee"), search);
263
- checkAllUnknown(path.get("arguments"), search);
264
263
  break;
265
264
  }
266
265
  case "OptionalCallExpression": {
@@ -271,20 +270,30 @@ function checkExpression(nodePath, search) {
271
270
  }
272
271
  case "AssignmentExpression": {
273
272
  const path = nodePath;
274
- meshLValue(path.get("left"), search.external);
275
- checkExpression(path.get("right"), search);
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
+ }
276
288
  break;
277
289
  }
278
290
  case "MemberExpression":
279
291
  case "OptionalMemberExpression": {
280
292
  const path = nodePath;
281
293
  const node = path.node;
282
- if (memberIsIValue(node, search.external, internal_js_1.VariableScope.Global)) {
294
+ if (memberIsIValue(node)) {
283
295
  addMemberExpr(path, search);
284
296
  }
285
- else if (t.isIdentifier(node.property) && node.property.name === "$") {
286
- addExternalIValue(path, search);
287
- }
288
297
  else {
289
298
  checkExpression(path.get("object"), search);
290
299
  checkOrIgnoreExpression(path.get("property"), search);
@@ -329,6 +338,7 @@ function checkExpression(nodePath, search) {
329
338
  case "UpdateExpression": {
330
339
  const path = nodePath;
331
340
  const arg = path.node.argument;
341
+ /* istanbul ignore else */
332
342
  if (t.isLVal(arg)) {
333
343
  meshLValue(path.get("argument"), search.external);
334
344
  }
@@ -394,10 +404,12 @@ function checkExpression(nodePath, search) {
394
404
  break;
395
405
  }
396
406
  case "JSXFragment": {
397
- throw nodePath.buildCodeFrameError("Vasille: JSX fragment is not allowed here");
407
+ (0, lib_1.err)(lib_1.Errors.IncompatibleContext, nodePath, "JSX fragment is not allowed here", search.external, null);
408
+ break;
398
409
  }
399
410
  case "JSXElement": {
400
- throw nodePath.buildCodeFrameError("Vasille: JSX element is not allowed here");
411
+ (0, lib_1.err)(lib_1.Errors.IncompatibleContext, nodePath, "JSX element is not allowed here", search.external, null);
412
+ break;
401
413
  }
402
414
  }
403
415
  }
@@ -406,36 +418,15 @@ function checkStatements(paths, search) {
406
418
  checkStatement(path, search);
407
419
  }
408
420
  }
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
- }
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"]);
431
426
  }
432
427
  }
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
- }
428
+ else {
429
+ (0, mesh_1.ignoreParams)(path, search.external, ["id", "array"]);
439
430
  }
440
431
  }
441
432
  function checkStatement(path, search) {
@@ -462,7 +453,7 @@ function checkStatement(path, search) {
462
453
  break;
463
454
  case "ForInStatement": {
464
455
  const _path = path;
465
- ignoreLocals(_path.node.left, search);
456
+ ignoreLocals(_path.get("left"), search);
466
457
  checkExpression(_path.get("right"), search);
467
458
  checkStatement(_path.get("body"), search);
468
459
  break;
@@ -478,6 +469,7 @@ function checkStatement(path, search) {
478
469
  case "ForStatement": {
479
470
  const _path = path;
480
471
  const node = _path.node;
472
+ /* istanbul ignore else */
481
473
  if (node.init) {
482
474
  if (t.isExpression(node.init)) {
483
475
  checkExpression(_path.get("init"), search);
@@ -535,6 +527,7 @@ function checkStatement(path, search) {
535
527
  case "TryStatement":
536
528
  const handlerPath = path.get("handler");
537
529
  checkStatement(path.get("block"), search);
530
+ /* istanbul ignore else */
538
531
  if (handlerPath.node) {
539
532
  checkStatement(handlerPath.get("body"), search);
540
533
  }
@@ -543,7 +536,7 @@ function checkStatement(path, search) {
543
536
  case "VariableDeclaration": {
544
537
  const _path = path;
545
538
  for (const declaration of _path.get("declarations")) {
546
- ignoreLocals(declaration.node.id, search);
539
+ ignoreLocals(declaration.get("id"), search);
547
540
  checkExpression(declaration.get("init"), search);
548
541
  }
549
542
  break;
@@ -560,9 +553,21 @@ function checkStatement(path, search) {
560
553
  }
561
554
  function checkFunction(path, search) {
562
555
  const node = path.node;
563
- for (const param of node.params) {
556
+ for (const param of path.get("params")) {
564
557
  ignoreLocals(param, search);
565
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
+ }
566
571
  if (t.isExpression(node.body)) {
567
572
  checkExpression(path.get("body"), search);
568
573
  }
@@ -570,4 +575,7 @@ function checkFunction(path, search) {
570
575
  const bodyPath = path.get("body");
571
576
  checkStatement(bodyPath, search);
572
577
  }
578
+ if (t.isFunctionExpression(node) && node.id) {
579
+ search.stack.pop();
580
+ }
573
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.trProgram)(path, params.opts.devMode !== false);
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 = exports.VariableScope = void 0;
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, 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--) {
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(statementHasJsx);
46
+ return node.body.some(statement => {
47
+ return t.isExpressionStatement(statement) && exprHasJsx(statement.expression);
48
+ });
100
49
  }