@putout/printer 16.6.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 +11 -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 +10 -15
  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,6 +1,4 @@
1
- 'use strict';
2
-
3
- const {isCoupleLines} = require('../is');
1
+ import {isCoupleLines} from '../is.js';
4
2
 
5
3
  const isNotJSX = ({parentPath}) => {
6
4
  const grandPath = parentPath.parentPath;
@@ -23,7 +21,7 @@ const isNotJSX = ({parentPath}) => {
23
21
  return !grandPath.isLogicalExpression();
24
22
  };
25
23
 
26
- module.exports.JSXOpeningElement = {
24
+ export const JSXOpeningElement = {
27
25
  print(path, {print, maybe}) {
28
26
  maybe.indent(isNotJSX(path));
29
27
  print('<');
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {isNext} from '#is';
2
2
 
3
- const {isNext} = require('#is');
4
-
5
- module.exports.JSXText = (path, {write, indent}) => {
3
+ export const JSXText = (path, {write, indent}) => {
6
4
  const {node} = path;
7
5
  const {value, extra} = node;
8
6
  const isSpacesOnly = /^\s+$/.test(value);
@@ -1,9 +1,8 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
2
 
3
- const {types} = require('@putout/babel');
4
3
  const {isMemberExpression} = types;
5
4
 
6
- module.exports.Decorator = (path, {print, maybe}) => {
5
+ export const Decorator = (path, {print, maybe}) => {
7
6
  const {expression} = path.node;
8
7
  const isMember = isMemberExpression(expression);
9
8
 
@@ -14,7 +13,7 @@ module.exports.Decorator = (path, {print, maybe}) => {
14
13
  maybe.print(isMember, ')');
15
14
  };
16
15
 
17
- module.exports.Decorator.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
16
+ Decorator.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
18
17
  const {print} = printer;
19
18
  printComment();
20
19
  print.breakline();
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.DirectiveLiteral = (path, {write}) => {
1
+ export const DirectiveLiteral = (path, {write}) => {
4
2
  write.indent();
5
3
  write(path.node.raw || `'${path.node.value}'`);
6
4
  write(';');
@@ -1,10 +1,8 @@
1
- 'use strict';
1
+ import {maybeDecorators} from '../maybe-get.js';
2
+ import {maybeParens} from '../maybe/maybe-parens.js';
3
+ import {maybeTypeAnnotation} from '../maybe/maybe-type-annotation.js';
2
4
 
3
- const {maybeDecorators} = require('../maybe-get');
4
- const {maybeParens} = require('../maybe/maybe-parens');
5
- const {maybeTypeAnnotation} = require('../maybe/maybe-type-annotation');
6
-
7
- module.exports.Identifier = maybeParens(maybeTypeAnnotation((path, printer) => {
5
+ export const Identifier = maybeParens(maybeTypeAnnotation((path, printer) => {
8
6
  const {
9
7
  write,
10
8
  maybe,
@@ -1,50 +1,46 @@
1
- 'use strict';
2
-
3
- const {TemplateLiteral} = require('./template-literal');
4
- const {Identifier} = require('./identifier');
5
-
6
- const {Decorator} = require('../expressions/decorator/decorator');
7
- const {StringLiteral} = require('./string-literal');
8
- const {DirectiveLiteral} = require('./directive-literal');
9
- const {VoidPattern} = require('./void-pattern/void-pattern');
10
-
11
- module.exports = {
12
- Identifier,
13
- Decorator,
14
- DirectiveLiteral,
15
- TemplateLiteral,
16
- VoidPattern,
17
- BigIntLiteral(path, {write}) {
18
- write(path.node.raw);
19
- },
20
- NumericLiteral(path, {write}) {
21
- const {
22
- raw,
23
- extra,
24
- value,
25
- } = path.node;
26
-
27
- write(raw || extra?.raw || value);
28
- },
29
- Directive(path, {print, maybe}) {
30
- maybe.print.breakline(path.node.leadingComments?.length);
31
- print('__value');
32
- },
33
- BooleanLiteral(path, {write}) {
34
- write(path.node.value);
35
- },
36
- StringLiteral,
37
- RegExpLiteral(path, {print}) {
38
- const {raw, pattern} = path.node;
39
- print(raw || `/${pattern}/`);
40
- },
41
- NullLiteral(path, {write}) {
42
- write('null');
43
- },
44
- MetaProperty(path, {write}) {
45
- write('import.meta');
46
- },
47
- Super(path, {write}) {
48
- write('super');
49
- },
1
+ export {TemplateLiteral} from './template-literal.js';
2
+ export {Identifier} from './identifier.js';
3
+ export {Decorator} from './decorator/decorator.js';
4
+ export {StringLiteral} from './string-literal.js';
5
+ export {DirectiveLiteral} from './directive-literal.js';
6
+ export {VoidPattern} from './void-pattern/void-pattern.js';
7
+ export const BigIntLiteral = (path, {write}) => {
8
+ write(path.node.raw);
50
9
  };
10
+
11
+ export const NumericLiteral = (path, {write}) => {
12
+ const {
13
+ raw,
14
+ extra,
15
+ value,
16
+ } = path.node;
17
+
18
+ write(raw || extra?.raw || value);
19
+ };
20
+
21
+ export const Directive = (path, {print, maybe}) => {
22
+ maybe.print.breakline(path.node.leadingComments?.length);
23
+ print('__value');
24
+ };
25
+
26
+ export const BooleanLiteral = (path, {write}) => {
27
+ write(path.node.value);
28
+ };
29
+
30
+ export const RegExpLiteral = (path, {print}) => {
31
+ const {raw, pattern} = path.node;
32
+ print(raw || `/${pattern}/`);
33
+ };
34
+
35
+ export const NullLiteral = (path, {write}) => {
36
+ write('null');
37
+ };
38
+
39
+ export const MetaProperty = (path, {write}) => {
40
+ write('import.meta');
41
+ };
42
+
43
+ export const Super = (path, {write}) => {
44
+ write('super');
45
+ };
46
+
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.StringLiteral = (path, {write}, semantics) => {
1
+ export const StringLiteral = (path, {write}, semantics) => {
4
2
  const {value, raw = `'${value}'`} = path.node;
5
3
 
6
4
  if (path.parentPath.isJSXAttribute()) {
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {writeTemplateLiteral} from './write-template-literal.js';
2
2
 
3
- const {writeTemplateLiteral} = require('./write-template-literal');
4
-
5
- module.exports.TemplateLiteral = (path, printer) => {
3
+ export const TemplateLiteral = (path, printer) => {
6
4
  const expressions = path.get('expressions');
7
5
  const quasis = path.get('quasis');
8
6
 
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
- module.exports.VoidPattern = (path, {write}) => {
1
+ export const VoidPattern = (path, {write}) => {
4
2
  write('void');
5
3
  };
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.writeTemplateLiteral = (quasis, expressions, {write, traverse}) => {
1
+ export const writeTemplateLiteral = (quasis, expressions, {write, traverse}) => {
4
2
  write('`');
5
3
  let i = 0;
6
4
 
@@ -1,26 +1,20 @@
1
- 'use strict';
2
-
3
1
  const WATER_MARK_BEFORE = '__putout_newline_before';
4
2
  const WATER_MARK_AFTER = '__putout_newline_after';
5
3
 
6
- module.exports.markBefore = markBefore;
7
- module.exports.markAfter = markAfter;
8
- module.exports.maybeMarkAfter = (a, path) => a && markAfter(path);
4
+ export const maybeMarkAfter = (a, path) => a && markAfter(path);
9
5
 
10
- function markBefore(path) {
6
+ export function markBefore(path) {
11
7
  path[WATER_MARK_BEFORE] = true;
12
8
  }
13
9
 
14
- function markAfter(path) {
10
+ export function markAfter(path) {
15
11
  path[WATER_MARK_AFTER] = true;
16
12
  }
17
13
 
18
- module.exports.isMarkedAfter = isMarkedAfter;
19
-
20
- function isMarkedAfter(path) {
14
+ export function isMarkedAfter(path) {
21
15
  return path[WATER_MARK_AFTER];
22
16
  }
23
17
 
24
- module.exports.hasPrevNewline = (path) => {
18
+ export const hasPrevNewline = (path) => {
25
19
  return isMarkedAfter(path.getPrevSibling());
26
20
  };
@@ -1,9 +1,6 @@
1
- 'use strict';
2
-
3
- const rendy = require('rendy');
4
-
5
- const {types} = require('@putout/babel');
6
- const maybeSatisfy = require('./satisfy');
1
+ import rendy from 'rendy';
2
+ import {types} from '@putout/babel';
3
+ import maybeSatisfy from './satisfy.js';
7
4
 
8
5
  const {
9
6
  isProgram,
@@ -16,7 +13,7 @@ const {
16
13
 
17
14
  const isFn = (a) => typeof a === 'function';
18
15
 
19
- module.exports.maybeThrow = (a, path, b) => {
16
+ export const maybeThrow = (a, path, b) => {
20
17
  if (!a)
21
18
  return;
22
19
 
@@ -32,9 +29,9 @@ const maybeProgram = (ast) => isProgram(ast) ? ast : program([
32
29
  maybeStatement(ast),
33
30
  ]);
34
31
 
35
- module.exports.maybeFile = (ast) => isFile(ast) ? ast : file(maybeProgram(ast));
32
+ export const maybeFile = (ast) => isFile(ast) ? ast : file(maybeProgram(ast));
36
33
 
37
- module.exports.maybeVisitor = (plugin, path, printer, options) => {
34
+ export const maybeVisitor = (plugin, path, printer, options) => {
38
35
  if (isFn(plugin))
39
36
  return plugin(path, printer, options);
40
37
 
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.maybeDeclare = (visit) => (path, printer, semantics) => {
1
+ export const maybeDeclare = (visit) => (path, printer, semantics) => {
4
2
  const {maybe} = printer;
5
3
  const {declare} = path.node;
6
4
 
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  const isPrevClassProperty = (path) => {
4
2
  const prev = path.getPrevSibling();
5
3
 
@@ -9,7 +7,7 @@ const isPrevClassProperty = (path) => {
9
7
  return prev.isClassProperty() || prev.isClassAccessorProperty();
10
8
  };
11
9
 
12
- module.exports.maybeDecorators = (visitor) => (path, printer, semantics, options) => {
10
+ export const maybeDecorators = (visitor) => (path, printer, semantics, options) => {
13
11
  const {
14
12
  write,
15
13
  traverse,
@@ -1,10 +1,8 @@
1
- 'use strict';
2
-
3
1
  const isFn = (a) => typeof a === 'function';
4
- const isParens = (path) => path.node.extra?.parenthesized;
5
2
 
6
- module.exports.isParens = isParens;
7
- module.exports.maybeParens = (print) => {
3
+ export const isParens = (path) => path.node.extra?.parenthesized;
4
+
5
+ export const maybeParens = (print) => {
8
6
  if (isFn(print))
9
7
  return maybeParensPrint(print);
10
8
 
@@ -1,20 +1,17 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
2
 
3
- const {types} = require('@putout/babel');
4
3
  const {
5
4
  isMemberExpression,
6
5
  isSequenceExpression,
7
6
  } = types;
8
7
 
9
- module.exports.maybePrintTypeAnnotation = maybePrintTypeAnnotation;
10
-
11
- module.exports.maybeTypeAnnotation = (visit) => (path, printer, semantics) => {
8
+ export const maybeTypeAnnotation = (visit) => (path, printer, semantics) => {
12
9
  visit(path, printer, semantics);
13
10
 
14
11
  maybePrintTypeAnnotation(path, printer);
15
12
  };
16
13
 
17
- function maybePrintTypeAnnotation(path, printer) {
14
+ export function maybePrintTypeAnnotation(path, printer) {
18
15
  const {parentPath, node} = path;
19
16
 
20
17
  const {typeAnnotation} = node;
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {satisfy} from '../is.js';
2
2
 
3
- const {satisfy} = require('../is');
4
-
5
- module.exports = (plugin) => {
3
+ export default (plugin) => {
6
4
  if (!plugin.afterSatisfy && !plugin.beforeSatisfy && !plugin.satisfy)
7
5
  return plugin;
8
6
 
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.maybeDecorators = (path) => {
1
+ export const maybeDecorators = (path) => {
4
2
  if (!path.node.decorators)
5
3
  return [];
6
4
 
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import {parseRoundBraces} from './parse-round-braces.js';
2
+ import {parseQuotes} from './parse-quotes.js';
2
3
 
3
- const {parseRoundBraces} = require('./parse-round-braces');
4
- const {parseQuotes} = require('./parse-quotes');
5
-
6
- module.exports.parseOverrides = (overrides = {}) => {
4
+ export const parseOverrides = (overrides = {}) => {
7
5
  const {
8
6
  format,
9
7
  semantics,
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.parseQuotes = ({quote}) => {
1
+ export const parseQuotes = ({quote}) => {
4
2
  if (quote === '"')
5
3
  return {
6
4
  escapeSingleQuote: false,
@@ -1,30 +1,28 @@
1
- 'use strict';
2
-
3
1
  const isObject = (a) => a && typeof a === 'object';
4
2
  const isBool = (a) => typeof a === 'boolean';
5
3
 
6
- const ROUND_BRACES_DEFAULTS = {
4
+ export const ROUND_BRACES_DEFAULTS = {
7
5
  arrow: true,
8
6
  sequence: true,
9
7
  assign: false,
10
8
  new: true,
11
9
  };
12
10
 
13
- const ROUND_BRACES_ENABLED = {
11
+ export const ROUND_BRACES_ENABLED = {
14
12
  arrow: true,
15
13
  sequence: true,
16
14
  assign: true,
17
15
  new: true,
18
16
  };
19
17
 
20
- const ROUND_BRACES_DISABLED = {
18
+ export const ROUND_BRACES_DISABLED = {
21
19
  arrow: false,
22
20
  sequence: false,
23
21
  assign: false,
24
22
  new: false,
25
23
  };
26
24
 
27
- module.exports.parseRoundBraces = ({roundBraces}) => {
25
+ export const parseRoundBraces = ({roundBraces}) => {
28
26
  if (isObject(roundBraces))
29
27
  return {
30
28
  ...ROUND_BRACES_DEFAULTS,
@@ -39,7 +37,3 @@ module.exports.parseRoundBraces = ({roundBraces}) => {
39
37
 
40
38
  return ROUND_BRACES_DEFAULTS;
41
39
  };
42
-
43
- module.exports.ROUND_BRACES_DISABLED = ROUND_BRACES_DISABLED;
44
- module.exports.ROUND_BRACES_ENABLED = ROUND_BRACES_ENABLED;
45
- module.exports.ROUND_BRACES_DEFAULTS = ROUND_BRACES_DEFAULTS;
@@ -1,20 +1,17 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
- const {
1
+ import {types} from '@putout/babel';
2
+ import {markAfter} from '../../mark.js';
3
+ import {parseComments} from '../../comment/comment.js';
4
+ import {
5
5
  isNext,
6
6
  isParentProgram,
7
7
  isLast,
8
8
  exists,
9
9
  satisfy,
10
- } = require('../../is');
11
-
12
- const {markAfter} = require('../../mark');
13
- const {parseComments} = require('../../comment/comment');
14
- const {insideIfWithNoBody} = require('./inside-if-with-no-body');
15
- const {getDirectives} = require('./get-directives');
10
+ } from '../../is.js';
11
+ import {insideIfWithNoBody} from './inside-if-with-no-body.js';
12
+ import {getDirectives} from './get-directives.js';
13
+ import {isCallInsideChain} from './is-call-inside-chain.js';
16
14
 
17
- const {isCallInsideChain} = require('./is-call-inside-chain');
18
15
  const {
19
16
  isArrowFunctionExpression,
20
17
  isObjectMethod,
@@ -47,7 +44,7 @@ const parentIfWithoutElse = ({parentPath}) => {
47
44
  return !parentPath.node.alternate;
48
45
  };
49
46
 
50
- module.exports.BlockStatement = {
47
+ export const BlockStatement = {
51
48
  print(path, printer, semantics) {
52
49
  const {trailingComma} = semantics;
53
50
  const {
@@ -1,3 +1 @@
1
- 'use strict';
2
-
3
- module.exports.getDirectives = (path) => !path.node.directives ? [] : path.get('directives');
1
+ export const getDirectives = (path) => !path.node.directives ? [] : path.get('directives');
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {exists} from '../../is.js';
2
2
 
3
- const {exists} = require('../../is');
4
-
5
- module.exports.insideIfWithNoBody = (path) => {
3
+ export const insideIfWithNoBody = (path) => {
6
4
  if (!path.parentPath.isIfStatement())
7
5
  return false;
8
6
 
@@ -1,7 +1,6 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
+ import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain.js';
2
3
 
3
- const {types} = require('@putout/babel');
4
- const {isLooksLikeChain} = require('../../expressions/member-expression/is-looks-like-chain');
5
4
  const {
6
5
  isReturnStatement,
7
6
  isExpressionStatement,
@@ -9,7 +8,7 @@ const {
9
8
  isCallExpression,
10
9
  } = types;
11
10
 
12
- module.exports.isCallInsideChain = (path) => {
11
+ export const isCallInsideChain = (path) => {
13
12
  if (!isCallExpression(path.parentPath.parentPath))
14
13
  return false;
15
14
 
@@ -1,15 +1,13 @@
1
- 'use strict';
2
-
3
- const {
1
+ import {
4
2
  isParentBlock,
5
3
  isNextParent,
6
4
  isInsideIf,
7
5
  isInsideLabel,
8
- } = require('../../is');
6
+ } from '../../is.js';
9
7
 
10
8
  const isInsideCase = (path) => path.parentPath.isSwitchCase();
11
9
 
12
- module.exports.BreakStatement = {
10
+ export const BreakStatement = {
13
11
  split(path, {print}) {
14
12
  print.newline();
15
13
  },
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {isInsideLabel} from '../../is.js';
2
2
 
3
- const {isInsideLabel} = require('../../is');
4
-
5
- module.exports.ContinueStatement = (path, {print, maybe, write}) => {
3
+ export const ContinueStatement = (path, {print, maybe, write}) => {
6
4
  const {label} = path.node;
7
5
 
8
6
  maybe.indent(!isInsideLabel(path));
@@ -1,9 +1,8 @@
1
- 'use strict';
1
+ import {isNext, isInsideIf} from '../is.js';
2
2
 
3
- const {isNext, isInsideIf} = require('../is');
4
3
  const isInsideBlock = (path) => path.parentPath.isBlockStatement();
5
4
 
6
- module.exports.DebuggerStatement = {
5
+ export const DebuggerStatement = {
7
6
  print(path, {print, indent}) {
8
7
  indent();
9
8
  print('debugger;');
@@ -1,9 +1,8 @@
1
- 'use strict';
1
+ import {isLast} from '#is';
2
2
 
3
- const {isLast} = require('#is');
4
3
  const notLast = (path) => !isLast(path);
5
4
 
6
- module.exports.DoWhileStatement = {
5
+ export const DoWhileStatement = {
7
6
  print(path, {print, indent}) {
8
7
  indent();
9
8
  print('do');
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {isLast} from '#is';
2
2
 
3
- const {isLast} = require('#is');
4
-
5
- module.exports.EmptyStatement = (path, {write, maybe}) => {
3
+ export const EmptyStatement = (path, {write, maybe}) => {
6
4
  const {parentPath} = path;
7
5
  write(';');
8
6
  maybe.write.newline(!isLast(path) && !isLast(parentPath));
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.ExportAllDeclaration = (path, {print}) => {
1
+ export const ExportAllDeclaration = (path, {print}) => {
4
2
  const {exportKind} = path.node;
5
3
  print('export ');
6
4
 
@@ -1,20 +1,16 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
-
5
- const {isParentBlock} = require('#is');
6
- const {
1
+ import {types} from '@putout/babel';
2
+ import {isParentBlock} from '#is';
3
+ import {
7
4
  markAfter,
8
5
  isMarkedAfter,
9
6
  hasPrevNewline,
10
- } = require('../../mark');
11
-
12
- const {
7
+ } from '../../mark.js';
8
+ import {
13
9
  isNewlineBetweenSiblings,
14
10
  exists,
15
11
  isNext,
16
12
  isLast,
17
- } = require('../../is');
13
+ } from '../../is.js';
18
14
 
19
15
  const {
20
16
  isExportNamespaceSpecifier,
@@ -32,7 +28,7 @@ const options = {
32
28
  },
33
29
  };
34
30
 
35
- module.exports.ExportSpecifier = (path, {print}) => {
31
+ export const ExportSpecifier = (path, {print}) => {
36
32
  const {local, exported} = path.node;
37
33
 
38
34
  print('__local');
@@ -43,16 +39,16 @@ module.exports.ExportSpecifier = (path, {print}) => {
43
39
  }
44
40
  };
45
41
 
46
- module.exports.ExportNamespaceSpecifier = (path, {print}) => {
42
+ export const ExportNamespaceSpecifier = (path, {print}) => {
47
43
  print('* as ');
48
44
  print('__exported');
49
45
  };
50
46
 
51
- module.exports.ExportDefaultSpecifier = (path, {print}) => {
47
+ export const ExportDefaultSpecifier = (path, {print}) => {
52
48
  print('__exported');
53
49
  };
54
50
 
55
- module.exports.ExportNamedDeclaration = {
51
+ export const ExportNamedDeclaration = {
56
52
  beforeIf(path) {
57
53
  const prev = path.getPrevSibling();
58
54
 
@@ -176,4 +172,3 @@ module.exports.ExportNamedDeclaration = {
176
172
  markAfter(path);
177
173
  },
178
174
  };
179
-