hermes-transform 0.5.0 → 0.6.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 (74) hide show
  1. package/LICENSE +1 -1
  2. package/dist/detachedNode.js +25 -49
  3. package/dist/detachedNode.js.flow +3 -3
  4. package/dist/generated/TransformCloneSignatures.js.flow +1761 -9
  5. package/dist/generated/TransformReplaceSignatures.js.flow +936 -774
  6. package/dist/generated/node-types.js +1117 -1132
  7. package/dist/generated/node-types.js.flow +26 -1
  8. package/dist/generated/special-case-node-types.js +106 -85
  9. package/dist/generated/special-case-node-types.js.flow +28 -2
  10. package/dist/getVisitorKeys.js +4 -6
  11. package/dist/getVisitorKeys.js.flow +1 -1
  12. package/dist/index.js +13 -18
  13. package/dist/index.js.flow +7 -2
  14. package/dist/transform/Errors.js +8 -116
  15. package/dist/transform/Errors.js.flow +1 -1
  16. package/dist/transform/MutationContext.js +54 -67
  17. package/dist/transform/MutationContext.js.flow +1 -1
  18. package/dist/transform/TransformContext.js +106 -54
  19. package/dist/transform/TransformContext.js.flow +255 -121
  20. package/dist/transform/comments/comments.js +25 -25
  21. package/dist/transform/comments/comments.js.flow +1 -1
  22. package/dist/transform/comments/prettier/common/util.js +46 -47
  23. package/dist/transform/comments/prettier/common/util.js.flow +1 -1
  24. package/dist/transform/comments/prettier/language-js/comments.js +199 -216
  25. package/dist/transform/comments/prettier/language-js/comments.js.flow +1 -1
  26. package/dist/transform/comments/prettier/language-js/loc.js +10 -9
  27. package/dist/transform/comments/prettier/language-js/loc.js.flow +1 -1
  28. package/dist/transform/comments/prettier/language-js/printer-estree.js +7 -6
  29. package/dist/transform/comments/prettier/language-js/printer-estree.js.flow +1 -1
  30. package/dist/transform/comments/prettier/language-js/utils.js +18 -30
  31. package/dist/transform/comments/prettier/language-js/utils.js.flow +1 -1
  32. package/dist/transform/comments/prettier/main/comments.js +225 -298
  33. package/dist/transform/comments/prettier/main/comments.js.flow +1 -1
  34. package/dist/transform/comments/prettier/utils/get-last.js +2 -4
  35. package/dist/transform/comments/prettier/utils/get-last.js.flow +1 -1
  36. package/dist/transform/getTransformedAST.js +85 -101
  37. package/dist/transform/getTransformedAST.js.flow +7 -2
  38. package/dist/transform/mutations/AddLeadingComments.js +15 -22
  39. package/dist/transform/mutations/AddLeadingComments.js.flow +1 -1
  40. package/dist/transform/mutations/AddTrailingComments.js +15 -22
  41. package/dist/transform/mutations/AddTrailingComments.js.flow +1 -1
  42. package/dist/transform/mutations/CloneCommentsTo.js +16 -23
  43. package/dist/transform/mutations/CloneCommentsTo.js.flow +1 -1
  44. package/dist/transform/mutations/InsertStatement.js +27 -30
  45. package/dist/transform/mutations/InsertStatement.js.flow +1 -1
  46. package/dist/transform/mutations/RemoveComment.js +25 -43
  47. package/dist/transform/mutations/RemoveComment.js.flow +1 -1
  48. package/dist/transform/mutations/RemoveNode.js +185 -0
  49. package/dist/transform/mutations/RemoveNode.js.flow +279 -0
  50. package/dist/transform/mutations/RemoveStatement.js +7 -9
  51. package/dist/transform/mutations/RemoveStatement.js.flow +1 -1
  52. package/dist/transform/mutations/ReplaceNode.js +36 -44
  53. package/dist/transform/mutations/ReplaceNode.js.flow +1 -1
  54. package/dist/transform/mutations/ReplaceStatementWithMany.js +11 -13
  55. package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +1 -1
  56. package/dist/transform/mutations/utils/arrayUtils.js +2 -14
  57. package/dist/transform/mutations/utils/arrayUtils.js.flow +1 -1
  58. package/dist/transform/mutations/utils/getStatementParent.js +23 -28
  59. package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -2
  60. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +7 -24
  61. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +1 -1
  62. package/dist/transform/transform.js +20 -24
  63. package/dist/transform/transform.js.flow +12 -8
  64. package/dist/traverse/NodeEventGenerator.js +91 -165
  65. package/dist/traverse/NodeEventGenerator.js.flow +1 -1
  66. package/dist/traverse/SafeEmitter.js +20 -38
  67. package/dist/traverse/SafeEmitter.js.flow +1 -1
  68. package/dist/traverse/SimpleTraverser.js +67 -98
  69. package/dist/traverse/SimpleTraverser.js.flow +4 -1
  70. package/dist/traverse/esquery.js +6 -6
  71. package/dist/traverse/esquery.js.flow +1 -1
  72. package/dist/traverse/traverse.js +39 -51
  73. package/dist/traverse/traverse.js.flow +1 -1
  74. package/package.json +4 -3
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -8,43 +8,34 @@
8
8
  */
9
9
  'use strict';
10
10
 
11
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
-
13
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
-
15
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
-
17
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
-
19
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
-
21
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
22
-
23
- var _require = require('../common/util.js'),
24
- getLast = _require.getLast,
25
- hasNewline = _require.hasNewline,
26
- addLeadingComment = _require.addLeadingComment,
27
- getNextNonSpaceNonCommentCharacterIndexWithStartIndex = _require.getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
28
- getNextNonSpaceNonCommentCharacterIndex = _require.getNextNonSpaceNonCommentCharacterIndex,
29
- hasNewlineInRange = _require.hasNewlineInRange,
30
- addTrailingComment = _require.addTrailingComment,
31
- addDanglingComment = _require.addDanglingComment,
32
- getNextNonSpaceNonCommentCharacter = _require.getNextNonSpaceNonCommentCharacter,
33
- isNonEmptyArray = _require.isNonEmptyArray;
34
-
35
- var _require2 = require('./utils.js'),
36
- isBlockComment = _require2.isBlockComment,
37
- getFunctionParameters = _require2.getFunctionParameters,
38
- isPrettierIgnoreComment = _require2.isPrettierIgnoreComment,
39
- isCallLikeExpression = _require2.isCallLikeExpression,
40
- getCallArguments = _require2.getCallArguments,
41
- isCallExpression = _require2.isCallExpression,
42
- isMemberExpression = _require2.isMemberExpression,
43
- isObjectProperty = _require2.isObjectProperty;
44
-
45
- var _require3 = require('./loc.js'),
46
- locStart = _require3.locStart,
47
- locEnd = _require3.locEnd;
11
+ const {
12
+ getLast,
13
+ hasNewline,
14
+ addLeadingComment,
15
+ getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
16
+ getNextNonSpaceNonCommentCharacterIndex,
17
+ hasNewlineInRange,
18
+ addTrailingComment,
19
+ addDanglingComment,
20
+ getNextNonSpaceNonCommentCharacter,
21
+ isNonEmptyArray
22
+ } = require('../common/util.js');
23
+
24
+ const {
25
+ isBlockComment,
26
+ getFunctionParameters,
27
+ isPrettierIgnoreComment,
28
+ isCallLikeExpression,
29
+ getCallArguments,
30
+ isCallExpression,
31
+ isMemberExpression,
32
+ isObjectProperty
33
+ } = require('./utils.js');
34
+
35
+ const {
36
+ locStart,
37
+ locEnd
38
+ } = require('./loc.js');
48
39
  /**
49
40
  * @typedef {import("./types/estree").Node} Node
50
41
  * @typedef {import("./types/estree").Comment} Comment
@@ -68,9 +59,7 @@ var _require3 = require('./loc.js'),
68
59
 
69
60
 
70
61
  function handleOwnLineComment(context) {
71
- return [handleIgnoreComments, handleLastFunctionArgComments, handleMemberExpressionComments, handleIfStatementComments, handleWhileComments, handleTryStatementComments, handleClassComments, handleImportSpecifierComments, handleForComments, handleUnionTypeComments, handleOnlyComments, handleImportDeclarationComments, handleAssignmentPatternComments, handleMethodNameComments, handleLabeledStatementComments].some(function (fn) {
72
- return fn(context);
73
- });
62
+ return [handleIgnoreComments, handleLastFunctionArgComments, handleMemberExpressionComments, handleIfStatementComments, handleWhileComments, handleTryStatementComments, handleClassComments, handleImportSpecifierComments, handleForComments, handleUnionTypeComments, handleOnlyComments, handleImportDeclarationComments, handleAssignmentPatternComments, handleMethodNameComments, handleLabeledStatementComments].some(fn => fn(context));
74
63
  }
75
64
  /**
76
65
  * @param {CommentContext} context
@@ -79,9 +68,7 @@ function handleOwnLineComment(context) {
79
68
 
80
69
 
81
70
  function handleEndOfLineComment(context) {
82
- return [handleClosureTypeCastComments, handleLastFunctionArgComments, handleConditionalExpressionComments, handleImportSpecifierComments, handleIfStatementComments, handleWhileComments, handleTryStatementComments, handleClassComments, handleLabeledStatementComments, handleCallExpressionComments, handlePropertyComments, handleOnlyComments, handleTypeAliasComments, handleVariableDeclaratorComments].some(function (fn) {
83
- return fn(context);
84
- });
71
+ return [handleClosureTypeCastComments, handleLastFunctionArgComments, handleConditionalExpressionComments, handleImportSpecifierComments, handleIfStatementComments, handleWhileComments, handleTryStatementComments, handleClassComments, handleLabeledStatementComments, handleCallExpressionComments, handlePropertyComments, handleOnlyComments, handleTypeAliasComments, handleVariableDeclaratorComments].some(fn => fn(context));
85
72
  }
86
73
  /**
87
74
  * @param {CommentContext} context
@@ -90,9 +77,7 @@ function handleEndOfLineComment(context) {
90
77
 
91
78
 
92
79
  function handleRemainingComment(context) {
93
- return [handleIgnoreComments, handleIfStatementComments, handleWhileComments, handleObjectPropertyAssignment, handleCommentInEmptyParens, handleMethodNameComments, handleOnlyComments, handleCommentAfterArrowParams, handleFunctionNameComments, handleTSMappedTypeComments, handleBreakAndContinueStatementComments, handleTSFunctionTrailingComments].some(function (fn) {
94
- return fn(context);
95
- });
80
+ return [handleIgnoreComments, handleIfStatementComments, handleWhileComments, handleObjectPropertyAssignment, handleCommentInEmptyParens, handleMethodNameComments, handleOnlyComments, handleCommentAfterArrowParams, handleFunctionNameComments, handleTSMappedTypeComments, handleBreakAndContinueStatementComments, handleTSFunctionTrailingComments].some(fn => fn(context));
96
81
  }
97
82
  /**
98
83
  * @param {Node} node
@@ -102,10 +87,9 @@ function handleRemainingComment(context) {
102
87
 
103
88
  function addBlockStatementFirstComment(node, comment) {
104
89
  // @ts-expect-error
105
- var firstNonEmptyNode = (node.body || node.properties).find(function (_ref) {
106
- var type = _ref.type;
107
- return type !== 'EmptyStatement';
108
- });
90
+ const firstNonEmptyNode = (node.body || node.properties).find(({
91
+ type
92
+ }) => type !== 'EmptyStatement');
109
93
 
110
94
  if (firstNonEmptyNode) {
111
95
  addLeadingComment(firstNonEmptyNode, comment);
@@ -127,10 +111,10 @@ function addBlockOrNotComment(node, comment) {
127
111
  }
128
112
  }
129
113
 
130
- function handleClosureTypeCastComments(_ref2) {
131
- var comment = _ref2.comment,
132
- followingNode = _ref2.followingNode;
133
-
114
+ function handleClosureTypeCastComments({
115
+ comment,
116
+ followingNode
117
+ }) {
134
118
  if (followingNode && isTypeCastComment(comment)) {
135
119
  addLeadingComment(followingNode, comment);
136
120
  return true;
@@ -155,13 +139,13 @@ function handleClosureTypeCastComments(_ref2) {
155
139
  // }
156
140
 
157
141
 
158
- function handleIfStatementComments(_ref3) {
159
- var comment = _ref3.comment,
160
- precedingNode = _ref3.precedingNode,
161
- enclosingNode = _ref3.enclosingNode,
162
- followingNode = _ref3.followingNode,
163
- text = _ref3.text;
164
-
142
+ function handleIfStatementComments({
143
+ comment,
144
+ precedingNode,
145
+ enclosingNode,
146
+ followingNode,
147
+ text
148
+ }) {
165
149
  if (!enclosingNode || enclosingNode.type !== 'IfStatement' || !followingNode) {
166
150
  return false;
167
151
  } // We unfortunately have no way using the AST or location of nodes to know
@@ -171,7 +155,7 @@ function handleIfStatementComments(_ref3) {
171
155
  // it is a ).
172
156
 
173
157
 
174
- var nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment, locEnd);
158
+ const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment, locEnd);
175
159
 
176
160
  if (nextCharacter === ')') {
177
161
  addTrailingComment(precedingNode, comment);
@@ -214,13 +198,13 @@ function handleIfStatementComments(_ref3) {
214
198
  return false;
215
199
  }
216
200
 
217
- function handleWhileComments(_ref4) {
218
- var comment = _ref4.comment,
219
- precedingNode = _ref4.precedingNode,
220
- enclosingNode = _ref4.enclosingNode,
221
- followingNode = _ref4.followingNode,
222
- text = _ref4.text;
223
-
201
+ function handleWhileComments({
202
+ comment,
203
+ precedingNode,
204
+ enclosingNode,
205
+ followingNode,
206
+ text
207
+ }) {
224
208
  if (!enclosingNode || enclosingNode.type !== 'WhileStatement' || !followingNode) {
225
209
  return false;
226
210
  } // We unfortunately have no way using the AST or location of nodes to know
@@ -230,7 +214,7 @@ function handleWhileComments(_ref4) {
230
214
  // it is a ).
231
215
 
232
216
 
233
- var nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment, locEnd);
217
+ const nextCharacter = getNextNonSpaceNonCommentCharacter(text, comment, locEnd);
234
218
 
235
219
  if (nextCharacter === ')') {
236
220
  addTrailingComment(precedingNode, comment);
@@ -251,12 +235,12 @@ function handleWhileComments(_ref4) {
251
235
  } // Same as IfStatement but for TryStatement
252
236
 
253
237
 
254
- function handleTryStatementComments(_ref5) {
255
- var comment = _ref5.comment,
256
- precedingNode = _ref5.precedingNode,
257
- enclosingNode = _ref5.enclosingNode,
258
- followingNode = _ref5.followingNode;
259
-
238
+ function handleTryStatementComments({
239
+ comment,
240
+ precedingNode,
241
+ enclosingNode,
242
+ followingNode
243
+ }) {
260
244
  if (!enclosingNode || enclosingNode.type !== 'TryStatement' && enclosingNode.type !== 'CatchClause' || !followingNode) {
261
245
  return false;
262
246
  }
@@ -284,11 +268,11 @@ function handleTryStatementComments(_ref5) {
284
268
  return false;
285
269
  }
286
270
 
287
- function handleMemberExpressionComments(_ref6) {
288
- var comment = _ref6.comment,
289
- enclosingNode = _ref6.enclosingNode,
290
- followingNode = _ref6.followingNode;
291
-
271
+ function handleMemberExpressionComments({
272
+ comment,
273
+ enclosingNode,
274
+ followingNode
275
+ }) {
292
276
  if (isMemberExpression(enclosingNode) && followingNode && followingNode.type === 'Identifier') {
293
277
  addLeadingComment(enclosingNode, comment);
294
278
  return true;
@@ -297,13 +281,14 @@ function handleMemberExpressionComments(_ref6) {
297
281
  return false;
298
282
  }
299
283
 
300
- function handleConditionalExpressionComments(_ref7) {
301
- var comment = _ref7.comment,
302
- precedingNode = _ref7.precedingNode,
303
- enclosingNode = _ref7.enclosingNode,
304
- followingNode = _ref7.followingNode,
305
- text = _ref7.text;
306
- var isSameLineAsPrecedingNode = precedingNode && !hasNewlineInRange(text, locEnd(precedingNode), locStart(comment));
284
+ function handleConditionalExpressionComments({
285
+ comment,
286
+ precedingNode,
287
+ enclosingNode,
288
+ followingNode,
289
+ text
290
+ }) {
291
+ const isSameLineAsPrecedingNode = precedingNode && !hasNewlineInRange(text, locEnd(precedingNode), locStart(comment));
307
292
 
308
293
  if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && (enclosingNode.type === 'ConditionalExpression' || enclosingNode.type === 'TSConditionalType') && followingNode) {
309
294
  addLeadingComment(followingNode, comment);
@@ -313,11 +298,11 @@ function handleConditionalExpressionComments(_ref7) {
313
298
  return false;
314
299
  }
315
300
 
316
- function handleObjectPropertyAssignment(_ref8) {
317
- var comment = _ref8.comment,
318
- precedingNode = _ref8.precedingNode,
319
- enclosingNode = _ref8.enclosingNode;
320
-
301
+ function handleObjectPropertyAssignment({
302
+ comment,
303
+ precedingNode,
304
+ enclosingNode
305
+ }) {
321
306
  if (isObjectProperty(enclosingNode) && enclosingNode.shorthand && enclosingNode.key === precedingNode && enclosingNode.value.type === 'AssignmentPattern') {
322
307
  addTrailingComment(enclosingNode.value.left, comment);
323
308
  return true;
@@ -326,12 +311,12 @@ function handleObjectPropertyAssignment(_ref8) {
326
311
  return false;
327
312
  }
328
313
 
329
- function handleClassComments(_ref9) {
330
- var comment = _ref9.comment,
331
- precedingNode = _ref9.precedingNode,
332
- enclosingNode = _ref9.enclosingNode,
333
- followingNode = _ref9.followingNode;
334
-
314
+ function handleClassComments({
315
+ comment,
316
+ precedingNode,
317
+ enclosingNode,
318
+ followingNode
319
+ }) {
335
320
  if (enclosingNode && (enclosingNode.type === 'ClassDeclaration' || enclosingNode.type === 'ClassExpression' || enclosingNode.type === 'DeclareClass' || enclosingNode.type === 'DeclareInterface' || enclosingNode.type === 'InterfaceDeclaration' || enclosingNode.type === 'TSInterfaceDeclaration')) {
336
321
  if (isNonEmptyArray(enclosingNode.decorators) && !(followingNode && followingNode.type === 'Decorator')) {
337
322
  addTrailingComment(getLast(enclosingNode.decorators), comment);
@@ -346,9 +331,7 @@ function handleClassComments(_ref9) {
346
331
 
347
332
 
348
333
  if (followingNode) {
349
- for (var _i = 0, _arr = ['implements', 'extends', 'mixins']; _i < _arr.length; _i++) {
350
- var prop = _arr[_i];
351
-
334
+ for (const prop of ['implements', 'extends', 'mixins']) {
352
335
  if (enclosingNode[prop] && followingNode === enclosingNode[prop][0]) {
353
336
  if (precedingNode && (precedingNode === enclosingNode.id || precedingNode === enclosingNode.typeParameters || precedingNode === enclosingNode.superClass)) {
354
337
  addTrailingComment(precedingNode, comment);
@@ -365,12 +348,12 @@ function handleClassComments(_ref9) {
365
348
  return false;
366
349
  }
367
350
 
368
- function handleMethodNameComments(_ref10) {
369
- var comment = _ref10.comment,
370
- precedingNode = _ref10.precedingNode,
371
- enclosingNode = _ref10.enclosingNode,
372
- text = _ref10.text;
373
-
351
+ function handleMethodNameComments({
352
+ comment,
353
+ precedingNode,
354
+ enclosingNode,
355
+ text
356
+ }) {
374
357
  // This is only needed for estree parsers (flow, typescript) to attach
375
358
  // after a method name:
376
359
  // obj = { fn /*comment*/() {} };
@@ -392,12 +375,12 @@ function handleMethodNameComments(_ref10) {
392
375
  return false;
393
376
  }
394
377
 
395
- function handleFunctionNameComments(_ref11) {
396
- var comment = _ref11.comment,
397
- precedingNode = _ref11.precedingNode,
398
- enclosingNode = _ref11.enclosingNode,
399
- text = _ref11.text;
400
-
378
+ function handleFunctionNameComments({
379
+ comment,
380
+ precedingNode,
381
+ enclosingNode,
382
+ text
383
+ }) {
401
384
  if (getNextNonSpaceNonCommentCharacter(text, comment, locEnd) !== '(') {
402
385
  return false;
403
386
  }
@@ -410,16 +393,16 @@ function handleFunctionNameComments(_ref11) {
410
393
  return false;
411
394
  }
412
395
 
413
- function handleCommentAfterArrowParams(_ref12) {
414
- var comment = _ref12.comment,
415
- enclosingNode = _ref12.enclosingNode,
416
- text = _ref12.text;
417
-
396
+ function handleCommentAfterArrowParams({
397
+ comment,
398
+ enclosingNode,
399
+ text
400
+ }) {
418
401
  if (!(enclosingNode && enclosingNode.type === 'ArrowFunctionExpression')) {
419
402
  return false;
420
403
  }
421
404
 
422
- var index = getNextNonSpaceNonCommentCharacterIndex(text, comment, locEnd);
405
+ const index = getNextNonSpaceNonCommentCharacterIndex(text, comment, locEnd);
423
406
 
424
407
  if (index !== false && text.slice(index, index + 2) === '=>') {
425
408
  addDanglingComment(enclosingNode, comment);
@@ -429,11 +412,11 @@ function handleCommentAfterArrowParams(_ref12) {
429
412
  return false;
430
413
  }
431
414
 
432
- function handleCommentInEmptyParens(_ref13) {
433
- var comment = _ref13.comment,
434
- enclosingNode = _ref13.enclosingNode,
435
- text = _ref13.text;
436
-
415
+ function handleCommentInEmptyParens({
416
+ comment,
417
+ enclosingNode,
418
+ text
419
+ }) {
437
420
  if (getNextNonSpaceNonCommentCharacter(text, comment, locEnd) !== ')') {
438
421
  return false;
439
422
  } // Only add dangling comments to fix the case when no params are present,
@@ -453,13 +436,13 @@ function handleCommentInEmptyParens(_ref13) {
453
436
  return false;
454
437
  }
455
438
 
456
- function handleLastFunctionArgComments(_ref14) {
457
- var comment = _ref14.comment,
458
- precedingNode = _ref14.precedingNode,
459
- enclosingNode = _ref14.enclosingNode,
460
- followingNode = _ref14.followingNode,
461
- text = _ref14.text;
462
-
439
+ function handleLastFunctionArgComments({
440
+ comment,
441
+ precedingNode,
442
+ enclosingNode,
443
+ followingNode,
444
+ text
445
+ }) {
463
446
  // Flow function type definitions
464
447
  if (precedingNode && precedingNode.type === 'FunctionTypeParam' && enclosingNode && enclosingNode.type === 'FunctionTypeAnnotation' && followingNode && followingNode.type !== 'FunctionTypeParam') {
465
448
  addTrailingComment(precedingNode, comment);
@@ -473,16 +456,16 @@ function handleLastFunctionArgComments(_ref14) {
473
456
  }
474
457
 
475
458
  if (enclosingNode && enclosingNode.type === 'FunctionDeclaration' && followingNode && followingNode.type === 'BlockStatement') {
476
- var functionParamRightParenIndex = function () {
477
- var parameters = getFunctionParameters(enclosingNode);
459
+ const functionParamRightParenIndex = (() => {
460
+ const parameters = getFunctionParameters(enclosingNode);
478
461
 
479
462
  if (parameters.length > 0) {
480
463
  return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(getLast(parameters)));
481
464
  }
482
465
 
483
- var functionParamLeftParenIndex = getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(enclosingNode.id));
466
+ const functionParamLeftParenIndex = getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(enclosingNode.id));
484
467
  return functionParamLeftParenIndex !== false && getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, functionParamLeftParenIndex + 1);
485
- }();
468
+ })();
486
469
 
487
470
  if (locStart(comment) > functionParamRightParenIndex) {
488
471
  addBlockStatementFirstComment(followingNode, comment);
@@ -493,10 +476,10 @@ function handleLastFunctionArgComments(_ref14) {
493
476
  return false;
494
477
  }
495
478
 
496
- function handleImportSpecifierComments(_ref15) {
497
- var comment = _ref15.comment,
498
- enclosingNode = _ref15.enclosingNode;
499
-
479
+ function handleImportSpecifierComments({
480
+ comment,
481
+ enclosingNode
482
+ }) {
500
483
  if (enclosingNode && enclosingNode.type === 'ImportSpecifier') {
501
484
  addLeadingComment(enclosingNode, comment);
502
485
  return true;
@@ -505,10 +488,10 @@ function handleImportSpecifierComments(_ref15) {
505
488
  return false;
506
489
  }
507
490
 
508
- function handleLabeledStatementComments(_ref16) {
509
- var comment = _ref16.comment,
510
- enclosingNode = _ref16.enclosingNode;
511
-
491
+ function handleLabeledStatementComments({
492
+ comment,
493
+ enclosingNode
494
+ }) {
512
495
  if (enclosingNode && enclosingNode.type === 'LabeledStatement') {
513
496
  addLeadingComment(enclosingNode, comment);
514
497
  return true;
@@ -517,10 +500,10 @@ function handleLabeledStatementComments(_ref16) {
517
500
  return false;
518
501
  }
519
502
 
520
- function handleBreakAndContinueStatementComments(_ref17) {
521
- var comment = _ref17.comment,
522
- enclosingNode = _ref17.enclosingNode;
523
-
503
+ function handleBreakAndContinueStatementComments({
504
+ comment,
505
+ enclosingNode
506
+ }) {
524
507
  if (enclosingNode && (enclosingNode.type === 'ContinueStatement' || enclosingNode.type === 'BreakStatement') && !enclosingNode.label) {
525
508
  addTrailingComment(enclosingNode, comment);
526
509
  return true;
@@ -529,11 +512,11 @@ function handleBreakAndContinueStatementComments(_ref17) {
529
512
  return false;
530
513
  }
531
514
 
532
- function handleCallExpressionComments(_ref18) {
533
- var comment = _ref18.comment,
534
- precedingNode = _ref18.precedingNode,
535
- enclosingNode = _ref18.enclosingNode;
536
-
515
+ function handleCallExpressionComments({
516
+ comment,
517
+ precedingNode,
518
+ enclosingNode
519
+ }) {
537
520
  if (isCallExpression(enclosingNode) && precedingNode && enclosingNode.callee === precedingNode && enclosingNode.arguments.length > 0) {
538
521
  addLeadingComment(enclosingNode.arguments[0], comment);
539
522
  return true;
@@ -542,12 +525,12 @@ function handleCallExpressionComments(_ref18) {
542
525
  return false;
543
526
  }
544
527
 
545
- function handleUnionTypeComments(_ref19) {
546
- var comment = _ref19.comment,
547
- precedingNode = _ref19.precedingNode,
548
- enclosingNode = _ref19.enclosingNode,
549
- followingNode = _ref19.followingNode;
550
-
528
+ function handleUnionTypeComments({
529
+ comment,
530
+ precedingNode,
531
+ enclosingNode,
532
+ followingNode
533
+ }) {
551
534
  if (enclosingNode && (enclosingNode.type === 'UnionTypeAnnotation' || enclosingNode.type === 'TSUnionType')) {
552
535
  if (isPrettierIgnoreComment(comment)) {
553
536
  followingNode.prettierIgnore = true;
@@ -570,10 +553,10 @@ function handleUnionTypeComments(_ref19) {
570
553
  return false;
571
554
  }
572
555
 
573
- function handlePropertyComments(_ref20) {
574
- var comment = _ref20.comment,
575
- enclosingNode = _ref20.enclosingNode;
576
-
556
+ function handlePropertyComments({
557
+ comment,
558
+ enclosingNode
559
+ }) {
577
560
  if (isObjectProperty(enclosingNode)) {
578
561
  addLeadingComment(enclosingNode, comment);
579
562
  return true;
@@ -582,13 +565,13 @@ function handlePropertyComments(_ref20) {
582
565
  return false;
583
566
  }
584
567
 
585
- function handleOnlyComments(_ref21) {
586
- var comment = _ref21.comment,
587
- enclosingNode = _ref21.enclosingNode,
588
- followingNode = _ref21.followingNode,
589
- ast = _ref21.ast,
590
- isLastComment = _ref21.isLastComment;
591
-
568
+ function handleOnlyComments({
569
+ comment,
570
+ enclosingNode,
571
+ followingNode,
572
+ ast,
573
+ isLastComment
574
+ }) {
592
575
  // With Flow the enclosingNode is undefined so use the AST instead.
593
576
  if (ast && ast.body && ast.body.length === 0) {
594
577
  if (isLastComment) {
@@ -618,10 +601,10 @@ function handleOnlyComments(_ref21) {
618
601
  return false;
619
602
  }
620
603
 
621
- function handleForComments(_ref22) {
622
- var comment = _ref22.comment,
623
- enclosingNode = _ref22.enclosingNode;
624
-
604
+ function handleForComments({
605
+ comment,
606
+ enclosingNode
607
+ }) {
625
608
  if (enclosingNode && (enclosingNode.type === 'ForInStatement' || enclosingNode.type === 'ForOfStatement')) {
626
609
  addLeadingComment(enclosingNode, comment);
627
610
  return true;
@@ -630,12 +613,12 @@ function handleForComments(_ref22) {
630
613
  return false;
631
614
  }
632
615
 
633
- function handleImportDeclarationComments(_ref23) {
634
- var comment = _ref23.comment,
635
- precedingNode = _ref23.precedingNode,
636
- enclosingNode = _ref23.enclosingNode,
637
- text = _ref23.text;
638
-
616
+ function handleImportDeclarationComments({
617
+ comment,
618
+ precedingNode,
619
+ enclosingNode,
620
+ text
621
+ }) {
639
622
  if (precedingNode && precedingNode.type === 'ImportSpecifier' && enclosingNode && enclosingNode.type === 'ImportDeclaration' && hasNewline(text, locEnd(comment))) {
640
623
  addTrailingComment(precedingNode, comment);
641
624
  return true;
@@ -644,10 +627,10 @@ function handleImportDeclarationComments(_ref23) {
644
627
  return false;
645
628
  }
646
629
 
647
- function handleAssignmentPatternComments(_ref24) {
648
- var comment = _ref24.comment,
649
- enclosingNode = _ref24.enclosingNode;
650
-
630
+ function handleAssignmentPatternComments({
631
+ comment,
632
+ enclosingNode
633
+ }) {
651
634
  if (enclosingNode && enclosingNode.type === 'AssignmentPattern') {
652
635
  addLeadingComment(enclosingNode, comment);
653
636
  return true;
@@ -656,10 +639,10 @@ function handleAssignmentPatternComments(_ref24) {
656
639
  return false;
657
640
  }
658
641
 
659
- function handleTypeAliasComments(_ref25) {
660
- var comment = _ref25.comment,
661
- enclosingNode = _ref25.enclosingNode;
662
-
642
+ function handleTypeAliasComments({
643
+ comment,
644
+ enclosingNode
645
+ }) {
663
646
  if (enclosingNode && enclosingNode.type === 'TypeAlias') {
664
647
  addLeadingComment(enclosingNode, comment);
665
648
  return true;
@@ -668,11 +651,11 @@ function handleTypeAliasComments(_ref25) {
668
651
  return false;
669
652
  }
670
653
 
671
- function handleVariableDeclaratorComments(_ref26) {
672
- var comment = _ref26.comment,
673
- enclosingNode = _ref26.enclosingNode,
674
- followingNode = _ref26.followingNode;
675
-
654
+ function handleVariableDeclaratorComments({
655
+ comment,
656
+ enclosingNode,
657
+ followingNode
658
+ }) {
676
659
  if (enclosingNode && (enclosingNode.type === 'VariableDeclarator' || enclosingNode.type === 'AssignmentExpression') && followingNode && (followingNode.type === 'ObjectExpression' || followingNode.type === 'ArrayExpression' || followingNode.type === 'TemplateLiteral' || followingNode.type === 'TaggedTemplateExpression' || isBlockComment(comment))) {
677
660
  addLeadingComment(followingNode, comment);
678
661
  return true;
@@ -681,12 +664,12 @@ function handleVariableDeclaratorComments(_ref26) {
681
664
  return false;
682
665
  }
683
666
 
684
- function handleTSFunctionTrailingComments(_ref27) {
685
- var comment = _ref27.comment,
686
- enclosingNode = _ref27.enclosingNode,
687
- followingNode = _ref27.followingNode,
688
- text = _ref27.text;
689
-
667
+ function handleTSFunctionTrailingComments({
668
+ comment,
669
+ enclosingNode,
670
+ followingNode,
671
+ text
672
+ }) {
690
673
  if (!followingNode && enclosingNode && (enclosingNode.type === 'TSMethodSignature' || enclosingNode.type === 'TSDeclareFunction' || enclosingNode.type === 'TSAbstractMethodDefinition') && getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === ';') {
691
674
  addTrailingComment(enclosingNode, comment);
692
675
  return true;
@@ -695,11 +678,11 @@ function handleTSFunctionTrailingComments(_ref27) {
695
678
  return false;
696
679
  }
697
680
 
698
- function handleIgnoreComments(_ref28) {
699
- var comment = _ref28.comment,
700
- enclosingNode = _ref28.enclosingNode,
701
- followingNode = _ref28.followingNode;
702
-
681
+ function handleIgnoreComments({
682
+ comment,
683
+ enclosingNode,
684
+ followingNode
685
+ }) {
703
686
  if (isPrettierIgnoreComment(comment) && enclosingNode && enclosingNode.type === 'TSMappedType' && followingNode && followingNode.type === 'TSTypeParameter' && followingNode.constraint) {
704
687
  enclosingNode.prettierIgnore = true;
705
688
  comment.unignore = true;
@@ -707,12 +690,12 @@ function handleIgnoreComments(_ref28) {
707
690
  }
708
691
  }
709
692
 
710
- function handleTSMappedTypeComments(_ref29) {
711
- var comment = _ref29.comment,
712
- precedingNode = _ref29.precedingNode,
713
- enclosingNode = _ref29.enclosingNode,
714
- followingNode = _ref29.followingNode;
715
-
693
+ function handleTSMappedTypeComments({
694
+ comment,
695
+ precedingNode,
696
+ enclosingNode,
697
+ followingNode
698
+ }) {
716
699
  if (!enclosingNode || enclosingNode.type !== 'TSMappedType') {
717
700
  return false;
718
701
  }
@@ -753,7 +736,7 @@ function getCommentChildNodes(node, options) {
753
736
  // }
754
737
  // }
755
738
  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) {
756
- return [].concat(_toConsumableArray(node.decorators || []), [node.key, node.value.body]);
739
+ return [...(node.decorators || []), node.key, node.value.body];
757
740
  }
758
741
  }
759
742
  /**
@@ -770,8 +753,8 @@ function isTypeCastComment(comment) {
770
753
  }
771
754
 
772
755
  module.exports = {
773
- handleOwnLineComment: handleOwnLineComment,
774
- handleEndOfLineComment: handleEndOfLineComment,
775
- handleRemainingComment: handleRemainingComment,
776
- getCommentChildNodes: getCommentChildNodes
756
+ handleOwnLineComment,
757
+ handleEndOfLineComment,
758
+ handleRemainingComment,
759
+ getCommentChildNodes
777
760
  };