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.
- package/LICENSE +1 -1
- package/dist/detachedNode.js +25 -49
- package/dist/detachedNode.js.flow +3 -3
- package/dist/generated/TransformCloneSignatures.js.flow +1761 -9
- package/dist/generated/TransformReplaceSignatures.js.flow +936 -774
- package/dist/generated/node-types.js +1117 -1132
- package/dist/generated/node-types.js.flow +26 -1
- package/dist/generated/special-case-node-types.js +106 -85
- package/dist/generated/special-case-node-types.js.flow +28 -2
- package/dist/getVisitorKeys.js +4 -6
- package/dist/getVisitorKeys.js.flow +1 -1
- package/dist/index.js +13 -18
- package/dist/index.js.flow +7 -2
- package/dist/transform/Errors.js +8 -116
- package/dist/transform/Errors.js.flow +1 -1
- package/dist/transform/MutationContext.js +54 -67
- package/dist/transform/MutationContext.js.flow +1 -1
- package/dist/transform/TransformContext.js +106 -54
- package/dist/transform/TransformContext.js.flow +255 -121
- package/dist/transform/comments/comments.js +25 -25
- package/dist/transform/comments/comments.js.flow +1 -1
- package/dist/transform/comments/prettier/common/util.js +46 -47
- package/dist/transform/comments/prettier/common/util.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/comments.js +199 -216
- package/dist/transform/comments/prettier/language-js/comments.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/loc.js +10 -9
- package/dist/transform/comments/prettier/language-js/loc.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/printer-estree.js +7 -6
- package/dist/transform/comments/prettier/language-js/printer-estree.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/utils.js +18 -30
- package/dist/transform/comments/prettier/language-js/utils.js.flow +1 -1
- package/dist/transform/comments/prettier/main/comments.js +225 -298
- package/dist/transform/comments/prettier/main/comments.js.flow +1 -1
- package/dist/transform/comments/prettier/utils/get-last.js +2 -4
- package/dist/transform/comments/prettier/utils/get-last.js.flow +1 -1
- package/dist/transform/getTransformedAST.js +85 -101
- package/dist/transform/getTransformedAST.js.flow +7 -2
- package/dist/transform/mutations/AddLeadingComments.js +15 -22
- package/dist/transform/mutations/AddLeadingComments.js.flow +1 -1
- package/dist/transform/mutations/AddTrailingComments.js +15 -22
- package/dist/transform/mutations/AddTrailingComments.js.flow +1 -1
- package/dist/transform/mutations/CloneCommentsTo.js +16 -23
- package/dist/transform/mutations/CloneCommentsTo.js.flow +1 -1
- package/dist/transform/mutations/InsertStatement.js +27 -30
- package/dist/transform/mutations/InsertStatement.js.flow +1 -1
- package/dist/transform/mutations/RemoveComment.js +25 -43
- package/dist/transform/mutations/RemoveComment.js.flow +1 -1
- package/dist/transform/mutations/RemoveNode.js +185 -0
- package/dist/transform/mutations/RemoveNode.js.flow +279 -0
- package/dist/transform/mutations/RemoveStatement.js +7 -9
- package/dist/transform/mutations/RemoveStatement.js.flow +1 -1
- package/dist/transform/mutations/ReplaceNode.js +36 -44
- package/dist/transform/mutations/ReplaceNode.js.flow +1 -1
- package/dist/transform/mutations/ReplaceStatementWithMany.js +11 -13
- package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +1 -1
- package/dist/transform/mutations/utils/arrayUtils.js +2 -14
- package/dist/transform/mutations/utils/arrayUtils.js.flow +1 -1
- package/dist/transform/mutations/utils/getStatementParent.js +23 -28
- package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -2
- package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +7 -24
- package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +1 -1
- package/dist/transform/transform.js +20 -24
- package/dist/transform/transform.js.flow +12 -8
- package/dist/traverse/NodeEventGenerator.js +91 -165
- package/dist/traverse/NodeEventGenerator.js.flow +1 -1
- package/dist/traverse/SafeEmitter.js +20 -38
- package/dist/traverse/SafeEmitter.js.flow +1 -1
- package/dist/traverse/SimpleTraverser.js +67 -98
- package/dist/traverse/SimpleTraverser.js.flow +4 -1
- package/dist/traverse/esquery.js +6 -6
- package/dist/traverse/esquery.js.flow +1 -1
- package/dist/traverse/traverse.js +39 -51
- package/dist/traverse/traverse.js.flow +1 -1
- package/package.json +4 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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(
|
|
131
|
-
|
|
132
|
-
|
|
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(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
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(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
|
|
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(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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 (
|
|
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(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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(
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
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(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
477
|
-
|
|
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
|
-
|
|
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(
|
|
497
|
-
|
|
498
|
-
|
|
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(
|
|
509
|
-
|
|
510
|
-
|
|
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(
|
|
521
|
-
|
|
522
|
-
|
|
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(
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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(
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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(
|
|
574
|
-
|
|
575
|
-
|
|
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(
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
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(
|
|
622
|
-
|
|
623
|
-
|
|
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(
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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(
|
|
648
|
-
|
|
649
|
-
|
|
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(
|
|
660
|
-
|
|
661
|
-
|
|
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(
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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(
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
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(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
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(
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
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 [
|
|
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
|
|
774
|
-
handleEndOfLineComment
|
|
775
|
-
handleRemainingComment
|
|
776
|
-
getCommentChildNodes
|
|
756
|
+
handleOwnLineComment,
|
|
757
|
+
handleEndOfLineComment,
|
|
758
|
+
handleRemainingComment,
|
|
759
|
+
getCommentChildNodes
|
|
777
760
|
};
|