@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.
- package/ChangeLog +16 -0
- package/README.md +5 -5
- package/lib/json.js +3 -5
- package/lib/print-tokens/cook.js +1 -3
- package/lib/print-tokens/index.js +2 -4
- package/lib/printer.js +6 -11
- package/lib/tokenize/comment/comment.js +3 -9
- package/lib/tokenize/comment/comments-printer/comments-printer.js +4 -6
- package/lib/tokenize/comment/maybe-inside-fn.js +1 -3
- package/lib/tokenize/comment/parse-comments.js +2 -4
- package/lib/tokenize/comment/parse-leading-comments.js +8 -12
- package/lib/tokenize/comment/parse-trailing-comments.js +8 -15
- package/lib/tokenize/debug.js +6 -8
- package/lib/tokenize/expressions/array-expression/array-expression.js +10 -15
- package/lib/tokenize/expressions/array-expression/indent.js +5 -11
- package/lib/tokenize/expressions/array-expression/is-object-after-simple.js +3 -5
- package/lib/tokenize/expressions/array-expression/newline.js +7 -11
- package/lib/tokenize/expressions/array-pattern/array-pattern.js +2 -3
- package/lib/tokenize/expressions/assignment-expression/assignment-expression-comments.js +6 -7
- package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +8 -12
- package/lib/tokenize/expressions/assignment-expression/maybe-parens-condition.js +3 -6
- package/lib/tokenize/expressions/assignment-expression/print-separator.js +2 -3
- package/lib/tokenize/expressions/assignment-pattern.js +1 -3
- package/lib/tokenize/expressions/binary-expression/binary-expression.js +5 -8
- package/lib/tokenize/expressions/binary-expression/concatenate.js +3 -4
- package/lib/tokenize/expressions/binary-expression/maybe-space.js +1 -3
- package/lib/tokenize/expressions/call-expression/call-expression.js +4 -6
- package/lib/tokenize/expressions/class/class-property.js +9 -11
- package/lib/tokenize/expressions/class/class.js +8 -12
- package/lib/tokenize/expressions/class/static-block.js +1 -3
- package/lib/tokenize/expressions/conditional-expression.js +2 -4
- package/lib/tokenize/expressions/function/arrow-function-expression.js +4 -6
- package/lib/tokenize/expressions/function/class-method.js +8 -12
- package/lib/tokenize/expressions/function/function-declaration.js +5 -7
- package/lib/tokenize/expressions/function/function-expression.js +4 -6
- package/lib/tokenize/expressions/function/functions.js +5 -19
- package/lib/tokenize/expressions/function/kind.js +1 -3
- package/lib/tokenize/expressions/function/object-method.js +5 -7
- package/lib/tokenize/expressions/function/params.js +2 -4
- package/lib/tokenize/expressions/function/print-function-params.js +4 -8
- package/lib/tokenize/expressions/import-expression.js +2 -5
- package/lib/tokenize/expressions/index.js +29 -68
- package/lib/tokenize/expressions/logical-expression/chain.js +3 -4
- package/lib/tokenize/expressions/logical-expression/logical-expression.js +3 -5
- package/lib/tokenize/expressions/member-expression/chain.js +2 -3
- package/lib/tokenize/expressions/member-expression/is-looks-like-chain.js +4 -6
- package/lib/tokenize/expressions/member-expression/member-expressions.js +6 -8
- package/lib/tokenize/expressions/new-expression/new-expression.js +4 -6
- package/lib/tokenize/expressions/object-expression/is-inside-tuple.js +2 -3
- package/lib/tokenize/expressions/object-expression/is-third-object-inside-array.js +2 -3
- package/lib/tokenize/expressions/object-expression/maybe-print-computed.js +1 -3
- package/lib/tokenize/expressions/object-expression/object-expression.js +9 -13
- package/lib/tokenize/expressions/object-expression/object-property.js +4 -6
- package/lib/tokenize/expressions/object-expression/print-key.js +2 -4
- package/lib/tokenize/expressions/object-pattern/calculate-long-assign-pattern.js +3 -6
- package/lib/tokenize/expressions/object-pattern/comments.js +1 -3
- package/lib/tokenize/expressions/object-pattern/more-then-max-properties-in-one-line.js +1 -3
- package/lib/tokenize/expressions/object-pattern/more-then-max-properties-length-in-one-line.js +2 -3
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +12 -20
- package/lib/tokenize/expressions/object-pattern/wrong-shorthand.js +1 -3
- package/lib/tokenize/expressions/parenthesized-expression/parenthesized-expression.js +2 -3
- package/lib/tokenize/expressions/rest-element.js +2 -4
- package/lib/tokenize/expressions/sequence-expression/maybe-write-brace.js +1 -3
- package/lib/tokenize/expressions/sequence-expression/sequence-expression-comments.js +4 -5
- package/lib/tokenize/expressions/sequence-expression/sequence-expression.js +8 -11
- package/lib/tokenize/expressions/spread-element.js +2 -4
- package/lib/tokenize/expressions/tagged-template-expression.js +1 -3
- package/lib/tokenize/expressions/unary-expression/unary-expressions.js +7 -9
- package/lib/tokenize/is.js +35 -43
- package/lib/tokenize/jsx/index.js +38 -45
- package/lib/tokenize/jsx/jsx-attribute.js +2 -4
- package/lib/tokenize/jsx/jsx-element.js +2 -3
- package/lib/tokenize/jsx/jsx-fragment.js +3 -5
- package/lib/tokenize/jsx/jsx-opening-element.js +2 -4
- package/lib/tokenize/jsx/jsx-text/jsx-text.js +2 -4
- package/lib/tokenize/{expressions → literals}/decorator/decorator.js +3 -4
- package/lib/tokenize/literals/directive-literal.js +1 -3
- package/lib/tokenize/literals/identifier.js +4 -6
- package/lib/tokenize/literals/index.js +45 -49
- package/lib/tokenize/literals/string-literal.js +1 -3
- package/lib/tokenize/literals/template-literal.js +2 -4
- package/lib/tokenize/literals/void-pattern/void-pattern.js +1 -3
- package/lib/tokenize/literals/write-template-literal.js +1 -3
- package/lib/tokenize/mark.js +5 -11
- package/lib/tokenize/maybe/index.js +6 -9
- package/lib/tokenize/maybe/maybe-declare.js +1 -3
- package/lib/tokenize/maybe/maybe-decorators.js +1 -3
- package/lib/tokenize/maybe/maybe-parens.js +3 -5
- package/lib/tokenize/maybe/maybe-type-annotation.js +3 -6
- package/lib/tokenize/maybe/satisfy.js +2 -4
- package/lib/tokenize/maybe-get.js +1 -3
- package/lib/tokenize/overrides/overrides.js +3 -5
- package/lib/tokenize/overrides/parse-quotes.js +1 -3
- package/lib/tokenize/overrides/parse-round-braces.js +4 -10
- package/lib/tokenize/statements/block-statement/block-statement.js +9 -12
- package/lib/tokenize/statements/block-statement/get-directives.js +1 -3
- package/lib/tokenize/statements/block-statement/inside-if-with-no-body.js +2 -4
- package/lib/tokenize/statements/block-statement/is-call-inside-chain.js +3 -4
- package/lib/tokenize/statements/break-statement/break-statement.js +3 -5
- package/lib/tokenize/statements/continue-statement/continue-statement.js +2 -4
- package/lib/tokenize/statements/debugger-statement.js +2 -3
- package/lib/tokenize/statements/do-while-statement/do-while-statement.js +2 -3
- package/lib/tokenize/statements/empty-statement/empty-statement.js +2 -4
- package/lib/tokenize/statements/export-declaration/export-all-declaration.js +1 -3
- package/lib/tokenize/statements/export-declaration/export-declaration.js +33 -17
- package/lib/tokenize/statements/export-declaration/export-default-declaration.js +3 -5
- package/lib/tokenize/statements/expression-statement/expression-statement-comments.js +4 -6
- package/lib/tokenize/statements/expression-statement/expression-statement.js +9 -25
- package/lib/tokenize/statements/expression-statement/is-inside-assign-next-assign-function.js +2 -3
- package/lib/tokenize/statements/for-in-statement.js +1 -3
- package/lib/tokenize/statements/for-of-statement/for-of-statement.js +5 -8
- package/lib/tokenize/statements/for-statement.js +4 -7
- package/lib/tokenize/statements/if-statement/if-statement.js +5 -8
- package/lib/tokenize/statements/import-declaration/import-attribute.js +2 -4
- package/lib/tokenize/statements/import-declaration/import-declaration-comments.js +3 -4
- package/lib/tokenize/statements/import-declaration/import-declaration.js +10 -17
- package/lib/tokenize/statements/index.js +28 -61
- package/lib/tokenize/statements/labeled-statement/labeled-statement.js +2 -4
- package/lib/tokenize/statements/program/program.js +4 -6
- package/lib/tokenize/statements/return-statement/maybe-space-after-keyword.js +1 -3
- package/lib/tokenize/statements/return-statement/return-statement.js +8 -11
- package/lib/tokenize/statements/switch-statement/switch-statement.js +5 -9
- package/lib/tokenize/statements/try-statement/try-statements.js +3 -5
- package/lib/tokenize/statements/variable-declaration/maybe-space-after-keyword.js +1 -3
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +9 -13
- package/lib/tokenize/statements/while-statement/while-statement.js +3 -5
- package/lib/tokenize/statements/with-statement/with-statement.js +3 -5
- package/lib/tokenize/tokenize.js +12 -18
- package/lib/tokenize/typescript/enum/ts-enum-declaration.js +4 -7
- package/lib/tokenize/typescript/enum/ts-enum-member.js +1 -3
- package/lib/tokenize/typescript/function/print-return-type.js +2 -4
- package/lib/tokenize/typescript/function/ts-call-signature-declaration.js +3 -5
- package/lib/tokenize/typescript/function/ts-construct-signature-declaration.js +4 -7
- package/lib/tokenize/typescript/function/ts-constructor-type.js +3 -5
- package/lib/tokenize/typescript/function/ts-declare-function.js +4 -6
- package/lib/tokenize/typescript/function/ts-declare-method.js +2 -4
- package/lib/tokenize/typescript/function/ts-function-type.js +4 -7
- package/lib/tokenize/typescript/function/ts-method-signature.js +6 -9
- package/lib/tokenize/typescript/index.js +172 -207
- package/lib/tokenize/typescript/interface/ts-interface-body.js +2 -4
- package/lib/tokenize/typescript/interface/ts-interface-declaration.js +5 -8
- package/lib/tokenize/typescript/mapped-type/ts-mapped-type.js +2 -3
- package/lib/tokenize/typescript/namespace/ts-module-declaration.js +4 -6
- package/lib/tokenize/typescript/ts-as-expression/ts-as-expression.js +3 -5
- package/lib/tokenize/typescript/ts-conditional-type.js +1 -3
- package/lib/tokenize/typescript/ts-export-assignment/ts-export-assignment.js +2 -4
- package/lib/tokenize/typescript/ts-import-type/ts-import-type.js +2 -4
- package/lib/tokenize/typescript/ts-infer-type/ts-infer-type.js +2 -4
- package/lib/tokenize/typescript/ts-intersection-type.js +1 -3
- package/lib/tokenize/typescript/ts-optional-type/ts-optional-type.js +1 -3
- package/lib/tokenize/typescript/ts-parameter-property/ts-parameter-property.js +3 -5
- package/lib/tokenize/typescript/ts-parenthesized-type/ts-parenthesized-type.js +1 -3
- package/lib/tokenize/typescript/ts-property-signature/comments.js +4 -7
- package/lib/tokenize/typescript/ts-property-signature/ts-property-signature.js +10 -15
- package/lib/tokenize/typescript/ts-template-literal-type/ts-template-literal-type.js +2 -4
- package/lib/tokenize/typescript/ts-type-parameter-declaration/ts-type-parameter-declaration.js +4 -5
- package/lib/tokenize/typescript/ts-type-query/ts-type-query.js +2 -4
- package/lib/tokenize/typescript/ts-type-reference/ts-type-reference.js +1 -3
- package/lib/tokenize/typescript/ts-union-type/ts-union-type.js +2 -3
- package/lib/tokenize/typescript/tuple/ts-named-tuple-member.js +1 -3
- package/lib/tokenize/typescript/tuple/ts-tuple-type.js +1 -3
- package/lib/tokenize/typescript/type/ts-type-alias-declaration.js +5 -8
- package/lib/tokenize/typescript/type/ts-type-literal.js +1 -3
- package/lib/tokenize/typescript/type/ts-type-parameter.js +2 -4
- package/lib/tokenize/visitors.js +5 -14
- package/lib/types.js +1 -3
- package/package.json +9 -9
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import {isNext} from '#is';
|
|
2
|
+
import {markAfter} from '../../mark.js';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
const {markAfter} = require('../../mark');
|
|
5
|
-
|
|
6
|
-
module.exports.WhileStatement = {
|
|
4
|
+
export const WhileStatement = {
|
|
7
5
|
print(path, {print, indent}) {
|
|
8
6
|
indent();
|
|
9
7
|
print('while');
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import {isNext} from '#is';
|
|
2
|
+
import {markAfter} from '../../mark.js';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
const {markAfter} = require('../../mark');
|
|
5
|
-
|
|
6
|
-
module.exports.WithStatement = {
|
|
4
|
+
export const WithStatement = {
|
|
7
5
|
print(path, {print, indent}) {
|
|
8
6
|
indent();
|
|
9
7
|
print('with');
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
35
|
+
export const tokenize = (ast, overrides) => {
|
|
42
36
|
const {
|
|
43
37
|
visitors,
|
|
44
38
|
format,
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
isNext,
|
|
5
3
|
isNextParent,
|
|
6
4
|
isLast,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const {markAfter} = require('../../mark');
|
|
5
|
+
} from '../../is.js';
|
|
6
|
+
import {markAfter} from '../../mark.js';
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
export const TSEnumDeclaration = {
|
|
12
9
|
beforeIf(path) {
|
|
13
10
|
return path.node.const;
|
|
14
11
|
},
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export const hasReturnType = (path) => path.node.returnType;
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
1
|
+
import {printReturnType} from './print-return-type.js';
|
|
2
|
+
import {printParams} from '../../expressions/function/params.js';
|
|
2
3
|
|
|
3
|
-
const
|
|
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
|
-
|
|
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
|
-
}
|
|
5
|
+
} from './print-return-type.js';
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
export const TSConstructSignatureDeclaration = (path, printer, semantics) => {
|
|
11
8
|
const {write} = printer;
|
|
12
9
|
|
|
13
10
|
write('new');
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import {printParams} from '../../expressions/function/params.js';
|
|
2
|
+
import {printReturnType} from './print-return-type.js';
|
|
2
3
|
|
|
3
|
-
const
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
13
|
+
export const TSDeclareFunction = {
|
|
16
14
|
beforeIf: (path) => !isInsideNamedExport(path),
|
|
17
15
|
before: (path, {indent}) => {
|
|
18
16
|
indent();
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {printParams} from '../../expressions/function/params.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
9
|
+
export const TSMethodSignature = (path, printer, semantics) => {
|
|
13
10
|
const {write} = printer;
|
|
14
11
|
|
|
15
12
|
printKind(path, printer);
|
|
@@ -1,213 +1,178 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
};
|
|
16
126
|
|
|
17
|
-
const
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const {TSMethodSignature} = require('./function/ts-method-signature');
|
|
32
|
-
const {TSUnionType} = require('./ts-union-type/ts-union-type');
|
|
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
|
+
};
|
|
136
|
+
|
|
137
|
+
export const TSClassImplements = (path, {print}) => {
|
|
138
|
+
print('__expression');
|
|
139
|
+
print('__typeArguments');
|
|
140
|
+
};
|
|
33
141
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
};
|
|
45
146
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
},
|
|
147
|
+
export const TSTypePredicate = (path, {print}) => {
|
|
148
|
+
print('__parameterName');
|
|
149
|
+
print(' is ');
|
|
150
|
+
print('__typeAnnotation');
|
|
213
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
|
+
};
|
|
174
|
+
|
|
175
|
+
export const TSThisType = (path, {print}) => {
|
|
176
|
+
print('this');
|
|
177
|
+
};
|
|
178
|
+
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {parseComments} from '../../comment/comment.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
14
|
+
export const TSInterfaceDeclaration = {
|
|
18
15
|
print: maybeDeclare((path, {print, maybe}) => {
|
|
19
16
|
const {node} = path;
|
|
20
17
|
const {typeParameters} = node;
|