flow-parser 0.321.0 → 0.322.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.
Files changed (35) hide show
  1. package/dist/FlowParser.js +3 -53
  2. package/dist/FlowParserDeserializer.js +3 -41
  3. package/dist/FlowParserNodeDeserializers.js +0 -7
  4. package/dist/FlowParserWASM.js +1 -1
  5. package/dist/HermesParserDecodeUTF8String.js +0 -9
  6. package/dist/ParserOptions.js +1 -2
  7. package/dist/babel/TransformESTreeToBabel.js +9 -157
  8. package/dist/estree/StripFlowTypes.js +0 -26
  9. package/dist/estree/StripFlowTypesForBabel.js +0 -24
  10. package/dist/estree/TransformComponentSyntax.js +0 -87
  11. package/dist/estree/TransformEnumSyntax.js +0 -12
  12. package/dist/estree/TransformMatchSyntax.js +3 -99
  13. package/dist/estree/TransformRecordSyntax.js +3 -31
  14. package/dist/getModuleDocblock.js +0 -21
  15. package/dist/index.js +25 -99
  16. package/dist/transform/SimpleTransform.js +0 -21
  17. package/dist/transform/astArrayMutationHelpers.js +0 -9
  18. package/dist/transform/astNodeMutationHelpers.js +4 -26
  19. package/dist/transform/print/comments/comments.js +2 -51
  20. package/dist/transform/print/comments/prettier/common/util.js +0 -49
  21. package/dist/transform/print/comments/prettier/language-js/comments.js +0 -111
  22. package/dist/transform/print/comments/prettier/language-js/loc.js +0 -6
  23. package/dist/transform/print/comments/prettier/language-js/printer-estree.js +0 -3
  24. package/dist/transform/print/comments/prettier/language-js/utils.js +0 -20
  25. package/dist/transform/print/comments/prettier/main/comments.js +2 -63
  26. package/dist/transform/print/comments/prettier/utils/get-last.js +0 -1
  27. package/dist/transform/print/print.js +6 -22
  28. package/dist/traverse/SimpleTraverser.js +2 -22
  29. package/dist/traverse/getVisitorKeys.js +3 -9
  30. package/dist/utils/Builders.js +1 -17
  31. package/dist/utils/GenID.js +0 -7
  32. package/dist/utils/createSyntaxError.js +0 -1
  33. package/dist/utils/isReservedWord.js +0 -2
  34. package/dist/utils/mutateESTreeASTForPrettier.js +6 -21
  35. package/package.json +2 -2
@@ -12,7 +12,6 @@ const {
12
12
  getNextNonSpaceNonCommentCharacter,
13
13
  isNonEmptyArray
14
14
  } = require('../common/util.js');
15
-
16
15
  const {
17
16
  isBlockComment,
18
17
  getFunctionParameters,
@@ -23,36 +22,29 @@ const {
23
22
  isMemberExpression,
24
23
  isObjectProperty
25
24
  } = require('./utils.js');
26
-
27
25
  const {
28
26
  locStart,
29
27
  locEnd
30
28
  } = require('./loc.js');
31
-
32
29
  function handleOwnLineComment(context) {
33
30
  return [handleIgnoreComments, handleLastFunctionArgComments, handleMemberExpressionComments, handleIfStatementComments, handleWhileComments, handleTryStatementComments, handleClassComments, handleImportSpecifierComments, handleForComments, handleUnionTypeComments, handleMatchOrPatternComments, handleOnlyComments, handleImportDeclarationComments, handleAssignmentPatternComments, handleMethodNameComments, handleLabeledStatementComments].some(fn => fn(context));
34
31
  }
35
-
36
32
  function handleEndOfLineComment(context) {
37
33
  return [handleClosureTypeCastComments, handleLastFunctionArgComments, handleConditionalExpressionComments, handleImportSpecifierComments, handleIfStatementComments, handleWhileComments, handleTryStatementComments, handleClassComments, handleLabeledStatementComments, handleCallExpressionComments, handlePropertyComments, handleOnlyComments, handleTypeAliasComments, handleVariableDeclaratorComments].some(fn => fn(context));
38
34
  }
39
-
40
35
  function handleRemainingComment(context) {
41
36
  return [handleIgnoreComments, handleIfStatementComments, handleWhileComments, handleObjectPropertyAssignment, handleCommentInEmptyParens, handleMethodNameComments, handleOnlyComments, handleCommentAfterArrowParams, handleFunctionNameComments, handleTSMappedTypeComments, handleBreakAndContinueStatementComments, handleTSFunctionTrailingComments].some(fn => fn(context));
42
37
  }
43
-
44
38
  function addBlockStatementFirstComment(node, comment) {
45
39
  const firstNonEmptyNode = (node.body || node.properties).find(({
46
40
  type
47
41
  }) => type !== 'EmptyStatement');
48
-
49
42
  if (firstNonEmptyNode) {
50
43
  addLeadingComment(firstNonEmptyNode, comment);
51
44
  } else {
52
45
  addDanglingComment(node, comment);
53
46
  }
54
47
  }
55
-
56
48
  function addBlockOrNotComment(node, comment) {
57
49
  if (node.type === 'BlockStatement') {
58
50
  addBlockStatementFirstComment(node, comment);
@@ -60,7 +52,6 @@ function addBlockOrNotComment(node, comment) {
60
52
  addLeadingComment(node, comment);
61
53
  }
62
54
  }
63
-
64
55
  function handleClosureTypeCastComments({
65
56
  comment,
66
57
  followingNode
@@ -69,10 +60,8 @@ function handleClosureTypeCastComments({
69
60
  addLeadingComment(followingNode, comment);
70
61
  return true;
71
62
  }
72
-
73
63
  return false;
74
64
  }
75
-
76
65
  function handleIfStatementComments({
77
66
  comment,
78
67
  precedingNode,
@@ -83,42 +72,33 @@ function handleIfStatementComments({
83
72
  if (!enclosingNode || enclosingNode.type !== 'IfStatement' || !followingNode) {
84
73
  return false;
85
74
  }
86
-
87
75
  const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment, locEnd);
88
-
89
76
  if (nextCharacter === ')') {
90
77
  addTrailingComment(precedingNode, comment);
91
78
  return true;
92
79
  }
93
-
94
80
  if (precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate) {
95
81
  if (precedingNode.type === 'BlockStatement') {
96
82
  addTrailingComment(precedingNode, comment);
97
83
  } else {
98
84
  addDanglingComment(enclosingNode, comment);
99
85
  }
100
-
101
86
  return true;
102
87
  }
103
-
104
88
  if (followingNode.type === 'BlockStatement') {
105
89
  addBlockStatementFirstComment(followingNode, comment);
106
90
  return true;
107
91
  }
108
-
109
92
  if (followingNode.type === 'IfStatement') {
110
93
  addBlockOrNotComment(followingNode.consequent, comment);
111
94
  return true;
112
95
  }
113
-
114
96
  if (enclosingNode.consequent === followingNode) {
115
97
  addLeadingComment(followingNode, comment);
116
98
  return true;
117
99
  }
118
-
119
100
  return false;
120
101
  }
121
-
122
102
  function handleWhileComments({
123
103
  comment,
124
104
  precedingNode,
@@ -129,27 +109,21 @@ function handleWhileComments({
129
109
  if (!enclosingNode || enclosingNode.type !== 'WhileStatement' || !followingNode) {
130
110
  return false;
131
111
  }
132
-
133
112
  const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment, locEnd);
134
-
135
113
  if (nextCharacter === ')') {
136
114
  addTrailingComment(precedingNode, comment);
137
115
  return true;
138
116
  }
139
-
140
117
  if (followingNode.type === 'BlockStatement') {
141
118
  addBlockStatementFirstComment(followingNode, comment);
142
119
  return true;
143
120
  }
144
-
145
121
  if (enclosingNode.body === followingNode) {
146
122
  addLeadingComment(followingNode, comment);
147
123
  return true;
148
124
  }
149
-
150
125
  return false;
151
126
  }
152
-
153
127
  function handleTryStatementComments({
154
128
  comment,
155
129
  precedingNode,
@@ -159,30 +133,24 @@ function handleTryStatementComments({
159
133
  if (!enclosingNode || enclosingNode.type !== 'TryStatement' && enclosingNode.type !== 'CatchClause' || !followingNode) {
160
134
  return false;
161
135
  }
162
-
163
136
  if (enclosingNode.type === 'CatchClause' && precedingNode) {
164
137
  addTrailingComment(precedingNode, comment);
165
138
  return true;
166
139
  }
167
-
168
140
  if (followingNode.type === 'BlockStatement') {
169
141
  addBlockStatementFirstComment(followingNode, comment);
170
142
  return true;
171
143
  }
172
-
173
144
  if (followingNode.type === 'TryStatement') {
174
145
  addBlockOrNotComment(followingNode.finalizer, comment);
175
146
  return true;
176
147
  }
177
-
178
148
  if (followingNode.type === 'CatchClause') {
179
149
  addBlockOrNotComment(followingNode.body, comment);
180
150
  return true;
181
151
  }
182
-
183
152
  return false;
184
153
  }
185
-
186
154
  function handleMemberExpressionComments({
187
155
  comment,
188
156
  enclosingNode,
@@ -192,10 +160,8 @@ function handleMemberExpressionComments({
192
160
  addLeadingComment(enclosingNode, comment);
193
161
  return true;
194
162
  }
195
-
196
163
  return false;
197
164
  }
198
-
199
165
  function handleConditionalExpressionComments({
200
166
  comment,
201
167
  precedingNode,
@@ -204,15 +170,12 @@ function handleConditionalExpressionComments({
204
170
  text
205
171
  }) {
206
172
  const isSameLineAsPrecedingNode = precedingNode && !hasNewlineInRange(text, locEnd(precedingNode), locStart(comment));
207
-
208
173
  if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && (enclosingNode.type === 'ConditionalExpression' || enclosingNode.type === 'TSConditionalType') && followingNode) {
209
174
  addLeadingComment(followingNode, comment);
210
175
  return true;
211
176
  }
212
-
213
177
  return false;
214
178
  }
215
-
216
179
  function handleObjectPropertyAssignment({
217
180
  comment,
218
181
  precedingNode,
@@ -222,10 +185,8 @@ function handleObjectPropertyAssignment({
222
185
  addTrailingComment(enclosingNode.value.left, comment);
223
186
  return true;
224
187
  }
225
-
226
188
  return false;
227
189
  }
228
-
229
190
  function handleClassComments({
230
191
  comment,
231
192
  precedingNode,
@@ -237,12 +198,10 @@ function handleClassComments({
237
198
  addTrailingComment(getLast(enclosingNode.decorators), comment);
238
199
  return true;
239
200
  }
240
-
241
201
  if (enclosingNode.body && followingNode === enclosingNode.body) {
242
202
  addBlockStatementFirstComment(enclosingNode.body, comment);
243
203
  return true;
244
204
  }
245
-
246
205
  if (followingNode) {
247
206
  for (const prop of ['implements', 'extends', 'mixins']) {
248
207
  if (enclosingNode[prop] && followingNode === enclosingNode[prop][0]) {
@@ -251,16 +210,13 @@ function handleClassComments({
251
210
  } else {
252
211
  addDanglingComment(enclosingNode, comment, prop);
253
212
  }
254
-
255
213
  return true;
256
214
  }
257
215
  }
258
216
  }
259
217
  }
260
-
261
218
  return false;
262
219
  }
263
-
264
220
  function handleMethodNameComments({
265
221
  comment,
266
222
  precedingNode,
@@ -271,15 +227,12 @@ function handleMethodNameComments({
271
227
  addTrailingComment(precedingNode, comment);
272
228
  return true;
273
229
  }
274
-
275
230
  if (precedingNode && enclosingNode && precedingNode.type === 'Decorator' && (enclosingNode.type === 'ClassMethod' || enclosingNode.type === 'ClassProperty' || enclosingNode.type === 'PropertyDefinition' || enclosingNode.type === 'TSAbstractPropertyDefinition' || enclosingNode.type === 'TSAbstractMethodDefinition' || enclosingNode.type === 'TSDeclareMethod' || enclosingNode.type === 'MethodDefinition')) {
276
231
  addTrailingComment(precedingNode, comment);
277
232
  return true;
278
233
  }
279
-
280
234
  return false;
281
235
  }
282
-
283
236
  function handleFunctionNameComments({
284
237
  comment,
285
238
  precedingNode,
@@ -289,15 +242,12 @@ function handleFunctionNameComments({
289
242
  if (getNextNonSpaceNonCommentCharacter(text, comment, locEnd) !== '(') {
290
243
  return false;
291
244
  }
292
-
293
245
  if (precedingNode && enclosingNode && (enclosingNode.type === 'FunctionDeclaration' || enclosingNode.type === 'FunctionExpression' || enclosingNode.type === 'ClassMethod' || enclosingNode.type === 'MethodDefinition' || enclosingNode.type === 'ObjectMethod')) {
294
246
  addTrailingComment(precedingNode, comment);
295
247
  return true;
296
248
  }
297
-
298
249
  return false;
299
250
  }
300
-
301
251
  function handleCommentAfterArrowParams({
302
252
  comment,
303
253
  enclosingNode,
@@ -306,17 +256,13 @@ function handleCommentAfterArrowParams({
306
256
  if (!(enclosingNode && enclosingNode.type === 'ArrowFunctionExpression')) {
307
257
  return false;
308
258
  }
309
-
310
259
  const index = getNextNonSpaceNonCommentCharacterIndex(text, comment, locEnd);
311
-
312
260
  if (index !== false && text.slice(index, index + 2) === '=>') {
313
261
  addDanglingComment(enclosingNode, comment);
314
262
  return true;
315
263
  }
316
-
317
264
  return false;
318
265
  }
319
-
320
266
  function handleCommentInEmptyParens({
321
267
  comment,
322
268
  enclosingNode,
@@ -325,20 +271,16 @@ function handleCommentInEmptyParens({
325
271
  if (getNextNonSpaceNonCommentCharacter(text, comment, locEnd) !== ')') {
326
272
  return false;
327
273
  }
328
-
329
274
  if (enclosingNode && (isRealFunctionLikeNode(enclosingNode) && getFunctionParameters(enclosingNode).length === 0 || isCallLikeExpression(enclosingNode) && getCallArguments(enclosingNode).length === 0)) {
330
275
  addDanglingComment(enclosingNode, comment);
331
276
  return true;
332
277
  }
333
-
334
278
  if (enclosingNode && (enclosingNode.type === 'MethodDefinition' || enclosingNode.type === 'TSAbstractMethodDefinition') && getFunctionParameters(enclosingNode.value).length === 0) {
335
279
  addDanglingComment(enclosingNode.value, comment);
336
280
  return true;
337
281
  }
338
-
339
282
  return false;
340
283
  }
341
-
342
284
  function handleLastFunctionArgComments({
343
285
  comment,
344
286
  precedingNode,
@@ -350,33 +292,26 @@ function handleLastFunctionArgComments({
350
292
  addTrailingComment(precedingNode, comment);
351
293
  return true;
352
294
  }
353
-
354
295
  if (precedingNode && (precedingNode.type === 'Identifier' || precedingNode.type === 'AssignmentPattern') && enclosingNode && isRealFunctionLikeNode(enclosingNode) && getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === ')') {
355
296
  addTrailingComment(precedingNode, comment);
356
297
  return true;
357
298
  }
358
-
359
299
  if (enclosingNode && enclosingNode.type === 'FunctionDeclaration' && followingNode && followingNode.type === 'BlockStatement') {
360
300
  const functionParamRightParenIndex = (() => {
361
301
  const parameters = getFunctionParameters(enclosingNode);
362
-
363
302
  if (parameters.length > 0) {
364
303
  return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(getLast(parameters)));
365
304
  }
366
-
367
305
  const functionParamLeftParenIndex = getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(enclosingNode.id));
368
306
  return functionParamLeftParenIndex !== false && getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, functionParamLeftParenIndex + 1);
369
307
  })();
370
-
371
308
  if (locStart(comment) > functionParamRightParenIndex) {
372
309
  addBlockStatementFirstComment(followingNode, comment);
373
310
  return true;
374
311
  }
375
312
  }
376
-
377
313
  return false;
378
314
  }
379
-
380
315
  function handleImportSpecifierComments({
381
316
  comment,
382
317
  enclosingNode
@@ -385,10 +320,8 @@ function handleImportSpecifierComments({
385
320
  addLeadingComment(enclosingNode, comment);
386
321
  return true;
387
322
  }
388
-
389
323
  return false;
390
324
  }
391
-
392
325
  function handleLabeledStatementComments({
393
326
  comment,
394
327
  enclosingNode
@@ -397,10 +330,8 @@ function handleLabeledStatementComments({
397
330
  addLeadingComment(enclosingNode, comment);
398
331
  return true;
399
332
  }
400
-
401
333
  return false;
402
334
  }
403
-
404
335
  function handleBreakAndContinueStatementComments({
405
336
  comment,
406
337
  enclosingNode
@@ -409,10 +340,8 @@ function handleBreakAndContinueStatementComments({
409
340
  addTrailingComment(enclosingNode, comment);
410
341
  return true;
411
342
  }
412
-
413
343
  return false;
414
344
  }
415
-
416
345
  function handleCallExpressionComments({
417
346
  comment,
418
347
  precedingNode,
@@ -422,10 +351,8 @@ function handleCallExpressionComments({
422
351
  addLeadingComment(enclosingNode.arguments[0], comment);
423
352
  return true;
424
353
  }
425
-
426
354
  return false;
427
355
  }
428
-
429
356
  function handleUnionTypeComments({
430
357
  comment,
431
358
  precedingNode,
@@ -437,23 +364,18 @@ function handleUnionTypeComments({
437
364
  followingNode.prettierIgnore = true;
438
365
  comment.unignore = true;
439
366
  }
440
-
441
367
  if (precedingNode) {
442
368
  addTrailingComment(precedingNode, comment);
443
369
  return true;
444
370
  }
445
-
446
371
  return false;
447
372
  }
448
-
449
373
  if (followingNode && (followingNode.type === 'UnionTypeAnnotation' || followingNode.type === 'TSUnionType') && isPrettierIgnoreComment(comment)) {
450
374
  followingNode.types[0].prettierIgnore = true;
451
375
  comment.unignore = true;
452
376
  }
453
-
454
377
  return false;
455
378
  }
456
-
457
379
  function handleMatchOrPatternComments({
458
380
  comment,
459
381
  precedingNode,
@@ -465,23 +387,18 @@ function handleMatchOrPatternComments({
465
387
  followingNode.prettierIgnore = true;
466
388
  comment.unignore = true;
467
389
  }
468
-
469
390
  if (precedingNode) {
470
391
  addTrailingComment(precedingNode, comment);
471
392
  return true;
472
393
  }
473
-
474
394
  return false;
475
395
  }
476
-
477
396
  if (followingNode && followingNode.type === 'MatchOrPattern' && isPrettierIgnoreComment(comment)) {
478
397
  followingNode.types[0].prettierIgnore = true;
479
398
  comment.unignore = true;
480
399
  }
481
-
482
400
  return false;
483
401
  }
484
-
485
402
  function handlePropertyComments({
486
403
  comment,
487
404
  enclosingNode
@@ -490,10 +407,8 @@ function handlePropertyComments({
490
407
  addLeadingComment(enclosingNode, comment);
491
408
  return true;
492
409
  }
493
-
494
410
  return false;
495
411
  }
496
-
497
412
  function handleOnlyComments({
498
413
  comment,
499
414
  enclosingNode,
@@ -507,28 +422,22 @@ function handleOnlyComments({
507
422
  } else {
508
423
  addLeadingComment(ast, comment);
509
424
  }
510
-
511
425
  return true;
512
426
  }
513
-
514
427
  if (enclosingNode && enclosingNode.type === 'Program' && enclosingNode.body.length === 0 && !isNonEmptyArray(enclosingNode.directives)) {
515
428
  if (isLastComment) {
516
429
  addDanglingComment(enclosingNode, comment);
517
430
  } else {
518
431
  addLeadingComment(enclosingNode, comment);
519
432
  }
520
-
521
433
  return true;
522
434
  }
523
-
524
435
  if (followingNode && followingNode.type === 'Program' && followingNode.body.length === 0 && enclosingNode && enclosingNode.type === 'ModuleExpression') {
525
436
  addDanglingComment(followingNode, comment);
526
437
  return true;
527
438
  }
528
-
529
439
  return false;
530
440
  }
531
-
532
441
  function handleForComments({
533
442
  comment,
534
443
  enclosingNode
@@ -537,10 +446,8 @@ function handleForComments({
537
446
  addLeadingComment(enclosingNode, comment);
538
447
  return true;
539
448
  }
540
-
541
449
  return false;
542
450
  }
543
-
544
451
  function handleImportDeclarationComments({
545
452
  comment,
546
453
  precedingNode,
@@ -551,10 +458,8 @@ function handleImportDeclarationComments({
551
458
  addTrailingComment(precedingNode, comment);
552
459
  return true;
553
460
  }
554
-
555
461
  return false;
556
462
  }
557
-
558
463
  function handleAssignmentPatternComments({
559
464
  comment,
560
465
  enclosingNode
@@ -563,10 +468,8 @@ function handleAssignmentPatternComments({
563
468
  addLeadingComment(enclosingNode, comment);
564
469
  return true;
565
470
  }
566
-
567
471
  return false;
568
472
  }
569
-
570
473
  function handleTypeAliasComments({
571
474
  comment,
572
475
  enclosingNode
@@ -575,10 +478,8 @@ function handleTypeAliasComments({
575
478
  addLeadingComment(enclosingNode, comment);
576
479
  return true;
577
480
  }
578
-
579
481
  return false;
580
482
  }
581
-
582
483
  function handleVariableDeclaratorComments({
583
484
  comment,
584
485
  enclosingNode,
@@ -588,10 +489,8 @@ function handleVariableDeclaratorComments({
588
489
  addLeadingComment(followingNode, comment);
589
490
  return true;
590
491
  }
591
-
592
492
  return false;
593
493
  }
594
-
595
494
  function handleTSFunctionTrailingComments({
596
495
  comment,
597
496
  enclosingNode,
@@ -602,10 +501,8 @@ function handleTSFunctionTrailingComments({
602
501
  addTrailingComment(enclosingNode, comment);
603
502
  return true;
604
503
  }
605
-
606
504
  return false;
607
505
  }
608
-
609
506
  function handleIgnoreComments({
610
507
  comment,
611
508
  enclosingNode,
@@ -617,7 +514,6 @@ function handleIgnoreComments({
617
514
  return true;
618
515
  }
619
516
  }
620
-
621
517
  function handleTSMappedTypeComments({
622
518
  comment,
623
519
  precedingNode,
@@ -627,34 +523,27 @@ function handleTSMappedTypeComments({
627
523
  if (!enclosingNode || enclosingNode.type !== 'TSMappedType') {
628
524
  return false;
629
525
  }
630
-
631
526
  if (followingNode && followingNode.type === 'TSTypeParameter' && followingNode.name) {
632
527
  addLeadingComment(followingNode.name, comment);
633
528
  return true;
634
529
  }
635
-
636
530
  if (precedingNode && precedingNode.type === 'TSTypeParameter' && precedingNode.constraint) {
637
531
  addTrailingComment(precedingNode.constraint, comment);
638
532
  return true;
639
533
  }
640
-
641
534
  return false;
642
535
  }
643
-
644
536
  function isRealFunctionLikeNode(node) {
645
537
  return node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ObjectMethod' || node.type === 'ClassMethod' || node.type === 'TSDeclareFunction' || node.type === 'TSCallSignatureDeclaration' || node.type === 'TSConstructSignatureDeclaration' || node.type === 'TSMethodSignature' || node.type === 'TSConstructorType' || node.type === 'TSFunctionType' || node.type === 'TSDeclareMethod';
646
538
  }
647
-
648
539
  function getCommentChildNodes(node, options) {
649
540
  if ((options.parser === 'typescript' || options.parser === 'flow' || options.parser === 'espree' || options.parser === 'meriyah' || options.parser === '__babel_estree') && node.type === 'MethodDefinition' && node.value && node.value.type === 'FunctionExpression' && getFunctionParameters(node.value).length === 0 && !node.value.returnType && !isNonEmptyArray(node.value.typeParameters) && node.value.body) {
650
541
  return [...(node.decorators || []), node.key, node.value.body];
651
542
  }
652
543
  }
653
-
654
544
  function isTypeCastComment(comment) {
655
545
  return isBlockComment(comment) && comment.value[0] === '*' && /@type\b/.test(comment.value);
656
546
  }
657
-
658
547
  module.exports = {
659
548
  handleOwnLineComment,
660
549
  handleEndOfLineComment,
@@ -3,27 +3,21 @@
3
3
  const {
4
4
  isNonEmptyArray
5
5
  } = require('../common/util.js');
6
-
7
6
  function locStart(node, opts) {
8
7
  const {
9
8
  ignoreDecorators
10
9
  } = opts || {};
11
-
12
10
  if (!ignoreDecorators) {
13
11
  const decorators = node.declaration && node.declaration.decorators || node.decorators;
14
-
15
12
  if (isNonEmptyArray(decorators)) {
16
13
  return locStart(decorators[0]);
17
14
  }
18
15
  }
19
-
20
16
  return node.range ? node.range[0] : node.start;
21
17
  }
22
-
23
18
  function locEnd(node) {
24
19
  return node.range ? node.range[1] : node.end;
25
20
  }
26
-
27
21
  module.exports = {
28
22
  locStart,
29
23
  locEnd
@@ -1,16 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  const handleComments = require('./comments.js');
4
-
5
4
  const {
6
5
  isBlockComment,
7
6
  isLineComment
8
7
  } = require('./utils.js');
9
-
10
8
  function canAttachComment(node) {
11
9
  return node.type && !isBlockComment(node) && !isLineComment(node) && node.type !== 'EmptyStatement' && node.type !== 'TemplateElement' && node.type !== 'Import' && node.type !== 'TSEmptyBodyFunctionExpression';
12
10
  }
13
-
14
11
  module.exports = {
15
12
  canAttachComment,
16
13
  handleComments: {
@@ -3,79 +3,59 @@
3
3
  function isBlockComment(comment) {
4
4
  return comment.type === 'Block' || comment.type === 'CommentBlock' || comment.type === 'MultiLine';
5
5
  }
6
-
7
6
  function isLineComment(comment) {
8
7
  return comment.type === 'Line' || comment.type === 'CommentLine' || comment.type === 'SingleLine' || comment.type === 'HashbangComment' || comment.type === 'HTMLOpen' || comment.type === 'HTMLClose';
9
8
  }
10
-
11
9
  function isCallExpression(node) {
12
10
  return node && (node.type === 'CallExpression' || node.type === 'OptionalCallExpression');
13
11
  }
14
-
15
12
  function isMemberExpression(node) {
16
13
  return node && (node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression');
17
14
  }
18
-
19
15
  const functionParametersCache = new WeakMap();
20
-
21
16
  function getFunctionParameters(node) {
22
17
  if (functionParametersCache.has(node)) {
23
18
  return functionParametersCache.get(node);
24
19
  }
25
-
26
20
  const parameters = [];
27
-
28
21
  if (node.this) {
29
22
  parameters.push(node.this);
30
23
  }
31
-
32
24
  if (Array.isArray(node.parameters)) {
33
25
  parameters.push(...node.parameters);
34
26
  } else if (Array.isArray(node.params)) {
35
27
  parameters.push(...node.params);
36
28
  }
37
-
38
29
  if (node.rest) {
39
30
  parameters.push(node.rest);
40
31
  }
41
-
42
32
  functionParametersCache.set(node, parameters);
43
33
  return parameters;
44
34
  }
45
-
46
35
  const callArgumentsCache = new WeakMap();
47
-
48
36
  function getCallArguments(node) {
49
37
  if (callArgumentsCache.has(node)) {
50
38
  return callArgumentsCache.get(node);
51
39
  }
52
-
53
40
  let args = node.arguments;
54
-
55
41
  if (node.type === 'ImportExpression') {
56
42
  args = [node.source];
57
-
58
43
  if (node.attributes) {
59
44
  args.push(node.attributes);
60
45
  }
61
46
  }
62
-
63
47
  callArgumentsCache.set(node, args);
64
48
  return args;
65
49
  }
66
-
67
50
  function isPrettierIgnoreComment(comment) {
68
51
  return comment.value.trim() === 'prettier-ignore' && !comment.unignore;
69
52
  }
70
-
71
53
  function isCallLikeExpression(node) {
72
54
  return isCallExpression(node) || node.type === 'NewExpression' || node.type === 'ImportExpression';
73
55
  }
74
-
75
56
  function isObjectProperty(node) {
76
57
  return node && (node.type === 'ObjectProperty' || node.type === 'Property' && !node.method && node.kind === 'init');
77
58
  }
78
-
79
59
  module.exports = {
80
60
  getFunctionParameters,
81
61
  getCallArguments,