@putout/printer 16.6.0 → 17.0.1

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 +23 -0
  2. package/README.md +6 -6
  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 +27 -72
  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 +37 -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 +41 -46
  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 +27 -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 +171 -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 +15 -15
@@ -1,26 +1,20 @@
1
- 'use strict';
2
-
3
- const fullstore = require('fullstore');
4
-
5
- const babelTraverse = require('@putout/babel').traverse;
6
- const {TYPES} = require('../types');
7
- const baseVisitors = require('./visitors');
8
-
9
- const {
1
+ import {fullstore} from 'fullstore';
2
+ import {traverse as babelTraverse} from '@putout/babel';
3
+ import {TYPES} from '../types.js';
4
+ import * as baseVisitors from './visitors.js';
5
+ import {
10
6
  maybeFile,
11
7
  maybeVisitor,
12
8
  maybeThrow,
13
- } = require('./maybe');
14
-
15
- const {createDebug, createLog} = require('./debug');
16
- const {maybeMarkAfter} = require('./mark');
17
-
18
- const {
9
+ } from './maybe/index.js';
10
+ import {createDebug, createLog} from './debug.js';
11
+ import {maybeMarkAfter} from './mark.js';
12
+ import {
19
13
  parseLeadingComments,
20
14
  parseTrailingComments,
21
- } = require('./comment/comment');
15
+ } from './comment/comment.js';
16
+ import {parseOverrides} from './overrides/overrides.js';
22
17
 
23
- const {parseOverrides} = require('./overrides/overrides');
24
18
  const isObject = (a) => a && typeof a === 'object';
25
19
  const {round} = Math;
26
20
  const isString = (a) => typeof a === 'string';
@@ -38,7 +32,7 @@ const createAddToken = (tokens) => {
38
32
  };
39
33
  };
40
34
 
41
- module.exports.tokenize = (ast, overrides) => {
35
+ export const tokenize = (ast, overrides) => {
42
36
  const {
43
37
  visitors,
44
38
  format,
@@ -1,14 +1,11 @@
1
- 'use strict';
2
-
3
- const {
1
+ import {
4
2
  isNext,
5
3
  isNextParent,
6
4
  isLast,
7
- } = require('../../is');
8
-
9
- const {markAfter} = require('../../mark');
5
+ } from '../../is.js';
6
+ import {markAfter} from '../../mark.js';
10
7
 
11
- module.exports.TSEnumDeclaration = {
8
+ export const TSEnumDeclaration = {
12
9
  beforeIf(path) {
13
10
  return path.node.const;
14
11
  },
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports.TSEnumMember = (path, {print, indent}) => {
1
+ export const TSEnumMember = (path, {print, indent}) => {
4
2
  const {initializer} = path.node;
5
3
  indent();
6
4
  print('__id');
@@ -1,7 +1,5 @@
1
- 'use strict';
1
+ export const hasReturnType = (path) => path.node.returnType;
2
2
 
3
- module.exports.hasReturnType = (path) => path.node.returnType;
4
-
5
- module.exports.printReturnType = (path, {traverse}) => {
3
+ export const printReturnType = (path, {traverse}) => {
6
4
  traverse(path.get('returnType'));
7
5
  };
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import {printReturnType} from './print-return-type.js';
2
+ import {printParams} from '../../expressions/function/params.js';
2
3
 
3
- const {printReturnType} = require('./print-return-type');
4
- const {printParams} = require('../../expressions/function/params');
5
-
6
- module.exports.TSCallSignatureDeclaration = (path, printer, semantics) => {
4
+ export const TSCallSignatureDeclaration = (path, printer, semantics) => {
7
5
  const {print} = printer;
8
6
  printParams(path, printer, semantics);
9
7
  print(':');
@@ -1,13 +1,10 @@
1
- 'use strict';
2
-
3
- const {printParams} = require('../../expressions/function/params');
4
-
5
- const {
1
+ import {printParams} from '../../expressions/function/params.js';
2
+ import {
6
3
  hasReturnType,
7
4
  printReturnType,
8
- } = require('./print-return-type');
5
+ } from './print-return-type.js';
9
6
 
10
- module.exports.TSConstructSignatureDeclaration = (path, printer, semantics) => {
7
+ export const TSConstructSignatureDeclaration = (path, printer, semantics) => {
11
8
  const {write} = printer;
12
9
 
13
10
  write('new');
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import {printParams} from '../../expressions/function/params.js';
2
+ import {printReturnType} from './print-return-type.js';
2
3
 
3
- const {printParams} = require('../../expressions/function/params');
4
- const {printReturnType} = require('./print-return-type');
5
-
6
- module.exports.TSConstructorType = (path, printer, semantics) => {
4
+ export const TSConstructorType = (path, printer, semantics) => {
7
5
  const {print} = printer;
8
6
 
9
7
  print('new');
@@ -1,8 +1,6 @@
1
- 'use strict';
2
-
3
- const {printParams} = require('../../expressions/function/params');
4
- const {isNext} = require('../../is');
5
- const {maybeDeclare} = require('../../maybe/maybe-declare');
1
+ import {printParams} from '../../expressions/function/params.js';
2
+ import {isNext} from '../../is.js';
3
+ import {maybeDeclare} from '../../maybe/maybe-declare.js';
6
4
 
7
5
  const isInsideDefaultExport = (path) => {
8
6
  return path.parentPath.isExportDefaultDeclaration();
@@ -12,7 +10,7 @@ const isInsideNamedExport = (path) => {
12
10
  return path.parentPath.isExportNamedDeclaration();
13
11
  };
14
12
 
15
- module.exports.TSDeclareFunction = {
13
+ export const TSDeclareFunction = {
16
14
  beforeIf: (path) => !isInsideNamedExport(path),
17
15
  before: (path, {indent}) => {
18
16
  indent();
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {printParams} from '../../expressions/function/params.js';
2
2
 
3
- const {printParams} = require('../../expressions/function/params');
4
-
5
- module.exports.TSDeclareMethod = (path, printer, semantics) => {
3
+ export const TSDeclareMethod = (path, printer, semantics) => {
6
4
  const {print} = printer;
7
5
  const {
8
6
  accessibility,
@@ -1,11 +1,8 @@
1
- 'use strict';
1
+ import {printParams} from '../../expressions/function/params.js';
2
+ import {printReturnType} from './print-return-type.js';
3
+ import {maybeParens} from '../../maybe/maybe-parens.js';
2
4
 
3
- const {printParams} = require('../../expressions/function/params');
4
- const {printReturnType} = require('./print-return-type');
5
-
6
- const {maybeParens} = require('../../maybe/maybe-parens');
7
-
8
- module.exports.TSFunctionType = maybeParens((path, printer, semantics) => {
5
+ export const TSFunctionType = maybeParens((path, printer, semantics) => {
9
6
  const {print} = printer;
10
7
 
11
8
  printParams(path, printer, semantics);
@@ -1,15 +1,12 @@
1
- 'use strict';
2
-
3
- const {printParams} = require('../../expressions/function/params');
4
- const {printKind} = require('../../expressions/function/kind');
5
- const {
1
+ import {printParams} from '../../expressions/function/params.js';
2
+ import {printKind} from '../../expressions/function/kind.js';
3
+ import {
6
4
  hasReturnType,
7
5
  printReturnType,
8
- } = require('./print-return-type');
9
-
10
- const {printKey} = require('../../expressions/object-expression/print-key');
6
+ } from './print-return-type.js';
7
+ import {printKey} from '../../expressions/object-expression/print-key.js';
11
8
 
12
- module.exports.TSMethodSignature = (path, printer, semantics) => {
9
+ export const TSMethodSignature = (path, printer, semantics) => {
13
10
  const {write} = printer;
14
11
 
15
12
  printKind(path, printer);
@@ -1,213 +1,177 @@
1
- 'use strict';
1
+ import {isNext} from '#is';
2
+ import {printParams} from '../expressions/function/params.js';
3
+ import {maybePrintTypeAnnotation} from '../maybe/maybe-type-annotation.js';
2
4
 
3
- const {isNext} = require('../is');
4
- const {TSTypeLiteral} = require('./type/ts-type-literal');
5
- const {TSTypeAliasDeclaration} = require('./type/ts-type-alias-declaration');
6
- const {TSMappedType} = require('./mapped-type/ts-mapped-type');
7
- const {TSConditionalType} = require('./ts-conditional-type');
8
- const {TSTypeParameter} = require('./type/ts-type-parameter');
9
- const {TSDeclareFunction} = require('./function/ts-declare-function');
10
- const {TSDeclareMethod} = require('./function/ts-declare-method');
5
+ export {TSTypeLiteral} from './type/ts-type-literal.js';
6
+ export {TSTypeAliasDeclaration} from './type/ts-type-alias-declaration.js';
7
+ export {TSMappedType} from './mapped-type/ts-mapped-type.js';
8
+ export {TSConditionalType} from './ts-conditional-type.js';
9
+ export {TSTypeParameter} from './type/ts-type-parameter.js';
10
+ export {TSDeclareFunction} from './function/ts-declare-function.js';
11
+ export {TSDeclareMethod} from './function/ts-declare-method.js';
12
+ export {TSModuleDeclaration, TSModuleBlock} from './namespace/ts-module-declaration.js';
13
+ export {TSInterfaceDeclaration} from './interface/ts-interface-declaration.js';
14
+ export {TSAsExpression} from './ts-as-expression/ts-as-expression.js';
15
+ export {TSInterfaceBody} from './interface/ts-interface-body.js';
16
+ export {TSIntersectionType} from './ts-intersection-type.js';
17
+ export {TSPropertySignature} from './ts-property-signature/ts-property-signature.js';
18
+ export {TSFunctionType} from './function/ts-function-type.js';
19
+ export {TSEnumDeclaration} from './enum/ts-enum-declaration.js';
20
+ export {TSEnumMember} from './enum/ts-enum-member.js';
21
+ export {TSTupleType} from './tuple/ts-tuple-type.js';
22
+ export {TSNamedTupleMember} from './tuple/ts-named-tuple-member.js';
23
+ export {TSConstructorType} from './function/ts-constructor-type.js';
24
+ export {TSCallSignatureDeclaration} from './function/ts-call-signature-declaration.js';
25
+ export {TSConstructSignatureDeclaration} from './function/ts-construct-signature-declaration.js';
26
+ export {TSMethodSignature} from './function/ts-method-signature.js';
27
+ export {TSUnionType} from './ts-union-type/ts-union-type.js';
28
+ export {TSImportType} from './ts-import-type/ts-import-type.js';
29
+ export {TSExportAssignment} from './ts-export-assignment/ts-export-assignment.js';
30
+ export {TSTypeReference} from './ts-type-reference/ts-type-reference.js';
31
+ export {TSInferType} from './ts-infer-type/ts-infer-type.js';
32
+ export {TSParameterProperty} from './ts-parameter-property/ts-parameter-property.js';
33
+ export {TSTypeParameterDeclaration} from './ts-type-parameter-declaration/ts-type-parameter-declaration.js';
34
+ export {TSTypeQuery} from './ts-type-query/ts-type-query.js';
35
+ export {TSParenthesizedType} from './ts-parenthesized-type/ts-parenthesized-type.js';
36
+ export {TSTemplateLiteralType} from './ts-template-literal-type/ts-template-literal-type.js';
37
+ export {TSOptionalType} from './ts-optional-type/ts-optional-type.js';
11
38
 
12
- const {
13
- TSModuleDeclaration,
14
- TSModuleBlock,
15
- } = require('./namespace/ts-module-declaration');
39
+ export const TSBigIntKeyword = (path, {write}) => {
40
+ write('bigint');
41
+ };
42
+ export const TSNullKeyword = (path, {write}) => {
43
+ write('null');
44
+ };
45
+ export const TSSymbolKeyword = (path, {write}) => {
46
+ write('symbol');
47
+ };
48
+ export const TSNeverKeyword = (path, {write}) => {
49
+ write('never');
50
+ };
51
+ export const TSUnknownKeyword = (path, {write}) => {
52
+ write('unknown');
53
+ };
54
+ export const TSObjectKeyword = (path, {write}) => {
55
+ write('object');
56
+ };
57
+ export const TSLiteralType = (path, {print}) => {
58
+ print('__literal');
59
+ };
60
+ export const TSRestType = (path, {print}) => {
61
+ print('...');
62
+ print('__typeAnnotation');
63
+ };
64
+ export const TSTypeParameterInstantiation = (path, printer, semantics) => {
65
+ printParams(path, printer, semantics, {
66
+ braceOpen: '<',
67
+ braceClose: '>',
68
+ });
69
+ };
70
+ export const TSArrayType = (path, {print}) => {
71
+ print('__elementType');
72
+ print('[]');
73
+ };
74
+ export const TSTypeOperator = (path, {write, print}) => {
75
+ const {operator} = path.node;
76
+ write(`${operator} `);
77
+ print('__typeAnnotation');
78
+ };
79
+ export const TSTypeAssertion = (path, {print}) => {
80
+ print('<');
81
+ print('__typeAnnotation');
82
+ print('>');
83
+ print('__expression');
84
+ };
85
+ export const TSUndefinedKeyword = (path, {write}) => {
86
+ write('undefined');
87
+ };
88
+ export const TSBooleanKeyword = (path, {write}) => {
89
+ write('boolean');
90
+ };
91
+ export const TSSatisfiesExpression = (path, {print}) => {
92
+ print('__expression');
93
+ print(' satisfies ');
94
+ print('__typeAnnotation');
95
+ };
96
+ export const TSNumberKeyword = (path, {write}) => {
97
+ write('number');
98
+ };
99
+ export const TSIndexedAccessType = (path, {print}) => {
100
+ print('__objectType');
101
+ print('[');
102
+ print('__indexType');
103
+ print(']');
104
+ };
105
+ export const TSStringKeyword = (path, {write}) => {
106
+ write('string');
107
+ };
108
+ export const TSInstantiationExpression = (path, {print}) => {
109
+ print('__expression');
110
+ print('__typeArguments');
111
+ };
112
+ export const TSAnyKeyword = (path, {write}) => {
113
+ write('any');
114
+ };
115
+ export const TSVoidKeyword = (path, {write}) => {
116
+ write('void');
117
+ };
118
+ export const TSQualifiedName = (path, {print}) => {
119
+ print('__left');
120
+ print('.');
121
+ print('__right');
122
+ };
123
+ export const TSTypeAnnotation = (path, {print}) => {
124
+ print('__typeAnnotation');
125
+ };
126
+
127
+ export const TSIndexSignature = (path, printer) => {
128
+ const {print} = printer;
129
+ print('[');
130
+ print('__parameters.0');
131
+ print(']');
132
+ maybePrintTypeAnnotation(path, printer);
133
+ print(';');
134
+ print.newline();
135
+ };
16
136
 
17
- const {TSInterfaceDeclaration} = require('./interface/ts-interface-declaration');
18
- const {TSAsExpression} = require('./ts-as-expression/ts-as-expression');
19
- const {TSInterfaceBody} = require('./interface/ts-interface-body');
20
- const {TSIntersectionType} = require('./ts-intersection-type');
21
- const {TSPropertySignature} = require('./ts-property-signature/ts-property-signature');
22
- const {TSFunctionType} = require('./function/ts-function-type');
23
- const {printParams} = require('../expressions/function/params');
24
- const {TSEnumDeclaration} = require('./enum/ts-enum-declaration');
25
- const {TSEnumMember} = require('./enum/ts-enum-member');
26
- const {TSTupleType} = require('./tuple/ts-tuple-type');
27
- const {TSNamedTupleMember} = require('./tuple/ts-named-tuple-member');
28
- const {TSConstructorType} = require('./function/ts-constructor-type');
29
- const {TSCallSignatureDeclaration} = require('./function/ts-call-signature-declaration');
30
- const {TSConstructSignatureDeclaration} = require('./function/ts-construct-signature-declaration');
31
- const {TSMethodSignature} = require('./function/ts-method-signature');
32
- const {TSUnionType} = require('./ts-union-type/ts-union-type');
137
+ export const TSClassImplements = (path, {print}) => {
138
+ print('__expression');
139
+ print('__typeArguments');
140
+ };
33
141
 
34
- const {maybePrintTypeAnnotation} = require('../maybe/maybe-type-annotation');
35
- const {TSImportType} = require('./ts-import-type/ts-import-type');
36
- const {TSExportAssignment} = require('./ts-export-assignment/ts-export-assignment');
37
- const {TSTypeReference} = require('./ts-type-reference/ts-type-reference');
38
- const {TSInferType} = require('./ts-infer-type/ts-infer-type');
39
- const {TSParameterProperty} = require('./ts-parameter-property/ts-parameter-property');
40
- const {TSTypeParameterDeclaration} = require('./ts-type-parameter-declaration/ts-type-parameter-declaration');
41
- const {TSTypeQuery} = require('./ts-type-query/ts-type-query');
42
- const {TSParenthesizedType} = require('./ts-parenthesized-type/ts-parenthesized-type');
43
- const {TSTemplateLiteralType} = require('./ts-template-literal-type/ts-template-literal-type');
44
- const {TSOptionalType} = require('./ts-optional-type/ts-optional-type');
142
+ export const TSInterfaceHeritage = (path, {print}) => {
143
+ print('__expression');
144
+ print('__typeArguments');
145
+ };
146
+
147
+ export const TSTypePredicate = (path, {print}) => {
148
+ print('__parameterName');
149
+ print(' is ');
150
+ print('__typeAnnotation');
151
+ };
152
+
153
+ export const TSNonNullExpression = (path, {print}) => {
154
+ print('__expression');
155
+ print('!');
156
+ };
157
+
158
+ export const TSImportEqualsDeclaration = (path, {print, maybe}) => {
159
+ maybe.print(path.node.isExport, 'export ');
160
+ print('import ');
161
+ print('__id');
162
+ print.space();
163
+ print('=');
164
+ print.space();
165
+ print('__moduleReference');
166
+ print(';');
167
+ maybe.print.newline(isNext(path));
168
+ };
169
+ export const TSExternalModuleReference = (path, {print}) => {
170
+ print('require(');
171
+ print('__expression');
172
+ print(')');
173
+ };
45
174
 
46
- module.exports = {
47
- TSAsExpression,
48
- TSExportAssignment,
49
- TSTypeLiteral,
50
- TSTypeAliasDeclaration,
51
- TSTypeParameter,
52
- TSMappedType,
53
- TSConditionalType,
54
- TSDeclareFunction,
55
- TSModuleDeclaration,
56
- TSModuleBlock,
57
- TSIntersectionType,
58
- TSImportType,
59
- TSUnionType,
60
- TSTypeQuery,
61
- TSTemplateLiteralType,
62
- TSOptionalType,
63
- TSTypeParameterDeclaration,
64
- TSBigIntKeyword(path, {write}) {
65
- write('bigint');
66
- },
67
- TSNullKeyword(path, {write}) {
68
- write('null');
69
- },
70
- TSSymbolKeyword(path, {write}) {
71
- write('symbol');
72
- },
73
- TSNeverKeyword(path, {write}) {
74
- write('never');
75
- },
76
- TSUnknownKeyword(path, {write}) {
77
- write('unknown');
78
- },
79
- TSObjectKeyword(path, {write}) {
80
- write('object');
81
- },
82
- TSLiteralType(path, {print}) {
83
- print('__literal');
84
- },
85
- TSTupleType,
86
- TSInferType,
87
- TSRestType(path, {print}) {
88
- print('...');
89
- print('__typeAnnotation');
90
- },
91
- TSTypeParameterInstantiation(path, printer, semantics) {
92
- printParams(path, printer, semantics, {
93
- braceOpen: '<',
94
- braceClose: '>',
95
- });
96
- },
97
- TSArrayType(path, {print}) {
98
- print('__elementType');
99
- print('[]');
100
- },
101
- TSTypeReference,
102
- TSTypeOperator(path, {write, print}) {
103
- const {operator} = path.node;
104
- write(`${operator} `);
105
- print('__typeAnnotation');
106
- },
107
- TSInterfaceDeclaration,
108
- TSInterfaceBody,
109
- TSTypeAssertion(path, {print}) {
110
- print('<');
111
- print('__typeAnnotation');
112
- print('>');
113
- print('__expression');
114
- },
115
- TSUndefinedKeyword(path, {write}) {
116
- write('undefined');
117
- },
118
- TSBooleanKeyword(path, {write}) {
119
- write('boolean');
120
- },
121
- TSSatisfiesExpression(path, {print}) {
122
- print('__expression');
123
- print(' satisfies ');
124
- print('__typeAnnotation');
125
- },
126
- TSNumberKeyword(path, {write}) {
127
- write('number');
128
- },
129
- TSIndexedAccessType(path, {print}) {
130
- print('__objectType');
131
- print('[');
132
- print('__indexType');
133
- print(']');
134
- },
135
- TSStringKeyword(path, {write}) {
136
- write('string');
137
- },
138
- TSInstantiationExpression(path, {print}) {
139
- print('__expression');
140
- print('__typeArguments');
141
- },
142
- TSAnyKeyword(path, {write}) {
143
- write('any');
144
- },
145
- TSVoidKeyword(path, {write}) {
146
- write('void');
147
- },
148
- TSQualifiedName(path, {print}) {
149
- print('__left');
150
- print('.');
151
- print('__right');
152
- },
153
- TSTypeAnnotation(path, {print}) {
154
- print('__typeAnnotation');
155
- },
156
- TSParameterProperty,
157
- TSConstructSignatureDeclaration,
158
- TSIndexSignature(path, printer) {
159
- const {print} = printer;
160
- print('[');
161
- print('__parameters.0');
162
- print(']');
163
- maybePrintTypeAnnotation(path, printer);
164
- print(';');
165
- print.newline();
166
- },
167
- TSClassImplements(path, {print}) {
168
- print('__expression');
169
- print('__typeArguments');
170
- },
171
- TSInterfaceHeritage(path, {print}) {
172
- print('__expression');
173
- print('__typeArguments');
174
- },
175
- TSParenthesizedType,
176
- TSPropertySignature,
177
- TSFunctionType,
178
- TSTypePredicate(path, {print}) {
179
- print('__parameterName');
180
- print(' is ');
181
- print('__typeAnnotation');
182
- },
183
- TSNonNullExpression(path, {print}) {
184
- print('__expression');
185
- print('!');
186
- },
187
- TSEnumDeclaration,
188
- TSEnumMember,
189
- TSImportEqualsDeclaration(path, {print, maybe}) {
190
- maybe.print(path.node.isExport, 'export ');
191
- print('import ');
192
- print('__id');
193
- print.space();
194
- print('=');
195
- print.space();
196
- print('__moduleReference');
197
- print(';');
198
- maybe.print.newline(isNext(path));
199
- },
200
- TSExternalModuleReference(path, {print}) {
201
- print('require(');
202
- print('__expression');
203
- print(')');
204
- },
205
- TSDeclareMethod,
206
- TSNamedTupleMember,
207
- TSConstructorType,
208
- TSMethodSignature,
209
- TSCallSignatureDeclaration,
210
- TSThisType(path, {print}) {
211
- print('this');
212
- },
175
+ export const TSThisType = (path, {print}) => {
176
+ print('this');
213
177
  };
@@ -1,8 +1,6 @@
1
- 'use strict';
1
+ import {parseComments} from '../../comment/comment.js';
2
2
 
3
- const {parseComments} = require('../../comment/comment');
4
-
5
- module.exports.TSInterfaceBody = (path, printer, semantics) => {
3
+ export const TSInterfaceBody = (path, printer, semantics) => {
6
4
  const body = path.get('body');
7
5
  const {
8
6
  traverse,
@@ -1,10 +1,7 @@
1
- 'use strict';
2
-
3
- const {types} = require('@putout/babel');
4
-
5
- const {isNext, isNextParent} = require('../../is');
6
- const {maybeDeclare} = require('../../maybe/maybe-declare');
7
- const {markAfter} = require('../../mark');
1
+ import {types} from '@putout/babel';
2
+ import {isNext, isNextParent} from '../../is.js';
3
+ import {maybeDeclare} from '../../maybe/maybe-declare.js';
4
+ import {markAfter} from '../../mark.js';
8
5
 
9
6
  const {
10
7
  isTSTypeAliasDeclaration,
@@ -14,7 +11,7 @@ const {
14
11
 
15
12
  const isInsideNamespace = (path) => isTSModuleBlock(path.parentPath.parentPath);
16
13
 
17
- module.exports.TSInterfaceDeclaration = {
14
+ export const TSInterfaceDeclaration = {
18
15
  print: maybeDeclare((path, {print, maybe}) => {
19
16
  const {node} = path;
20
17
  const {typeParameters} = node;
@@ -1,9 +1,8 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
2
 
3
- const {types} = require('@putout/babel');
4
3
  const {isTSConditionalType} = types;
5
4
 
6
- module.exports.TSMappedType = (path, {print, indent, maybe}) => {
5
+ export const TSMappedType = (path, {print, indent, maybe}) => {
7
6
  const {
8
7
  readonly,
9
8
  optional,
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import {isNext} from '#is';
2
+ import {maybeDeclare} from '../../maybe/maybe-declare.js';
2
3
 
3
- const {isNext} = require('../../is');
4
- const {maybeDeclare} = require('../../maybe/maybe-declare');
5
-
6
- module.exports.TSModuleDeclaration = {
4
+ export const TSModuleDeclaration = {
7
5
  print: maybeDeclare((path, {print}) => {
8
6
  const {kind} = path.node;
9
7
  const id = path.get('id');
@@ -24,7 +22,7 @@ module.exports.TSModuleDeclaration = {
24
22
  },
25
23
  };
26
24
 
27
- module.exports.TSModuleBlock = (path, {print, traverse, indent}) => {
25
+ export const TSModuleBlock = (path, {print, traverse, indent}) => {
28
26
  print('{');
29
27
  print.breakline();
30
28
  indent.inc();