@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,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
}
|
|
11
|
-
|
|
12
|
-
const {
|
|
7
|
+
} from '../../mark.js';
|
|
8
|
+
import {
|
|
13
9
|
isNewlineBetweenSiblings,
|
|
14
10
|
exists,
|
|
15
11
|
isNext,
|
|
16
12
|
isLast,
|
|
17
|
-
}
|
|
13
|
+
} from '../../is.js';
|
|
18
14
|
|
|
19
15
|
const {
|
|
20
16
|
isExportNamespaceSpecifier,
|
|
21
17
|
isVariableDeclaration,
|
|
22
18
|
isExportNamedDeclaration,
|
|
19
|
+
isExportDefaultSpecifier,
|
|
23
20
|
} = types;
|
|
24
21
|
|
|
25
22
|
const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
|
|
@@ -31,7 +28,7 @@ const options = {
|
|
|
31
28
|
},
|
|
32
29
|
};
|
|
33
30
|
|
|
34
|
-
|
|
31
|
+
export const ExportSpecifier = (path, {print}) => {
|
|
35
32
|
const {local, exported} = path.node;
|
|
36
33
|
|
|
37
34
|
print('__local');
|
|
@@ -42,12 +39,16 @@ module.exports.ExportSpecifier = (path, {print}) => {
|
|
|
42
39
|
}
|
|
43
40
|
};
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
export const ExportNamespaceSpecifier = (path, {print}) => {
|
|
46
43
|
print('* as ');
|
|
47
44
|
print('__exported');
|
|
48
45
|
};
|
|
49
46
|
|
|
50
|
-
|
|
47
|
+
export const ExportDefaultSpecifier = (path, {print}) => {
|
|
48
|
+
print('__exported');
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const ExportNamedDeclaration = {
|
|
51
52
|
beforeIf(path) {
|
|
52
53
|
const prev = path.getPrevSibling();
|
|
53
54
|
|
|
@@ -88,15 +89,30 @@ module.exports.ExportNamedDeclaration = {
|
|
|
88
89
|
|
|
89
90
|
if (specifiers && !path.node.declaration) {
|
|
90
91
|
print.space();
|
|
91
|
-
print('{');
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
const [first, ...rest] = specifiers;
|
|
94
|
+
|
|
95
|
+
if (!specifiers.length) {
|
|
96
|
+
print('{}');
|
|
97
|
+
} else if (isExportDefaultSpecifier(first) && !rest.length) {
|
|
98
|
+
traverse(first);
|
|
99
|
+
} else {
|
|
100
|
+
if (isExportDefaultSpecifier(first)) {
|
|
101
|
+
traverse(first);
|
|
102
|
+
print(',');
|
|
103
|
+
print.space();
|
|
104
|
+
} else {
|
|
105
|
+
rest.unshift(first);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
print('{');
|
|
109
|
+
|
|
94
110
|
indent.inc();
|
|
95
111
|
maybe.print.newline(isNewline);
|
|
96
112
|
|
|
97
113
|
const lastIndex = n - 1;
|
|
98
114
|
|
|
99
|
-
for (const [i, spec] of
|
|
115
|
+
for (const [i, spec] of rest.entries()) {
|
|
100
116
|
const isType = spec.node.exportKind === 'type';
|
|
101
117
|
const isLast = i < lastIndex;
|
|
102
118
|
|
|
@@ -114,9 +130,9 @@ module.exports.ExportNamedDeclaration = {
|
|
|
114
130
|
|
|
115
131
|
indent.dec();
|
|
116
132
|
indent();
|
|
133
|
+
print('}');
|
|
117
134
|
}
|
|
118
135
|
|
|
119
|
-
print('}');
|
|
120
136
|
const source = path.get('source');
|
|
121
137
|
|
|
122
138
|
if (exists(source)) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
const {isNext} = require('../../is');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {isNext} from '../../is.js';
|
|
5
3
|
|
|
6
4
|
const {
|
|
7
5
|
isVariableDeclaration,
|
|
@@ -15,7 +13,7 @@ function shouldAddSemicolon(path) {
|
|
|
15
13
|
return !path.isFunctionDeclaration();
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
export const ExportDefaultDeclaration = {
|
|
19
17
|
print(path, {print, traverse, maybe}) {
|
|
20
18
|
const declaration = path.get('declaration');
|
|
21
19
|
print('export default ');
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
const {hasTrailingComment} = require('#is');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {hasTrailingComment} from '#is';
|
|
5
3
|
|
|
6
4
|
const {
|
|
7
5
|
isBlockStatement,
|
|
@@ -9,7 +7,7 @@ const {
|
|
|
9
7
|
isIfStatement,
|
|
10
8
|
} = types;
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
export const printLeadingCommentLine = (path, printer, semantics, {index, isLast, printComment}) => {
|
|
13
11
|
const {print, indent} = printer;
|
|
14
12
|
const prev = path.getPrevSibling();
|
|
15
13
|
const {parentPath} = path;
|
|
@@ -27,7 +25,7 @@ module.exports.printLeadingCommentLine = (path, printer, semantics, {index, isLa
|
|
|
27
25
|
print.indent();
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
export const printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
31
29
|
const {indent} = printer;
|
|
32
30
|
const prev = path.getPrevSibling();
|
|
33
31
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {
|
|
5
3
|
isNext,
|
|
6
4
|
isLast,
|
|
7
5
|
isParentBlock,
|
|
@@ -12,14 +10,12 @@ const {
|
|
|
12
10
|
hasTrailingComment,
|
|
13
11
|
isCoupleLines,
|
|
14
12
|
isInsideLabel,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const {
|
|
13
|
+
} from '../../is.js';
|
|
14
|
+
import {isInsideAssignNextAssignFunction} from './is-inside-assign-next-assign-function.js';
|
|
15
|
+
import {
|
|
20
16
|
printLeadingCommentLine,
|
|
21
17
|
printLeadingCommentBlock,
|
|
22
|
-
}
|
|
18
|
+
} from './expression-statement-comments.js';
|
|
23
19
|
|
|
24
20
|
const isCommentBlock = (a) => a?.type === 'CommentBlock';
|
|
25
21
|
|
|
@@ -58,11 +54,10 @@ const isNextIf = (path) => path
|
|
|
58
54
|
const shouldBreakline = satisfy([
|
|
59
55
|
isNewlineBetweenSiblings,
|
|
60
56
|
isNotLastBody,
|
|
61
|
-
isStrictMode,
|
|
62
57
|
isNextIf,
|
|
63
58
|
]);
|
|
64
59
|
|
|
65
|
-
|
|
60
|
+
export const ExpressionStatement = {
|
|
66
61
|
beforeIf(path) {
|
|
67
62
|
if (isInsideReturn(path))
|
|
68
63
|
return false;
|
|
@@ -123,8 +118,8 @@ module.exports.ExpressionStatement = {
|
|
|
123
118
|
}
|
|
124
119
|
},
|
|
125
120
|
};
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
ExpressionStatement.printLeadingCommentLine = printLeadingCommentLine;
|
|
122
|
+
ExpressionStatement.printLeadingCommentBlock = printLeadingCommentBlock;
|
|
128
123
|
|
|
129
124
|
function isTopParentLast({parentPath}) {
|
|
130
125
|
if (!parentPath.isIfStatement())
|
|
@@ -155,17 +150,6 @@ function isNextUp(path) {
|
|
|
155
150
|
return path.findParent(isNext);
|
|
156
151
|
}
|
|
157
152
|
|
|
158
|
-
function isStrictMode(path) {
|
|
159
|
-
const expressionPath = path.get('expression');
|
|
160
|
-
|
|
161
|
-
if (!expressionPath.isStringLiteral())
|
|
162
|
-
return false;
|
|
163
|
-
|
|
164
|
-
const {value} = path.node.expression;
|
|
165
|
-
|
|
166
|
-
return value === 'use strict';
|
|
167
|
-
}
|
|
168
|
-
|
|
169
153
|
function isNextToAssignmentCall(path) {
|
|
170
154
|
if (isAssignmentExpression(path.node.expression))
|
|
171
155
|
return false;
|
package/lib/tokenize/statements/expression-statement/is-inside-assign-next-assign-function.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {
|
|
5
4
|
isExpressionStatement,
|
|
6
5
|
isFunction,
|
|
7
6
|
isAssignmentExpression,
|
|
8
7
|
} = types;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
export const isInsideAssignNextAssignFunction = (path) => {
|
|
11
10
|
const {expression} = path.node;
|
|
12
11
|
|
|
13
12
|
if (!isAssignmentExpression(expression))
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
hasPrevNewline,
|
|
5
3
|
markAfter,
|
|
6
4
|
markBefore,
|
|
7
5
|
isMarkedAfter,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const {
|
|
6
|
+
} from '../../mark.js';
|
|
7
|
+
import {
|
|
11
8
|
isFirst,
|
|
12
9
|
isNext,
|
|
13
10
|
isLast,
|
|
14
|
-
}
|
|
11
|
+
} from '../../is.js';
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
export const ForOfStatement = {
|
|
17
14
|
beforeIf(path) {
|
|
18
15
|
const {parentPath} = path;
|
|
19
16
|
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {isInsideLabel} from '#is';
|
|
2
|
+
import {exists} from '../is.js';
|
|
3
|
+
import {markAfter} from '../mark.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const {exists} = require('../is');
|
|
5
|
-
|
|
6
|
-
const {markAfter} = require('../mark');
|
|
7
|
-
|
|
8
|
-
module.exports.ForStatement = {
|
|
5
|
+
export const ForStatement = {
|
|
9
6
|
print(path, {print, maybe}) {
|
|
10
7
|
const {
|
|
11
8
|
test,
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {markAfter} = require('../../mark');
|
|
6
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {markAfter} from '../../mark.js';
|
|
3
|
+
import {
|
|
7
4
|
exists,
|
|
8
5
|
isNext,
|
|
9
6
|
isInsideIf,
|
|
10
|
-
}
|
|
7
|
+
} from '../../is.js';
|
|
11
8
|
|
|
12
9
|
const {
|
|
13
10
|
isBlockStatement,
|
|
@@ -58,7 +55,7 @@ const isLastEmptyInsideBody = (path) => {
|
|
|
58
55
|
return isFunctionDeclaration(path.parentPath.parentPath);
|
|
59
56
|
};
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
export const IfStatement = {
|
|
62
59
|
print: (path, {indent, print, maybe, write, traverse}) => {
|
|
63
60
|
const {parentPath} = path;
|
|
64
61
|
const partOfAlternate = parentPath.get('alternate');
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports.ImportAttribute = (path, {print}) => {
|
|
1
|
+
export const ImportAttribute = (path, {print}) => {
|
|
4
2
|
print('__key');
|
|
5
3
|
print(':');
|
|
6
4
|
print.space();
|
|
@@ -8,7 +6,7 @@ module.exports.ImportAttribute = (path, {print}) => {
|
|
|
8
6
|
print(',');
|
|
9
7
|
};
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
export const printAttributes = (path, keyword, {write, traverse, indent}) => {
|
|
12
10
|
const attributes = path.get('attributes');
|
|
13
11
|
|
|
14
12
|
if (!attributes.length)
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {isExportDeclaration} = types;
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export const printTrailingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
7
6
|
const {print} = printer;
|
|
8
7
|
printComment();
|
|
9
8
|
print.breakline();
|
|
10
9
|
};
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
export const printTrailingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
13
12
|
const {maybe} = printer;
|
|
14
13
|
const next = path.getNextSibling();
|
|
15
14
|
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import {parseImportSpecifiers} from 'parse-import-specifiers';
|
|
2
|
+
import {markAfter} from '../../mark.js';
|
|
3
|
+
import {isLast, isNext} from '../../is.js';
|
|
4
|
+
import {printAttributes} from './import-attribute.js';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {markAfter} = require('../../mark');
|
|
6
|
-
const {isLast, isNext} = require('../../is');
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
ImportAttribute,
|
|
10
|
-
printAttributes,
|
|
11
|
-
} = require('./import-attribute');
|
|
12
|
-
|
|
13
|
-
const {
|
|
6
|
+
export {ImportAttribute} from './import-attribute.js';
|
|
7
|
+
import {
|
|
14
8
|
printTrailingCommentBlock,
|
|
15
9
|
printTrailingCommentLine,
|
|
16
|
-
}
|
|
10
|
+
} from './import-declaration-comments.js';
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
module.exports.ImportDeclaration = {
|
|
12
|
+
export const ImportDeclaration = {
|
|
20
13
|
print(path, printer, semantics) {
|
|
21
14
|
const {
|
|
22
15
|
print,
|
|
@@ -138,5 +131,5 @@ function parseMaxSpecifiers(imports, semantics) {
|
|
|
138
131
|
return maxSpecifiersInOneLine;
|
|
139
132
|
}
|
|
140
133
|
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
ImportDeclaration.printTrailingCommentBlock = printTrailingCommentBlock;
|
|
135
|
+
ImportDeclaration.printTrailingCommentLine = printTrailingCommentLine;
|
|
@@ -1,64 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
export {WithStatement} from './with-statement/with-statement.js';
|
|
2
|
+
export {EmptyStatement} from './empty-statement/empty-statement.js';
|
|
3
|
+
export {LabeledStatement} from './labeled-statement/labeled-statement.js';
|
|
4
|
+
export {ContinueStatement} from './continue-statement/continue-statement.js';
|
|
5
|
+
export {Program} from './program/program.js';
|
|
6
|
+
export {DoWhileStatement} from './do-while-statement/do-while-statement.js';
|
|
7
|
+
export {BreakStatement} from './break-statement/break-statement.js';
|
|
8
|
+
export {ExportDefaultDeclaration} from './export-declaration/export-default-declaration.js';
|
|
9
|
+
export {ForInStatement} from './for-in-statement.js';
|
|
10
|
+
export {SwitchStatement} from './switch-statement/switch-statement.js';
|
|
11
|
+
export {WhileStatement} from './while-statement/while-statement.js';
|
|
12
|
+
export {ExportAllDeclaration} from './export-declaration/export-all-declaration.js';
|
|
13
|
+
export * from './export-declaration/export-declaration.js';
|
|
14
|
+
export * from './import-declaration/import-declaration.js';
|
|
15
|
+
export {ForStatement} from './for-statement.js';
|
|
16
|
+
export {DebuggerStatement} from './debugger-statement.js';
|
|
17
|
+
export * from './try-statement/try-statements.js';
|
|
18
|
+
export {ReturnStatement} from './return-statement/return-statement.js';
|
|
19
|
+
export {BlockStatement} from './block-statement/block-statement.js';
|
|
20
|
+
export {ForOfStatement} from './for-of-statement/for-of-statement.js';
|
|
21
|
+
export {IfStatement} from './if-statement/if-statement.js';
|
|
22
|
+
export {VariableDeclaration} from './variable-declaration/variable-declaration.js';
|
|
23
|
+
export {ExpressionStatement} from './expression-statement/expression-statement.js';
|
|
2
24
|
|
|
3
|
-
const
|
|
4
|
-
const {VariableDeclaration} = require('./variable-declaration/variable-declaration');
|
|
5
|
-
const {IfStatement} = require('./if-statement/if-statement');
|
|
6
|
-
const {ForOfStatement} = require('./for-of-statement/for-of-statement');
|
|
7
|
-
const {BlockStatement} = require('./block-statement/block-statement');
|
|
8
|
-
const {ReturnStatement} = require('./return-statement/return-statement');
|
|
9
|
-
const TryStatements = require('./try-statement/try-statements');
|
|
10
|
-
const {DebuggerStatement} = require('./debugger-statement');
|
|
11
|
-
const {ForStatement} = require('./for-statement');
|
|
12
|
-
const importDeclarations = require('./import-declaration/import-declaration');
|
|
13
|
-
const exportDeclarations = require('./export-declaration/export-declaration');
|
|
14
|
-
const {ExportAllDeclaration} = require('./export-declaration/export-all-declaration');
|
|
25
|
+
const SHEBANG_HASHBANG = '#!';
|
|
15
26
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const {ExportDefaultDeclaration} = require('./export-declaration/export-default-declaration');
|
|
20
|
-
const {BreakStatement} = require('./break-statement/break-statement');
|
|
21
|
-
const {DoWhileStatement} = require('./do-while-statement/do-while-statement');
|
|
22
|
-
const {Program} = require('./program/program');
|
|
23
|
-
const {ContinueStatement} = require('./continue-statement/continue-statement');
|
|
24
|
-
const {LabeledStatement} = require('./labeled-statement/labeled-statement');
|
|
25
|
-
const {EmptyStatement} = require('./empty-statement/empty-statement');
|
|
26
|
-
const {WithStatement} = require('./with-statement/with-statement');
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
ExportNamespaceSpecifier,
|
|
30
|
-
ExportSpecifier,
|
|
31
|
-
} = exportDeclarations;
|
|
32
|
-
|
|
33
|
-
module.exports = {
|
|
34
|
-
...importDeclarations,
|
|
35
|
-
...exportDeclarations,
|
|
36
|
-
BlockStatement,
|
|
37
|
-
DoWhileStatement,
|
|
38
|
-
ExpressionStatement,
|
|
39
|
-
ExportSpecifier,
|
|
40
|
-
ExportNamespaceSpecifier,
|
|
41
|
-
ExportDefaultDeclaration,
|
|
42
|
-
ExportAllDeclaration,
|
|
43
|
-
VariableDeclaration,
|
|
44
|
-
IfStatement,
|
|
45
|
-
ForStatement,
|
|
46
|
-
ForInStatement,
|
|
47
|
-
ForOfStatement,
|
|
48
|
-
ReturnStatement,
|
|
49
|
-
DebuggerStatement,
|
|
50
|
-
LabeledStatement,
|
|
51
|
-
Program,
|
|
52
|
-
EmptyStatement,
|
|
53
|
-
InterpreterDirective(path, {print}) {
|
|
54
|
-
// shebang, hashbang
|
|
55
|
-
print(`#!${path.node.value}\n`);
|
|
56
|
-
print.newline();
|
|
57
|
-
},
|
|
58
|
-
SwitchStatement,
|
|
59
|
-
...TryStatements,
|
|
60
|
-
BreakStatement,
|
|
61
|
-
ContinueStatement,
|
|
62
|
-
WhileStatement,
|
|
63
|
-
WithStatement,
|
|
27
|
+
export const InterpreterDirective = (path, {print}) => {
|
|
28
|
+
print(`${SHEBANG_HASHBANG}${path.node.value}\n`);
|
|
29
|
+
print.newline();
|
|
64
30
|
};
|
|
31
|
+
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {isInsideLabel} from '../../is.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
module.exports.LabeledStatement = (path, {print, maybe}) => {
|
|
3
|
+
export const LabeledStatement = (path, {print, maybe}) => {
|
|
6
4
|
maybe.indent(!isInsideLabel(path));
|
|
7
5
|
print('__label');
|
|
8
6
|
print(':');
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {parseComments} from '../../comment/comment.js';
|
|
2
|
+
import {getDirectives} from '../block-statement/get-directives.js';
|
|
3
|
+
import {hasCoupleTrailingComments} from '../../is.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const {getDirectives} = require('../block-statement/get-directives');
|
|
5
|
-
const {hasCoupleTrailingComments} = require('../../is');
|
|
6
|
-
|
|
7
|
-
module.exports.Program = (path, printer, semantics) => {
|
|
5
|
+
export const Program = (path, printer, semantics) => {
|
|
8
6
|
const {body} = path.node;
|
|
9
7
|
const {
|
|
10
8
|
traverse,
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {isInsideLabel} = require('#is');
|
|
6
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {isInsideLabel} from '#is';
|
|
3
|
+
import {
|
|
7
4
|
isPrevBody,
|
|
8
5
|
noTrailingComment,
|
|
9
6
|
isLast,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
|
|
7
|
+
} from '../../is.js';
|
|
8
|
+
import {hasPrevNewline} from '../../mark.js';
|
|
9
|
+
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
14
10
|
|
|
15
11
|
const {isJSXElement} = types;
|
|
16
12
|
const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
|
|
17
13
|
|
|
18
14
|
const isInsideIfWithElse = ({parentPath}) => parentPath.isIfStatement() && parentPath.node.alternate;
|
|
19
15
|
|
|
20
|
-
|
|
16
|
+
export const ReturnStatement = {
|
|
21
17
|
beforeIf(path) {
|
|
22
18
|
return !hasPrevNewline(path) && isBodyLength(path) || isPrevBody(path);
|
|
23
19
|
},
|
|
@@ -62,6 +58,7 @@ module.exports.ReturnStatement = {
|
|
|
62
58
|
print.newline();
|
|
63
59
|
},
|
|
64
60
|
};
|
|
61
|
+
|
|
65
62
|
function isJSXWithComment(path) {
|
|
66
63
|
const arg = path.node.argument;
|
|
67
64
|
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
isNext,
|
|
5
3
|
exists,
|
|
6
4
|
isLast,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const {maybeSpaceAfterKeyword} = require('../return-statement/maybe-space-after-keyword.js');
|
|
5
|
+
} from '#is';
|
|
6
|
+
import {parseLeadingComments} from '../../comment/comment.js';
|
|
7
|
+
import {maybeSpaceAfterKeyword} from '../return-statement/maybe-space-after-keyword.js';
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
export const SwitchStatement = {
|
|
14
10
|
print(path, printer, semantics) {
|
|
15
11
|
const {
|
|
16
12
|
print,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {isNext} from '../../is.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
module.exports.TryStatement = {
|
|
3
|
+
export const TryStatement = {
|
|
6
4
|
print(path, {print}) {
|
|
7
5
|
const finalizer = path.get('finalizer');
|
|
8
6
|
print.indent();
|
|
@@ -26,7 +24,7 @@ module.exports.TryStatement = {
|
|
|
26
24
|
},
|
|
27
25
|
};
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
export const CatchClause = (path, {print, maybe}) => {
|
|
30
28
|
const param = path.get('param');
|
|
31
29
|
const body = path.get('body');
|
|
32
30
|
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {hasPrevNewline} from '../../mark.js';
|
|
3
|
+
import {
|
|
5
4
|
isNext,
|
|
6
5
|
isCoupleLines,
|
|
7
6
|
isNewlineBetweenSiblings,
|
|
8
7
|
exists,
|
|
9
8
|
noTrailingComment,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const {isConcatenation} = require('../../expressions/binary-expression/concatenate');
|
|
16
|
-
const {parseLeadingComments} = require('../../comment/comment');
|
|
17
|
-
const {maybeDeclare} = require('../../maybe/maybe-declare');
|
|
9
|
+
} from '../../is.js';
|
|
10
|
+
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
11
|
+
import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
|
|
12
|
+
import {parseLeadingComments} from '../../comment/comment.js';
|
|
13
|
+
import {maybeDeclare} from '../../maybe/maybe-declare.js';
|
|
18
14
|
|
|
19
15
|
const {isExportDeclaration} = types;
|
|
20
16
|
|
|
@@ -25,7 +21,7 @@ const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
|
|
|
25
21
|
const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
|
|
26
22
|
const isParentIf = (path) => path.parentPath.isIfStatement();
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
export const VariableDeclaration = {
|
|
29
25
|
beforeIf: shouldAddNewlineBefore,
|
|
30
26
|
before(path, {print}) {
|
|
31
27
|
print.breakline();
|