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