@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
@@ -1,7 +1,6 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
- const {
1
+ import {types} from '@putout/babel';
2
+ import {parseComments} from '../../comment/comment.js';
3
+ import {
5
4
  isCoupleLines,
6
5
  isForOf,
7
6
  isIf,
@@ -10,12 +9,10 @@ const {
10
9
  noLeadingComment,
11
10
  hasLeadingComment,
12
11
  exists,
13
- } = require('../../is');
14
-
15
- const {parseComments} = require('../../comment/comment');
16
- const {isInsideTuple} = require('./is-inside-tuple');
17
- const {isLooksLikeChain} = require('../member-expression/is-looks-like-chain');
18
- const {isThirdObjectInsideArray} = require('./is-third-object-inside-array');
12
+ } from '../../is.js';
13
+ import {isInsideTuple} from './is-inside-tuple.js';
14
+ import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
15
+ import {isThirdObjectInsideArray} from './is-third-object-inside-array.js';
19
16
 
20
17
  const {
21
18
  isStringLiteral,
@@ -58,7 +55,7 @@ function isInsideNestedTuple({parentPath}) {
58
55
  return isStringLiteral(first);
59
56
  }
60
57
 
61
- module.exports.ObjectExpression = (path, printer, semantics) => {
58
+ export const ObjectExpression = (path, printer, semantics) => {
62
59
  const {trailingComma} = semantics;
63
60
  const {
64
61
  print,
@@ -153,8 +150,7 @@ const notLastArgInsideCall = (path) => {
153
150
  const ONE_LINE = true;
154
151
  const MANY_LINES = false;
155
152
 
156
- module.exports.isOneLine = isOneLine;
157
- function isOneLine(path) {
153
+ export function isOneLine(path) {
158
154
  const {length} = path.get('properties');
159
155
 
160
156
  if (!length)
@@ -1,10 +1,8 @@
1
- 'use strict';
1
+ import {isConcatenation} from '../binary-expression/concatenate.js';
2
+ import {isOneLine} from './object-expression.js';
3
+ import {printKey} from './print-key.js';
2
4
 
3
- const {isConcatenation} = require('../binary-expression/concatenate');
4
- const {isOneLine} = require('./object-expression');
5
- const {printKey} = require('./print-key');
6
-
7
- module.exports.ObjectProperty = (path, printer, semantics) => {
5
+ export const ObjectProperty = (path, printer, semantics) => {
8
6
  const {trailingComma} = semantics;
9
7
  const {shorthand} = path.node;
10
8
  const {
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {maybePrintComputed} from './maybe-print-computed.js';
2
2
 
3
- const {maybePrintComputed} = require('./maybe-print-computed');
4
-
5
- module.exports.printKey = (path, printer) => {
3
+ export const printKey = (path, printer) => {
6
4
  const key = path.get('key');
7
5
 
8
6
  maybePrintComputed(path, key, printer);
@@ -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
  isAssignmentPattern,
6
5
  isArrayExpression,
@@ -8,7 +7,7 @@ const {
8
7
  isIdentifier,
9
8
  } = types;
10
9
 
11
- module.exports.calculateAssigns = (property, semantics) => {
10
+ export const calculateAssigns = (property, semantics) => {
12
11
  const currentAssign = isLongAssignPattern(property, semantics);
13
12
 
14
13
  const {right} = property.node.value;
@@ -20,9 +19,7 @@ module.exports.calculateAssigns = (property, semantics) => {
20
19
  };
21
20
  };
22
21
 
23
- module.exports.isLongAssignPattern = isLongAssignPattern;
24
-
25
- function isLongAssignPattern(path, semantics) {
22
+ export function isLongAssignPattern(path, semantics) {
26
23
  const {key, value} = path.node;
27
24
 
28
25
  if (!isAssignmentPattern(value))
@@ -1,9 +1,7 @@
1
- 'use strict';
2
-
3
1
  const createPrintCommentLine = (fn) => (value) => fn(`//${value}`);
4
2
  const createPrintCommentBlock = (fn) => (value) => fn(`/*${value}*/`);
5
3
 
6
- module.exports.printLeadingComments = (path, {print}) => {
4
+ export const printLeadingComments = (path, {print}) => {
7
5
  const printCommentLine = createPrintCommentLine(print);
8
6
  const printCommentBlock = createPrintCommentBlock(print);
9
7
  const {leadingComments} = path.node;
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.moreThenMaxPropertiesInOneLine = (path, {maxPropertiesInOneLine}) => {
1
+ export const moreThenMaxPropertiesInOneLine = (path, {maxPropertiesInOneLine}) => {
4
2
  const {parentPath} = path;
5
3
 
6
4
  if (parentPath.isObjectProperty())
@@ -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
  isAssignmentPattern,
6
5
  isIdentifier,
@@ -16,7 +15,7 @@ function getLength(left, right) {
16
15
  return 0;
17
16
  }
18
17
 
19
- module.exports.moreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengthInOneLine}) => {
18
+ export const moreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengthInOneLine}) => {
20
19
  const {properties} = path.node;
21
20
 
22
21
  for (const {key, value} of properties) {
@@ -1,27 +1,19 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
-
5
- const {wrongShorthand} = require('./wrong-shorthand');
6
-
7
- const {
1
+ import {types} from '@putout/babel';
2
+ import {wrongShorthand} from './wrong-shorthand.js';
3
+ import {
8
4
  isForOf,
9
5
  isCoupleLines,
10
6
  exists,
11
- } = require('../../is');
12
-
13
- const {moreThenMaxPropertiesInOneLine} = require('./more-then-max-properties-in-one-line');
14
-
15
- const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
16
- const {moreThenMaxPropertiesLengthInOneLine} = require('./more-then-max-properties-length-in-one-line');
17
- const {printKey} = require('../object-expression/print-key');
18
-
19
- const {
7
+ } from '../../is.js';
8
+ import {moreThenMaxPropertiesInOneLine} from './more-then-max-properties-in-one-line.js';
9
+ import {maybeTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
10
+ import {moreThenMaxPropertiesLengthInOneLine} from './more-then-max-properties-length-in-one-line.js';
11
+ import {printKey} from '../object-expression/print-key.js';
12
+ import {
20
13
  calculateAssigns,
21
14
  isLongAssignPattern,
22
- } = require('./calculate-long-assign-pattern');
23
-
24
- const {printLeadingComments} = require('./comments');
15
+ } from './calculate-long-assign-pattern.js';
16
+ import {printLeadingComments} from './comments.js';
25
17
 
26
18
  const {
27
19
  isObjectExpression,
@@ -95,7 +87,7 @@ function isNextAssignObject(path) {
95
87
  return isObjectExpression(right);
96
88
  }
97
89
 
98
- module.exports.ObjectPattern = {
90
+ export const ObjectPattern = {
99
91
  print: maybeTypeAnnotation((path, printer, semantics) => {
100
92
  const shouldIndent = isIndent(path);
101
93
  const {
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
- module.exports.wrongShorthand = ({computed, isAssign, keyPath, valuePath}) => {
1
+ export const wrongShorthand = ({computed, isAssign, keyPath, valuePath}) => {
4
2
  return !computed && !isAssign && keyPath.node.name !== valuePath.node.name;
5
3
  };
@@ -1,6 +1,5 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
2
 
3
- const {types} = require('@putout/babel');
4
3
  const {isJSXElement} = types;
5
4
 
6
5
  const condition = (path) => {
@@ -8,7 +7,7 @@ const condition = (path) => {
8
7
  return !isJSXElement(expression);
9
8
  };
10
9
 
11
- module.exports.ParenthesizedExpression = {
10
+ export const ParenthesizedExpression = {
12
11
  before(path, {print}) {
13
12
  print('(');
14
13
  },
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {maybeTypeAnnotation} from '../maybe/maybe-type-annotation.js';
2
2
 
3
- const {maybeTypeAnnotation} = require('../maybe/maybe-type-annotation');
4
-
5
- module.exports.RestElement = maybeTypeAnnotation((path, {print}) => {
3
+ export const RestElement = maybeTypeAnnotation((path, {print}) => {
6
4
  print('...');
7
5
  print('__argument');
8
6
  });
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.condition = (path, printer, semantics) => {
1
+ export const condition = (path, printer, semantics) => {
4
2
  const {parentPath} = path;
5
3
  const {type} = parentPath;
6
4
  const {roundBraces} = semantics;
@@ -1,12 +1,11 @@
1
- 'use strict';
1
+ import {hasLeadingComment} from '#is';
2
2
 
3
- const {hasLeadingComment} = require('#is');
4
3
  const noop = () => {};
5
4
 
6
- module.exports.printLeadingCommentLine = noop;
7
- module.exports.printLeadingCommentBlock = noop;
5
+ export const printLeadingCommentLine = noop;
6
+ export const printLeadingCommentBlock = noop;
8
7
 
9
- module.exports.maybePrintComments = (path, {print}) => {
8
+ export const maybePrintComments = (path, {print}) => {
10
9
  if (hasLeadingComment(path)) {
11
10
  const {leadingComments} = path.node;
12
11
 
@@ -1,16 +1,13 @@
1
- 'use strict';
2
-
3
- const {hasLeadingComment} = require('#is');
4
- const {maybeParens} = require('../../maybe/maybe-parens');
5
- const {condition} = require('./maybe-write-brace');
6
-
7
- const {
1
+ import {hasLeadingComment} from '#is';
2
+ import {maybeParens} from '../../maybe/maybe-parens.js';
3
+ import {condition} from './maybe-write-brace.js';
4
+ import {
8
5
  maybePrintComments,
9
6
  printLeadingCommentLine,
10
7
  printLeadingCommentBlock,
11
- } = require('./sequence-expression-comments');
8
+ } from './sequence-expression-comments.js';
12
9
 
13
- module.exports.SequenceExpression = maybeParens({
10
+ export const SequenceExpression = maybeParens({
14
11
  checkParens: false,
15
12
  condition,
16
13
  print(path, printer) {
@@ -49,5 +46,5 @@ module.exports.SequenceExpression = maybeParens({
49
46
  },
50
47
  });
51
48
 
52
- module.exports.SequenceExpression.printLeadingCommentLine = printLeadingCommentLine;
53
- module.exports.SequenceExpression.printLeadingCommentBlock = printLeadingCommentBlock;
49
+ SequenceExpression.printLeadingCommentLine = printLeadingCommentLine;
50
+ SequenceExpression.printLeadingCommentBlock = printLeadingCommentBlock;
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {hasTrailingComment} from '../is.js';
2
2
 
3
- const {hasTrailingComment} = require('../is');
4
-
5
- module.exports.SpreadElement = (path, printer) => {
3
+ export const SpreadElement = (path, printer) => {
6
4
  const {print} = printer;
7
5
  print('...');
8
6
  print('__argument');
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.TaggedTemplateExpression = (path, {print}) => {
1
+ export const TaggedTemplateExpression = (path, {print}) => {
4
2
  print('__tag');
5
3
  print('__quasi');
6
4
  };
@@ -1,7 +1,5 @@
1
- 'use strict';
2
-
3
- const {isLast, isNext} = require('../../is');
4
- const {maybeParens} = require('../../maybe/maybe-parens');
1
+ import {isLast, isNext} from '../../is.js';
2
+ import {maybeParens} from '../../maybe/maybe-parens.js';
5
3
 
6
4
  const isWord = (a) => /^(delete|typeof|void|throw)$/.test(a);
7
5
 
@@ -16,16 +14,16 @@ const unaryExpression = maybeParens((path, printer) => {
16
14
  maybe.print(!prefix, operator);
17
15
  });
18
16
 
19
- module.exports.UnaryExpression = unaryExpression;
20
- module.exports.UpdateExpression = unaryExpression;
17
+ export const UnaryExpression = unaryExpression;
18
+ export const UpdateExpression = unaryExpression;
21
19
 
22
- module.exports.AwaitExpression = maybeParens((path, {print}) => {
20
+ export const AwaitExpression = maybeParens((path, {print}) => {
23
21
  printUnary('await', {
24
22
  print,
25
23
  });
26
24
  });
27
25
 
28
- module.exports.YieldExpression = maybeParens((path, {print, maybe}) => {
26
+ export const YieldExpression = maybeParens((path, {print, maybe}) => {
29
27
  const {delegate} = path.node;
30
28
 
31
29
  print(`yield`);
@@ -34,7 +32,7 @@ module.exports.YieldExpression = maybeParens((path, {print, maybe}) => {
34
32
  print('__argument');
35
33
  });
36
34
 
37
- module.exports.ThrowStatement = (path, {print, indent, maybe}) => {
35
+ export const ThrowStatement = (path, {print, indent, maybe}) => {
38
36
  indent();
39
37
 
40
38
  printUnary('throw', {
@@ -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
  isIdentifier,
@@ -14,10 +13,10 @@ const {
14
13
  isLabeledStatement,
15
14
  } = types;
16
15
 
17
- const isParentProgram = (path) => path.parentPath?.isProgram();
18
- const isParentBlock = (path) => path.parentPath.isBlockStatement();
16
+ export const isParentProgram = (path) => path.parentPath?.isProgram();
17
+ export const isParentBlock = (path) => path.parentPath.isBlockStatement();
19
18
 
20
- const isNext = (path) => {
19
+ export const isNext = (path) => {
21
20
  const next = path.getNextSibling();
22
21
 
23
22
  if (!next.node)
@@ -26,35 +25,30 @@ const isNext = (path) => {
26
25
  return !next.isEmptyStatement();
27
26
  };
28
27
 
29
- const isPrev = (path) => {
28
+ export const isPrev = (path) => {
30
29
  const next = path.getPrevSibling();
31
30
  return next.node;
32
31
  };
33
32
 
34
- const isNextParent = (path) => isNext(path.parentPath);
35
- const isLast = (path) => isParentProgram(path) && !isNext(path);
33
+ export const isNextParent = (path) => isNext(path.parentPath);
34
+ export const isLast = (path) => isParentProgram(path) && !isNext(path);
36
35
 
37
- module.exports.isNextObject = (a) => a
36
+ export const isNextObject = (a) => a
38
37
  .getNextSibling()
39
38
  .isObjectExpression();
40
39
 
41
- module.exports.isPrevObject = (a) => a
40
+ export const isPrevObject = (a) => a
42
41
  .getPrevSibling()
43
42
  .isObjectExpression();
44
43
 
45
- module.exports.isFirst = (path) => path.node === path.parentPath.node.body?.[0];
46
- module.exports.isPrevBody = (path) => path
44
+ export const isFirst = (path) => path.node === path.parentPath.node.body?.[0];
45
+ export const isPrevBody = (path) => path
47
46
  .getPrevSibling()
48
47
  .isBlockStatement();
49
- module.exports.isNext = isNext;
50
- module.exports.isPrev = isPrev;
51
- module.exports.isNextParent = isNextParent;
52
- module.exports.isParentProgram = isParentProgram;
53
- module.exports.isParentBlock = isParentBlock;
54
- module.exports.isLast = isLast;
55
- module.exports.isParentLast = (path) => isLast(path.parentPath);
56
-
57
- module.exports.isIndented = (path = {}) => {
48
+
49
+ export const isParentLast = (path) => isLast(path.parentPath);
50
+
51
+ export const isIndented = (path = {}) => {
58
52
  const {parentPath, node} = path;
59
53
 
60
54
  if (!parentPath.node.loc)
@@ -63,18 +57,16 @@ module.exports.isIndented = (path = {}) => {
63
57
  return node.loc?.start.column !== parentPath.node.loc.start.column;
64
58
  };
65
59
 
66
- module.exports.isCoupleLines = isCoupleLines;
67
-
68
- function isCoupleLines(path) {
60
+ export function isCoupleLines(path) {
69
61
  const start = path.node?.loc?.start?.line;
70
62
  const end = path.node?.loc?.end?.line;
71
63
 
72
64
  return end !== start;
73
65
  }
74
66
 
75
- module.exports.exists = (a) => a.node;
76
- module.exports.isStringAndIdentifier = isStringAndIdentifier;
77
- function isStringAndIdentifier([a, b]) {
67
+ export const exists = (a) => a.node;
68
+
69
+ export function isStringAndIdentifier([a, b]) {
78
70
  return isStringLiteral(a) && isIdentifier(b);
79
71
  }
80
72
 
@@ -90,7 +82,7 @@ const checkObject = (elements) => {
90
82
  return a.node.properties.length;
91
83
  };
92
84
 
93
- module.exports.isSimpleAndNotEmptyObject = (elements) => {
85
+ export const isSimpleAndNotEmptyObject = (elements) => {
94
86
  const [a] = elements;
95
87
 
96
88
  const simpleTypes = [
@@ -107,13 +99,13 @@ module.exports.isSimpleAndNotEmptyObject = (elements) => {
107
99
  return checkObject(elements);
108
100
  };
109
101
 
110
- module.exports.isIdentifierAndIdentifier = ([a, b]) => {
102
+ export const isIdentifierAndIdentifier = ([a, b]) => {
111
103
  return isIdentifier(a) && isIdentifier(b);
112
104
  };
113
105
 
114
- module.exports.isStringAndMember = ([a, b]) => isStringLiteral(a) && isMemberExpression(b);
115
- module.exports.isIdentifierAndString = ([a, b]) => isIdentifier(a) && isStringLiteral(b);
116
- module.exports.isStringAndArray = ([a, b]) => {
106
+ export const isStringAndMember = ([a, b]) => isStringLiteral(a) && isMemberExpression(b);
107
+ export const isIdentifierAndString = ([a, b]) => isIdentifier(a) && isStringLiteral(b);
108
+ export const isStringAndArray = ([a, b]) => {
117
109
  if (!isStringLiteral(a))
118
110
  return false;
119
111
 
@@ -126,9 +118,9 @@ module.exports.isStringAndArray = ([a, b]) => {
126
118
  const isIfOrStatement = (a) => isIfStatement(a) || isStatement(a);
127
119
  const isForOfOrStatement = (a) => isForOfStatement(a) || isStatement(a);
128
120
 
129
- module.exports.isIf = (path) => isIfStatement(path.find(isIfOrStatement));
121
+ export const isIf = (path) => isIfStatement(path.find(isIfOrStatement));
130
122
 
131
- module.exports.isForOf = (path) => {
123
+ export const isForOf = (path) => {
132
124
  const current = path.find(isForOfOrStatement);
133
125
 
134
126
  if (isForOfStatement(current))
@@ -140,9 +132,9 @@ module.exports.isForOf = (path) => {
140
132
  return false;
141
133
  };
142
134
 
143
- module.exports.isInsideIf = (path) => path.parentPath?.isIfStatement();
135
+ export const isInsideIf = (path) => path.parentPath?.isIfStatement();
144
136
 
145
- module.exports.isNewlineBetweenSiblings = (path) => {
137
+ export const isNewlineBetweenSiblings = (path) => {
146
138
  const endCurrent = path.node?.loc?.end?.line;
147
139
  const startNext = path.getNextSibling().node?.loc?.start?.line;
148
140
 
@@ -152,9 +144,9 @@ module.exports.isNewlineBetweenSiblings = (path) => {
152
144
  return startNext - endCurrent > 1;
153
145
  };
154
146
 
155
- module.exports.isInsideLabel = ({parentPath}) => isLabeledStatement(parentPath);
147
+ export const isInsideLabel = ({parentPath}) => isLabeledStatement(parentPath);
156
148
 
157
- module.exports.satisfy = (conditions) => (path) => {
149
+ export const satisfy = (conditions) => (path) => {
158
150
  for (const condition of conditions)
159
151
  if (condition(path))
160
152
  return true;
@@ -164,17 +156,17 @@ module.exports.satisfy = (conditions) => (path) => {
164
156
 
165
157
  const parseNode = (path) => path.node || path;
166
158
 
167
- module.exports.hasCoupleTrailingComments = (path) => {
159
+ export const hasCoupleTrailingComments = (path) => {
168
160
  const node = parseNode(path);
169
161
  return node?.trailingComments?.length > 1;
170
162
  };
171
163
 
172
- module.exports.hasTrailingComment = (path) => {
164
+ export const hasTrailingComment = (path) => {
173
165
  const node = parseNode(path);
174
166
  return node.trailingComments?.length;
175
167
  };
176
168
 
177
- module.exports.hasLeadingComment = (path) => path.node?.leadingComments?.length;
169
+ export const hasLeadingComment = (path) => path.node?.leadingComments?.length;
178
170
 
179
- module.exports.noTrailingComment = (path) => !path.node.trailingComments?.length;
180
- module.exports.noLeadingComment = (path) => !path.node.leadingComments?.length;
171
+ export const noTrailingComment = (path) => !path.node.trailingComments?.length;
172
+ export const noLeadingComment = (path) => !path.node.leadingComments?.length;
@@ -1,48 +1,41 @@
1
- 'use strict';
1
+ import {isCoupleLines} from '#is';
2
+ import {parseComments} from '../comment/comment.js';
2
3
 
3
- const {JSXElement} = require('./jsx-element');
4
- const {JSXAttribute} = require('./jsx-attribute');
5
- const {isCoupleLines} = require('../is');
6
- const {JSXOpeningElement} = require('./jsx-opening-element');
7
- const fragments = require('./jsx-fragment');
8
- const {JSXText} = require('./jsx-text/jsx-text');
9
- const {parseComments} = require('../comment/comment');
4
+ export {JSXElement} from './jsx-element.js';
5
+ export {JSXAttribute} from './jsx-attribute.js';
6
+ export {JSXOpeningElement} from './jsx-opening-element.js';
7
+ export * from './jsx-fragment.js';
8
+ export {JSXText} from './jsx-text/jsx-text.js';
10
9
 
11
- module.exports = {
12
- ...fragments,
13
- JSXElement,
14
- JSXAttribute,
15
- JSXOpeningElement,
16
- JSXText,
17
- JSXEmptyExpression(path, operations, semantics) {
18
- parseComments(path, operations, semantics);
19
- },
20
- JSXExpressionContainer(path, {print}) {
21
- print('{');
22
- print('__expression');
23
- print('}');
24
- },
25
- JSXIdentifier(path, {write}) {
26
- write(path.node.name);
27
- },
28
- JSXMemberExpression(path, {print}) {
29
- print('__object');
30
- print('.');
31
- print('__property');
32
- },
33
- JSXSpreadAttribute(path, {print, maybe}) {
34
- const isNewline = isCoupleLines(path.parentPath);
35
- maybe.indent.inc(isNewline);
36
- maybe.print.breakline(isNewline);
37
- print('{');
38
- print('...');
39
- print('__argument');
40
- print('}');
41
- maybe.indent.dec(isNewline);
42
- },
43
- JSXClosingElement(path, {print}) {
44
- print('</');
45
- print('__name');
46
- print('>');
47
- },
10
+ export const JSXEmptyExpression = (path, operations, semantics) => {
11
+ parseComments(path, operations, semantics);
48
12
  };
13
+ export const JSXExpressionContainer = (path, {print}) => {
14
+ print('{');
15
+ print('__expression');
16
+ print('}');
17
+ };
18
+ export const JSXIdentifier = (path, {write}) => {
19
+ write(path.node.name);
20
+ };
21
+ export const JSXMemberExpression = (path, {print}) => {
22
+ print('__object');
23
+ print('.');
24
+ print('__property');
25
+ };
26
+ export const JSXSpreadAttribute = (path, {print, maybe}) => {
27
+ const isNewline = isCoupleLines(path.parentPath);
28
+ maybe.indent.inc(isNewline);
29
+ maybe.print.breakline(isNewline);
30
+ print('{');
31
+ print('...');
32
+ print('__argument');
33
+ print('}');
34
+ maybe.indent.dec(isNewline);
35
+ };
36
+ export const JSXClosingElement = (path, {print}) => {
37
+ print('</');
38
+ print('__name');
39
+ print('>');
40
+ };
41
+
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {isCoupleLines} from '../is.js';
2
2
 
3
- const {isCoupleLines} = require('../is');
4
-
5
- module.exports.JSXAttribute = {
3
+ export const JSXAttribute = {
6
4
  condition(path) {
7
5
  return isCoupleLines(path.parentPath);
8
6
  },
@@ -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
  isJSXElement,
6
5
  isJSXExpressionContainer,
@@ -10,7 +9,7 @@ const {
10
9
 
11
10
  const isInsideArrow = ({parentPath}) => parentPath.isArrowFunctionExpression();
12
11
 
13
- module.exports.JSXElement = {
12
+ export const JSXElement = {
14
13
  condition,
15
14
  before(path, {write, indent, maybe}) {
16
15
  const {leadingComments} = path.node;
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.JSXFragment = {
1
+ export const JSXFragment = {
4
2
  condition,
5
3
  before(path, {write, indent}) {
6
4
  write('(');
@@ -19,11 +17,11 @@ module.exports.JSXFragment = {
19
17
  },
20
18
  };
21
19
 
22
- module.exports.JSXOpeningFragment = (path, {write}) => {
20
+ export const JSXOpeningFragment = (path, {write}) => {
23
21
  write('<>');
24
22
  };
25
23
 
26
- module.exports.JSXClosingFragment = (path, {write}) => {
24
+ export const JSXClosingFragment = (path, {write}) => {
27
25
  write('</>');
28
26
  };
29
27