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