@putout/printer 16.5.0 → 17.0.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 (167) hide show
  1. package/ChangeLog +16 -0
  2. package/README.md +5 -5
  3. package/lib/json.js +3 -5
  4. package/lib/print-tokens/cook.js +1 -3
  5. package/lib/print-tokens/index.js +2 -4
  6. package/lib/printer.js +6 -11
  7. package/lib/tokenize/comment/comment.js +3 -9
  8. package/lib/tokenize/comment/comments-printer/comments-printer.js +4 -6
  9. package/lib/tokenize/comment/maybe-inside-fn.js +1 -3
  10. package/lib/tokenize/comment/parse-comments.js +2 -4
  11. package/lib/tokenize/comment/parse-leading-comments.js +8 -12
  12. package/lib/tokenize/comment/parse-trailing-comments.js +8 -15
  13. package/lib/tokenize/debug.js +6 -8
  14. package/lib/tokenize/expressions/array-expression/array-expression.js +10 -15
  15. package/lib/tokenize/expressions/array-expression/indent.js +5 -11
  16. package/lib/tokenize/expressions/array-expression/is-object-after-simple.js +3 -5
  17. package/lib/tokenize/expressions/array-expression/newline.js +7 -11
  18. package/lib/tokenize/expressions/array-pattern/array-pattern.js +2 -3
  19. package/lib/tokenize/expressions/assignment-expression/assignment-expression-comments.js +6 -7
  20. package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +8 -12
  21. package/lib/tokenize/expressions/assignment-expression/maybe-parens-condition.js +3 -6
  22. package/lib/tokenize/expressions/assignment-expression/print-separator.js +2 -3
  23. package/lib/tokenize/expressions/assignment-pattern.js +1 -3
  24. package/lib/tokenize/expressions/binary-expression/binary-expression.js +5 -8
  25. package/lib/tokenize/expressions/binary-expression/concatenate.js +3 -4
  26. package/lib/tokenize/expressions/binary-expression/maybe-space.js +1 -3
  27. package/lib/tokenize/expressions/call-expression/call-expression.js +4 -6
  28. package/lib/tokenize/expressions/class/class-property.js +9 -11
  29. package/lib/tokenize/expressions/class/class.js +8 -12
  30. package/lib/tokenize/expressions/class/static-block.js +1 -3
  31. package/lib/tokenize/expressions/conditional-expression.js +2 -4
  32. package/lib/tokenize/expressions/function/arrow-function-expression.js +4 -6
  33. package/lib/tokenize/expressions/function/class-method.js +8 -12
  34. package/lib/tokenize/expressions/function/function-declaration.js +5 -7
  35. package/lib/tokenize/expressions/function/function-expression.js +4 -6
  36. package/lib/tokenize/expressions/function/functions.js +5 -19
  37. package/lib/tokenize/expressions/function/kind.js +1 -3
  38. package/lib/tokenize/expressions/function/object-method.js +5 -7
  39. package/lib/tokenize/expressions/function/params.js +2 -4
  40. package/lib/tokenize/expressions/function/print-function-params.js +4 -8
  41. package/lib/tokenize/expressions/import-expression.js +2 -5
  42. package/lib/tokenize/expressions/index.js +29 -68
  43. package/lib/tokenize/expressions/logical-expression/chain.js +3 -4
  44. package/lib/tokenize/expressions/logical-expression/logical-expression.js +3 -5
  45. package/lib/tokenize/expressions/member-expression/chain.js +2 -3
  46. package/lib/tokenize/expressions/member-expression/is-looks-like-chain.js +4 -6
  47. package/lib/tokenize/expressions/member-expression/member-expressions.js +6 -8
  48. package/lib/tokenize/expressions/new-expression/new-expression.js +4 -6
  49. package/lib/tokenize/expressions/object-expression/is-inside-tuple.js +2 -3
  50. package/lib/tokenize/expressions/object-expression/is-third-object-inside-array.js +2 -3
  51. package/lib/tokenize/expressions/object-expression/maybe-print-computed.js +1 -3
  52. package/lib/tokenize/expressions/object-expression/object-expression.js +9 -13
  53. package/lib/tokenize/expressions/object-expression/object-property.js +4 -6
  54. package/lib/tokenize/expressions/object-expression/print-key.js +2 -4
  55. package/lib/tokenize/expressions/object-pattern/calculate-long-assign-pattern.js +3 -6
  56. package/lib/tokenize/expressions/object-pattern/comments.js +1 -3
  57. package/lib/tokenize/expressions/object-pattern/more-then-max-properties-in-one-line.js +1 -3
  58. package/lib/tokenize/expressions/object-pattern/more-then-max-properties-length-in-one-line.js +2 -3
  59. package/lib/tokenize/expressions/object-pattern/object-pattern.js +12 -20
  60. package/lib/tokenize/expressions/object-pattern/wrong-shorthand.js +1 -3
  61. package/lib/tokenize/expressions/parenthesized-expression/parenthesized-expression.js +2 -3
  62. package/lib/tokenize/expressions/rest-element.js +2 -4
  63. package/lib/tokenize/expressions/sequence-expression/maybe-write-brace.js +1 -3
  64. package/lib/tokenize/expressions/sequence-expression/sequence-expression-comments.js +4 -5
  65. package/lib/tokenize/expressions/sequence-expression/sequence-expression.js +8 -11
  66. package/lib/tokenize/expressions/spread-element.js +2 -4
  67. package/lib/tokenize/expressions/tagged-template-expression.js +1 -3
  68. package/lib/tokenize/expressions/unary-expression/unary-expressions.js +7 -9
  69. package/lib/tokenize/is.js +35 -43
  70. package/lib/tokenize/jsx/index.js +38 -45
  71. package/lib/tokenize/jsx/jsx-attribute.js +2 -4
  72. package/lib/tokenize/jsx/jsx-element.js +2 -3
  73. package/lib/tokenize/jsx/jsx-fragment.js +3 -5
  74. package/lib/tokenize/jsx/jsx-opening-element.js +2 -4
  75. package/lib/tokenize/jsx/jsx-text/jsx-text.js +2 -4
  76. package/lib/tokenize/{expressions → literals}/decorator/decorator.js +3 -4
  77. package/lib/tokenize/literals/directive-literal.js +1 -3
  78. package/lib/tokenize/literals/identifier.js +4 -6
  79. package/lib/tokenize/literals/index.js +45 -49
  80. package/lib/tokenize/literals/string-literal.js +1 -3
  81. package/lib/tokenize/literals/template-literal.js +2 -4
  82. package/lib/tokenize/literals/void-pattern/void-pattern.js +1 -3
  83. package/lib/tokenize/literals/write-template-literal.js +1 -3
  84. package/lib/tokenize/mark.js +5 -11
  85. package/lib/tokenize/maybe/index.js +6 -9
  86. package/lib/tokenize/maybe/maybe-declare.js +1 -3
  87. package/lib/tokenize/maybe/maybe-decorators.js +1 -3
  88. package/lib/tokenize/maybe/maybe-parens.js +3 -5
  89. package/lib/tokenize/maybe/maybe-type-annotation.js +3 -6
  90. package/lib/tokenize/maybe/satisfy.js +2 -4
  91. package/lib/tokenize/maybe-get.js +1 -3
  92. package/lib/tokenize/overrides/overrides.js +3 -5
  93. package/lib/tokenize/overrides/parse-quotes.js +1 -3
  94. package/lib/tokenize/overrides/parse-round-braces.js +4 -10
  95. package/lib/tokenize/statements/block-statement/block-statement.js +9 -12
  96. package/lib/tokenize/statements/block-statement/get-directives.js +1 -3
  97. package/lib/tokenize/statements/block-statement/inside-if-with-no-body.js +2 -4
  98. package/lib/tokenize/statements/block-statement/is-call-inside-chain.js +3 -4
  99. package/lib/tokenize/statements/break-statement/break-statement.js +3 -5
  100. package/lib/tokenize/statements/continue-statement/continue-statement.js +2 -4
  101. package/lib/tokenize/statements/debugger-statement.js +2 -3
  102. package/lib/tokenize/statements/do-while-statement/do-while-statement.js +2 -3
  103. package/lib/tokenize/statements/empty-statement/empty-statement.js +2 -4
  104. package/lib/tokenize/statements/export-declaration/export-all-declaration.js +1 -3
  105. package/lib/tokenize/statements/export-declaration/export-declaration.js +33 -17
  106. package/lib/tokenize/statements/export-declaration/export-default-declaration.js +3 -5
  107. package/lib/tokenize/statements/expression-statement/expression-statement-comments.js +4 -6
  108. package/lib/tokenize/statements/expression-statement/expression-statement.js +9 -25
  109. package/lib/tokenize/statements/expression-statement/is-inside-assign-next-assign-function.js +2 -3
  110. package/lib/tokenize/statements/for-in-statement.js +1 -3
  111. package/lib/tokenize/statements/for-of-statement/for-of-statement.js +5 -8
  112. package/lib/tokenize/statements/for-statement.js +4 -7
  113. package/lib/tokenize/statements/if-statement/if-statement.js +5 -8
  114. package/lib/tokenize/statements/import-declaration/import-attribute.js +2 -4
  115. package/lib/tokenize/statements/import-declaration/import-declaration-comments.js +3 -4
  116. package/lib/tokenize/statements/import-declaration/import-declaration.js +10 -17
  117. package/lib/tokenize/statements/index.js +28 -61
  118. package/lib/tokenize/statements/labeled-statement/labeled-statement.js +2 -4
  119. package/lib/tokenize/statements/program/program.js +4 -6
  120. package/lib/tokenize/statements/return-statement/maybe-space-after-keyword.js +1 -3
  121. package/lib/tokenize/statements/return-statement/return-statement.js +8 -11
  122. package/lib/tokenize/statements/switch-statement/switch-statement.js +5 -9
  123. package/lib/tokenize/statements/try-statement/try-statements.js +3 -5
  124. package/lib/tokenize/statements/variable-declaration/maybe-space-after-keyword.js +1 -3
  125. package/lib/tokenize/statements/variable-declaration/variable-declaration.js +9 -13
  126. package/lib/tokenize/statements/while-statement/while-statement.js +3 -5
  127. package/lib/tokenize/statements/with-statement/with-statement.js +3 -5
  128. package/lib/tokenize/tokenize.js +12 -18
  129. package/lib/tokenize/typescript/enum/ts-enum-declaration.js +4 -7
  130. package/lib/tokenize/typescript/enum/ts-enum-member.js +1 -3
  131. package/lib/tokenize/typescript/function/print-return-type.js +2 -4
  132. package/lib/tokenize/typescript/function/ts-call-signature-declaration.js +3 -5
  133. package/lib/tokenize/typescript/function/ts-construct-signature-declaration.js +4 -7
  134. package/lib/tokenize/typescript/function/ts-constructor-type.js +3 -5
  135. package/lib/tokenize/typescript/function/ts-declare-function.js +4 -6
  136. package/lib/tokenize/typescript/function/ts-declare-method.js +2 -4
  137. package/lib/tokenize/typescript/function/ts-function-type.js +4 -7
  138. package/lib/tokenize/typescript/function/ts-method-signature.js +6 -9
  139. package/lib/tokenize/typescript/index.js +172 -207
  140. package/lib/tokenize/typescript/interface/ts-interface-body.js +2 -4
  141. package/lib/tokenize/typescript/interface/ts-interface-declaration.js +5 -8
  142. package/lib/tokenize/typescript/mapped-type/ts-mapped-type.js +2 -3
  143. package/lib/tokenize/typescript/namespace/ts-module-declaration.js +4 -6
  144. package/lib/tokenize/typescript/ts-as-expression/ts-as-expression.js +3 -5
  145. package/lib/tokenize/typescript/ts-conditional-type.js +1 -3
  146. package/lib/tokenize/typescript/ts-export-assignment/ts-export-assignment.js +2 -4
  147. package/lib/tokenize/typescript/ts-import-type/ts-import-type.js +2 -4
  148. package/lib/tokenize/typescript/ts-infer-type/ts-infer-type.js +2 -4
  149. package/lib/tokenize/typescript/ts-intersection-type.js +1 -3
  150. package/lib/tokenize/typescript/ts-optional-type/ts-optional-type.js +1 -3
  151. package/lib/tokenize/typescript/ts-parameter-property/ts-parameter-property.js +3 -5
  152. package/lib/tokenize/typescript/ts-parenthesized-type/ts-parenthesized-type.js +1 -3
  153. package/lib/tokenize/typescript/ts-property-signature/comments.js +4 -7
  154. package/lib/tokenize/typescript/ts-property-signature/ts-property-signature.js +10 -15
  155. package/lib/tokenize/typescript/ts-template-literal-type/ts-template-literal-type.js +2 -4
  156. package/lib/tokenize/typescript/ts-type-parameter-declaration/ts-type-parameter-declaration.js +4 -5
  157. package/lib/tokenize/typescript/ts-type-query/ts-type-query.js +2 -4
  158. package/lib/tokenize/typescript/ts-type-reference/ts-type-reference.js +1 -3
  159. package/lib/tokenize/typescript/ts-union-type/ts-union-type.js +2 -3
  160. package/lib/tokenize/typescript/tuple/ts-named-tuple-member.js +1 -3
  161. package/lib/tokenize/typescript/tuple/ts-tuple-type.js +1 -3
  162. package/lib/tokenize/typescript/type/ts-type-alias-declaration.js +5 -8
  163. package/lib/tokenize/typescript/type/ts-type-literal.js +1 -3
  164. package/lib/tokenize/typescript/type/ts-type-parameter.js +2 -4
  165. package/lib/tokenize/visitors.js +5 -14
  166. package/lib/types.js +1 -3
  167. package/package.json +9 -9
package/ChangeLog CHANGED
@@ -1,3 +1,19 @@
1
+ 2026.01.04, v17.0.0
2
+
3
+ feature:
4
+ - b33d062 @putout/printer: migrate to ESM
5
+ - dcd78dd @putout/printer: redlint v5.0.2
6
+ - 45b4570 @putout/printer: goldstein v7.0.0
7
+ - 97a49eb @putout/printer: madrun v12.0.0
8
+ - 063fda0 @putout/printer: samadhi v4.0.2
9
+ - 3ff6ea5 @putout/printer: try-catch v4.0.6
10
+ - 09f5c5a @putout/printer: @putout/eslint v5.0.2
11
+
12
+ 2026.01.03, v16.6.0
13
+
14
+ feature:
15
+ - 8558f03 @putout/printer: ExportDeclaration: export default from: add support
16
+
1
17
  2025.12.27, v16.5.0
2
18
 
3
19
  feature:
package/README.md CHANGED
@@ -54,8 +54,8 @@ To benefit from it.
54
54
  ## Example
55
55
 
56
56
  ```js
57
- const {print} = require('@putout/printer');
58
- const {parse} = require('putout');
57
+ import {print} from '@putout/printer';
58
+ import {parse} from 'putout';
59
59
  const ast = parse('const a = (b, c) => {const d = 5; return a;}');
60
60
 
61
61
  print(ast);
@@ -309,10 +309,10 @@ This is the same as `print('__left')` but more low-level, and supports only obje
309
309
  About speed, for file `speed.js`:
310
310
 
311
311
  ```js
312
- const {readFileSync} = require('node:fs');
312
+ import {readFileSync} from 'node:fs';
313
313
 
314
- const putout = require('putout');
315
- const parser = require('@babel/parser');
314
+ import {putout} from 'putout';
315
+ import parser from '@babel/parser';
316
316
 
317
317
  const code = readFileSync('./lib/tokenize/tokenize.js', 'utf8');
318
318
  const ast = parser.parse(code);
package/lib/json.js CHANGED
@@ -1,14 +1,12 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
- const {isJSON} = require('@putout/operator-json');
1
+ import {types} from '@putout/babel';
2
+ import {isJSON} from '@putout/operator-json';
5
3
 
6
4
  const {
7
5
  isCallExpression,
8
6
  isIdentifier,
9
7
  } = types;
10
8
 
11
- module.exports.maybeJSON = (ast, overrides) => {
9
+ export const maybeJSON = (ast, overrides) => {
12
10
  if (isASTJSON(ast))
13
11
  return {
14
12
  ...overrides,
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.cook = (tokens) => {
1
+ export const cook = (tokens) => {
4
2
  const cookedTokens = [];
5
3
 
6
4
  for (const {value} of tokens) {
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {cook} from './cook.js';
2
2
 
3
- const {cook} = require('./cook');
4
-
5
- module.exports.printTokens = (tokens) => {
3
+ export const printTokens = (tokens) => {
6
4
  const cookedTokens = cook(tokens);
7
5
  return cookedTokens.join('');
8
6
  };
package/lib/printer.js CHANGED
@@ -1,13 +1,11 @@
1
- 'use strict';
1
+ import {tokenize} from './tokenize/tokenize.js';
2
+ import {printTokens} from './print-tokens/index.js';
3
+ import {maybeJSON} from './json.js';
2
4
 
3
- const {tokenize} = require('./tokenize/tokenize');
4
- const {printTokens} = require('./print-tokens');
5
- const {maybeJSON} = require('./json');
5
+ export {maybeVisitor} from './tokenize/maybe/index.js';
6
+ export * as visitors from './tokenize/visitors.js';
6
7
 
7
- const {maybeVisitor} = require('./tokenize/maybe/index');
8
- const visitors = require('./tokenize/visitors');
9
-
10
- module.exports.print = (ast, overrides = {}) => {
8
+ export const print = (ast, overrides = {}) => {
11
9
  check(ast);
12
10
 
13
11
  const options = maybeJSON(ast, overrides);
@@ -16,9 +14,6 @@ module.exports.print = (ast, overrides = {}) => {
16
14
  return printTokens(tokens);
17
15
  };
18
16
 
19
- module.exports.visitors = visitors;
20
- module.exports.maybeVisitor = maybeVisitor;
21
-
22
17
  function check(ast) {
23
18
  if (typeof ast !== 'object')
24
19
  throw Error('☝️Looks like ast not an object');
@@ -1,9 +1,3 @@
1
- 'use strict';
2
-
3
- const {parseLeadingComments} = require('./parse-leading-comments');
4
- const {parseTrailingComments} = require('./parse-trailing-comments');
5
- const {parseComments} = require('./parse-comments');
6
-
7
- module.exports.parseLeadingComments = parseLeadingComments;
8
- module.exports.parseTrailingComments = parseTrailingComments;
9
- module.exports.parseComments = parseComments;
1
+ export {parseLeadingComments} from './parse-leading-comments.js';
2
+ export {parseTrailingComments} from './parse-trailing-comments.js';
3
+ export {parseComments} from './parse-comments.js';
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
1
  const createPrintCommentLine = (fn, value) => () => fn(`//${value}`);
4
2
  const createPrintCommentBlock = (fn, value) => () => fn(`/*${value}*/\n`);
5
3
 
6
- module.exports.hasTrailingCommentsPrinter = (currentTraverse) => {
4
+ export const hasTrailingCommentsPrinter = (currentTraverse) => {
7
5
  const {
8
6
  printTrailingCommentBlock,
9
7
  printTrailingCommentLine,
@@ -15,7 +13,7 @@ module.exports.hasTrailingCommentsPrinter = (currentTraverse) => {
15
13
  return Boolean(printTrailingCommentLine);
16
14
  };
17
15
 
18
- module.exports.hasLeadingCommentsPrinter = (currentTraverse) => {
16
+ export const hasLeadingCommentsPrinter = (currentTraverse) => {
19
17
  const {
20
18
  printLeadingCommentLine,
21
19
  printLeadingCommentBlock,
@@ -27,7 +25,7 @@ module.exports.hasLeadingCommentsPrinter = (currentTraverse) => {
27
25
  return Boolean(printLeadingCommentBlock);
28
26
  };
29
27
 
30
- module.exports.printLeadingComments = (path, printer, semantics, {currentTraverse}) => {
28
+ export const printLeadingComments = (path, printer, semantics, {currentTraverse}) => {
31
29
  const {print} = printer;
32
30
  const {
33
31
  leadingComments = [],
@@ -58,7 +56,7 @@ module.exports.printLeadingComments = (path, printer, semantics, {currentTravers
58
56
  }
59
57
  };
60
58
 
61
- module.exports.printTrailingComments = (path, printer, semantics, {currentTraverse}) => {
59
+ export const printTrailingComments = (path, printer, semantics, {currentTraverse}) => {
62
60
  const {print} = printer;
63
61
  const {
64
62
  trailingComments = []} = path.node;
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.maybeInsideFn = (insideFn, {print, indent}) => {
1
+ export const maybeInsideFn = (insideFn, {print, indent}) => {
4
2
  if (!insideFn)
5
3
  return;
6
4
 
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {isNext} from '../is.js';
2
2
 
3
- const {isNext} = require('../is');
4
-
5
- module.exports.parseComments = (path, {write, maybe}, semantics) => {
3
+ export const parseComments = (path, {write, maybe}, semantics) => {
6
4
  if (!semantics.comments)
7
5
  return;
8
6
 
@@ -1,18 +1,14 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
- const {
1
+ import {types} from '@putout/babel';
2
+ import {
5
3
  hasTrailingComment,
6
4
  satisfy,
7
- } = require('../is');
8
-
9
- const {markBefore} = require('../mark');
10
- const {maybeInsideFn} = require('./maybe-inside-fn');
11
-
12
- const {
5
+ } from '../is.js';
6
+ import {markBefore} from '../mark.js';
7
+ import {maybeInsideFn} from './maybe-inside-fn.js';
8
+ import {
13
9
  printLeadingComments,
14
10
  hasLeadingCommentsPrinter,
15
- } = require('./comments-printer/comments-printer');
11
+ } from './comments-printer/comments-printer.js';
16
12
 
17
13
  const {
18
14
  isArrowFunctionExpression,
@@ -86,7 +82,7 @@ const isFirst = (path) => {
86
82
  return false;
87
83
  };
88
84
 
89
- module.exports.parseLeadingComments = (path, printer, semantics, {currentTraverse = {}} = {}) => {
85
+ export const parseLeadingComments = (path, printer, semantics, {currentTraverse = {}} = {}) => {
90
86
  const {
91
87
  print,
92
88
  maybe,
@@ -1,19 +1,14 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
-
5
- const {
1
+ import {types} from '@putout/babel';
2
+ import {
6
3
  isLast,
7
4
  isCoupleLines,
8
5
  isNext,
9
- } = require('../is');
10
-
11
- const {isLooksLikeChain} = require('../expressions/member-expression/is-looks-like-chain');
12
-
13
- const {
6
+ } from '../is.js';
7
+ import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain.js';
8
+ import {
14
9
  printTrailingComments,
15
10
  hasTrailingCommentsPrinter,
16
- } = require('./comments-printer/comments-printer');
11
+ } from './comments-printer/comments-printer.js';
17
12
 
18
13
  const {
19
14
  isDecorator,
@@ -42,7 +37,7 @@ function isSameLine(path, loc) {
42
37
  return path.node.loc?.start.line === loc.start.line || path.node.loc?.end.line === loc.end.line;
43
38
  }
44
39
 
45
- const isTrailingIsLeading = (path) => path.node.trailingComments === path.getNextSibling().node?.leadingComments;
40
+ export const isTrailingIsLeading = (path) => path.node.trailingComments === path.getNextSibling().node?.leadingComments;
46
41
 
47
42
  const isNewlineAfter = (path) => {
48
43
  const {parentPath} = path;
@@ -58,8 +53,6 @@ const isNewlineAfter = (path) => {
58
53
  return !isLast(path);
59
54
  };
60
55
 
61
- module.exports.isTrailingIsLeading = isTrailingIsLeading;
62
-
63
56
  function isCommentOnNextLine(path) {
64
57
  const {node} = path;
65
58
  const {
@@ -95,7 +88,7 @@ function isCommentOnNextLine(path) {
95
88
  return isNextLine || isNextLineAfterNewline;
96
89
  }
97
90
 
98
- module.exports.parseTrailingComments = (path, printer, semantics, {currentTraverse} = {}) => {
91
+ export const parseTrailingComments = (path, printer, semantics, {currentTraverse} = {}) => {
99
92
  const {parentPath} = path;
100
93
  const {
101
94
  write,
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
- const process = require('node:process');
4
- const toSnakeCase = require('just-snake-case');
5
- const {codeFrameColumns} = require('@putout/babel');
6
- const {TYPES} = require('../types');
1
+ import process from 'node:process';
2
+ import toSnakeCase from 'just-snake-case';
3
+ import {codeFrameColumns} from '@putout/babel';
4
+ import {TYPES} from '../types.js';
7
5
 
8
6
  const {stringify} = JSON;
9
7
  const {
@@ -14,7 +12,7 @@ const {
14
12
  LOG_DEBUG,
15
13
  } = process.env;
16
14
 
17
- module.exports.createDebug = (tokens) => (a) => {
15
+ export const createDebug = (tokens) => (a) => {
18
16
  if (!LOG_DEBUG)
19
17
  return;
20
18
 
@@ -24,7 +22,7 @@ module.exports.createDebug = (tokens) => (a) => {
24
22
  });
25
23
  };
26
24
 
27
- module.exports.createLog = ({newline = '\n', store = createStore()} = {}) => ({type, value}) => {
25
+ export const createLog = ({newline = '\n', store = createStore()} = {}) => ({type, value}) => {
28
26
  if (LOG_TOKENS) {
29
27
  console.log(codeFrameColumns(stringify({
30
28
  type,
@@ -1,31 +1,26 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
- const {
1
+ import {types} from '@putout/babel';
2
+ import {
5
3
  isCoupleLines,
6
4
  isStringAndIdentifier,
7
5
  isIdentifierAndIdentifier,
8
6
  isStringAndArray,
9
7
  isSimpleAndNotEmptyObject,
10
8
  isNextObject,
11
- } = require('#is');
12
-
13
- const {
9
+ } from '#is';
10
+ import {
14
11
  isIncreaseIndent,
15
12
  isCurrentNewLine,
16
13
  isMultiLine,
17
- } = require('./newline');
18
-
19
- const {
14
+ } from './newline.js';
15
+ import {
20
16
  isInsideArray,
21
17
  isArrayInsideArray,
22
18
  isArrayIndented,
23
- } = require('./indent');
24
-
25
- const {
19
+ } from './indent.js';
20
+ import {
26
21
  isObjectAfterSimple,
27
22
  isNextSimple,
28
- } = require('./is-object-after-simple');
23
+ } from './is-object-after-simple.js';
29
24
 
30
25
  const {
31
26
  isObjectExpression,
@@ -79,7 +74,7 @@ const isNextSimpleBetweenObjects = (a) => {
79
74
 
80
75
  const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
81
76
 
82
- module.exports.ArrayExpression = {
77
+ export const ArrayExpression = {
83
78
  beforeIf(path) {
84
79
  const {parentPath} = path;
85
80
  const {elements} = path.node;
@@ -1,18 +1,14 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
- const {isIndented} = require('../../is');
1
+ import {types} from '@putout/babel';
2
+ import {isIndented} from '../../is.js';
5
3
 
6
4
  const {
7
5
  isStringLiteral,
8
6
  isArrayExpression,
9
7
  } = types;
10
8
 
11
- const isInsideArray = (path) => path.parentPath.isArrayExpression();
12
-
13
- module.exports.isInsideArray = isInsideArray;
9
+ export const isInsideArray = (path) => path.parentPath.isArrayExpression();
14
10
 
15
- module.exports.isArrayIndented = (path) => {
11
+ export const isArrayIndented = (path) => {
16
12
  const elements = path.get('elements');
17
13
 
18
14
  if (isArrayInsideArray(path))
@@ -23,9 +19,7 @@ module.exports.isArrayIndented = (path) => {
23
19
  return !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(first);
24
20
  };
25
21
 
26
- module.exports.isArrayInsideArray = isArrayInsideArray;
27
-
28
- function isArrayInsideArray(path) {
22
+ export function isArrayInsideArray(path) {
29
23
  if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
30
24
  return false;
31
25
 
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- const {isNextObject, isPrevObject} = require('../../is');
1
+ import {isNextObject, isPrevObject} from '../../is.js';
4
2
 
5
3
  const SIMPLE_TYPES = [
6
4
  'ArrayExpression',
@@ -11,7 +9,7 @@ const SIMPLE_TYPES = [
11
9
  'NewExpression',
12
10
  ];
13
11
 
14
- module.exports.isObjectAfterSimple = (a) => {
12
+ export const isObjectAfterSimple = (a) => {
15
13
  const {type} = a;
16
14
 
17
15
  if (!isNextObject(a) || isPrevObject(a))
@@ -20,7 +18,7 @@ module.exports.isObjectAfterSimple = (a) => {
20
18
  return SIMPLE_TYPES.includes(type);
21
19
  };
22
20
 
23
- module.exports.isNextSimple = (a) => {
21
+ export const isNextSimple = (a) => {
24
22
  const {type} = a.getNextSibling();
25
23
 
26
24
  return SIMPLE_TYPES.includes(type);
@@ -1,9 +1,6 @@
1
- 'use strict';
2
-
3
- const {isSimple} = require('@putout/operate');
4
- const {types} = require('@putout/babel');
5
-
6
- const {
1
+ import {isSimple} from '@putout/operate';
2
+ import {types} from '@putout/babel';
3
+ import {
7
4
  isStringAndMember,
8
5
  isStringAndIdentifier,
9
6
  isIdentifierAndString,
@@ -11,7 +8,7 @@ const {
11
8
  isStringAndArray,
12
9
  isIdentifierAndIdentifier,
13
10
  isSimpleAndNotEmptyObject,
14
- } = require('../../is');
11
+ } from '../../is.js';
15
12
 
16
13
  const {
17
14
  isObjectExpression,
@@ -72,7 +69,7 @@ function isMaxElementLengthInOneLine(elements, maxElementLengthInOneLine) {
72
69
  return first.node.name.length < maxElementLengthInOneLine;
73
70
  }
74
71
 
75
- module.exports.isMultiLine = (path, {elements, maxElementsInOneLine, maxElementLengthInOneLine}) => {
72
+ export const isMultiLine = (path, {elements, maxElementsInOneLine, maxElementLengthInOneLine}) => {
76
73
  const [first] = elements;
77
74
 
78
75
  if (isMaxElementLengthInOneLine(elements, maxElementLengthInOneLine))
@@ -270,8 +267,7 @@ const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
270
267
 
271
268
  const isParentProperty = (path) => path.find(isObjectProperty);
272
269
 
273
- module.exports.isIncreaseIndent = isIncreaseIndent;
274
- function isIncreaseIndent(path) {
270
+ export function isIncreaseIndent(path) {
275
271
  const elements = path.get('elements');
276
272
 
277
273
  if (!elements.length)
@@ -306,7 +302,7 @@ const isStringAndObject = (elements) => {
306
302
  return isStringLiteral(first) && isObjectExpression(last);
307
303
  };
308
304
 
309
- module.exports.isCurrentNewLine = (path) => {
305
+ export const isCurrentNewLine = (path) => {
310
306
  if (path.isSpreadElement())
311
307
  return true;
312
308
 
@@ -1,9 +1,8 @@
1
- 'use strict';
1
+ import {maybeTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
2
2
 
3
- const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
4
3
  const isForOf = ({parentPath}) => parentPath.parentPath.parentPath?.isForOfStatement();
5
4
 
6
- module.exports.ArrayPattern = maybeTypeAnnotation((path, {indent, maybe, print}, semantics) => {
5
+ export const ArrayPattern = maybeTypeAnnotation((path, {indent, maybe, print}, semantics) => {
7
6
  const {maxElementsInOneLine} = semantics;
8
7
 
9
8
  print('[');
@@ -1,10 +1,9 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
+ import {hasLeadingComment} from '#is';
2
3
 
3
- const {types} = require('@putout/babel');
4
- const {hasLeadingComment} = require('#is');
5
4
  const {isReturnStatement} = types;
6
5
 
7
- module.exports.printLeadingCommentLine = (path, printer, semantics, {printComment, isLast}) => {
6
+ export const printLeadingCommentLine = (path, printer, semantics, {printComment, isLast}) => {
8
7
  const {parentPath} = path;
9
8
  const {print, maybe} = printer;
10
9
 
@@ -16,7 +15,7 @@ module.exports.printLeadingCommentLine = (path, printer, semantics, {printCommen
16
15
  print.breakline();
17
16
  };
18
17
 
19
- module.exports.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
18
+ export const printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
20
19
  const {parentPath} = path;
21
20
  const {print} = printer;
22
21
 
@@ -27,7 +26,7 @@ module.exports.printLeadingCommentBlock = (path, printer, semantics, {printComme
27
26
  print.indent();
28
27
  };
29
28
 
30
- module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
29
+ export const maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
31
30
  const {parentPath} = path;
32
31
  const is = isReturnStatement(parentPath);
33
32
 
@@ -47,7 +46,7 @@ module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
47
46
  }
48
47
  };
49
48
 
50
- module.exports.maybeInsideReturnWithCommentEnd = (path, {print, indent}) => {
49
+ export const maybeInsideReturnWithCommentEnd = (path, {print, indent}) => {
51
50
  const {parentPath} = path;
52
51
  const is = isReturnStatement(parentPath);
53
52
 
@@ -1,20 +1,16 @@
1
- 'use strict';
2
-
3
- const {condition} = require('./maybe-parens-condition');
4
-
5
- const {
1
+ import {condition} from './maybe-parens-condition.js';
2
+ import {
6
3
  printLeadingCommentLine,
7
4
  maybeInsideReturnWithCommentEnd,
8
5
  maybeInsideReturnWithCommentStart,
9
6
  printLeadingCommentBlock,
10
- } = require('./assignment-expression-comments');
11
-
12
- const {maybeParens} = require('../../maybe/maybe-parens');
13
- const {printSeparator} = require('./print-separator');
7
+ } from './assignment-expression-comments.js';
8
+ import {maybeParens} from '../../maybe/maybe-parens.js';
9
+ import {printSeparator} from './print-separator.js';
14
10
 
15
11
  const isInsideBlock = ({parentPath}) => /BlockStatement|Program/.test(parentPath.type);
16
12
 
17
- module.exports.AssignmentExpression = maybeParens({
13
+ export const AssignmentExpression = maybeParens({
18
14
  checkParens: false,
19
15
  condition,
20
16
  print(path, printer) {
@@ -38,5 +34,5 @@ module.exports.AssignmentExpression = maybeParens({
38
34
  },
39
35
  });
40
36
 
41
- module.exports.AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
42
- module.exports.AssignmentExpression.printLeadingCommentBlock = printLeadingCommentBlock;
37
+ AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
38
+ AssignmentExpression.printLeadingCommentBlock = printLeadingCommentBlock;
@@ -1,10 +1,7 @@
1
- 'use strict';
1
+ import {hasLeadingComment} from '#is';
2
+ import {isParens} from '../../maybe/maybe-parens.js';
2
3
 
3
- const {hasLeadingComment} = require('#is');
4
-
5
- const {isParens} = require('../../maybe/maybe-parens');
6
-
7
- module.exports.condition = (path, printer, semantics) => {
4
+ export const condition = (path, printer, semantics) => {
8
5
  const {parentPath} = path;
9
6
  const {type} = parentPath;
10
7
  const {roundBraces} = semantics;
@@ -1,12 +1,11 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
2
 
3
- const {types} = require('@putout/babel');
4
3
  const {
5
4
  isAssignmentExpression,
6
5
  isExpressionStatement,
7
6
  } = types;
8
7
 
9
- module.exports.printSeparator = (path, {print}) => {
8
+ export const printSeparator = (path, {print}) => {
10
9
  if (isMultiline(path))
11
10
  print.breakline();
12
11
  else
@@ -1,8 +1,6 @@
1
- 'use strict';
2
-
3
1
  const isArg = (path) => path.parentPath.isFunction();
4
2
 
5
- module.exports.AssignmentPattern = {
3
+ export const AssignmentPattern = {
6
4
  print(path, {print, maybe}) {
7
5
  maybe.print(shouldPrint(path), '__left');
8
6
  print.space();
@@ -1,14 +1,11 @@
1
- 'use strict';
2
-
3
- const {
1
+ import {
4
2
  concatenate,
5
3
  isConcatenation,
6
- } = require('./concatenate');
7
-
8
- const {maybeSpace} = require('./maybe-space');
9
- const {maybeParens} = require('../../maybe/maybe-parens');
4
+ } from './concatenate.js';
5
+ import {maybeSpace} from './maybe-space.js';
6
+ import {maybeParens} from '../../maybe/maybe-parens.js';
10
7
 
11
- module.exports.BinaryExpression = maybeParens((path, {print, indent, maybe}) => {
8
+ export const BinaryExpression = maybeParens((path, {print, indent, maybe}) => {
12
9
  const {operator} = path.node;
13
10
 
14
11
  if (operator === 'in' || operator === 'instanceof') {
@@ -1,6 +1,5 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
2
 
3
- const {types} = require('@putout/babel');
4
3
  const {
5
4
  isStringLiteral,
6
5
  isTemplateLiteral,
@@ -14,7 +13,7 @@ const isStringLike = (a) => {
14
13
  return isTemplateLiteral(a);
15
14
  };
16
15
 
17
- module.exports.isConcatenation = (path) => {
16
+ export const isConcatenation = (path) => {
18
17
  const {parentPath} = path;
19
18
  const {operator} = path.node;
20
19
 
@@ -36,7 +35,7 @@ module.exports.isConcatenation = (path) => {
36
35
  return isBinaryExpression(left) && isStringLike(right);
37
36
  };
38
37
 
39
- module.exports.concatenate = (path, {print, indent}) => {
38
+ export const concatenate = (path, {print, indent}) => {
40
39
  if (!path.parentPath.isBinaryExpression()) {
41
40
  indent.inc();
42
41
  print.breakline();
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.maybeSpace = (path, {print}) => {
1
+ export const maybeSpace = (path, {print}) => {
4
2
  const {right} = path.node;
5
3
 
6
4
  if (right.type === 'UnaryExpression' && right.operator === '+')