@putout/printer 16.6.0 → 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog +11 -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 +10 -15
- 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,7 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {exists} from '../../is.js';
|
|
2
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
2
3
|
|
|
3
|
-
const {exists} = require('../../is');
|
|
4
|
-
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
5
4
|
const {isArray} = Array;
|
|
6
5
|
|
|
7
6
|
const parseArgs = (path) => {
|
|
@@ -13,7 +12,7 @@ const parseArgs = (path) => {
|
|
|
13
12
|
return argsPath;
|
|
14
13
|
};
|
|
15
14
|
|
|
16
|
-
const CallExpression = maybeParens((path, {indent, print, maybe, traverse}) => {
|
|
15
|
+
export const CallExpression = maybeParens((path, {indent, print, maybe, traverse}) => {
|
|
17
16
|
const args = parseArgs(path);
|
|
18
17
|
const isParentCall = tooLong(args) && path.parentPath.isCallExpression();
|
|
19
18
|
|
|
@@ -61,8 +60,7 @@ const CallExpression = maybeParens((path, {indent, print, maybe, traverse}) => {
|
|
|
61
60
|
print(')');
|
|
62
61
|
});
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
module.exports.CallExpression = CallExpression;
|
|
63
|
+
export const OptionalCallExpression = CallExpression;
|
|
66
64
|
|
|
67
65
|
function tooLong(args) {
|
|
68
66
|
for (const arg of args) {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {printKey} = require('../object-expression/print-key');
|
|
7
|
-
const {printKind} = require('../function/kind');
|
|
1
|
+
import {exists} from '../../is.js';
|
|
2
|
+
import {maybePrintTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
|
|
3
|
+
import {maybeDecorators} from '../../maybe/maybe-decorators.js';
|
|
4
|
+
import {printKey} from '../object-expression/print-key.js';
|
|
5
|
+
import {printKind} from '../function/kind.js';
|
|
8
6
|
|
|
9
7
|
const processClassProperty = maybeDecorators((path, printer, semantics, {accessor} = {}) => {
|
|
10
8
|
const {node} = path;
|
|
@@ -43,15 +41,15 @@ const processClassProperty = maybeDecorators((path, printer, semantics, {accesso
|
|
|
43
41
|
print.newline();
|
|
44
42
|
});
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
export const ClassProperty = processClassProperty;
|
|
45
|
+
export const ClassPrivateProperty = processClassProperty;
|
|
48
46
|
|
|
49
|
-
|
|
47
|
+
export const PrivateName = (path, {print}) => {
|
|
50
48
|
print('#');
|
|
51
49
|
print('__id');
|
|
52
50
|
};
|
|
53
51
|
|
|
54
|
-
|
|
52
|
+
export const ClassAccessorProperty = (path, printer, semantics) => {
|
|
55
53
|
processClassProperty(path, printer, semantics, {
|
|
56
54
|
accessor: true,
|
|
57
55
|
});
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const {maybeDeclare} = require('../../maybe/maybe-declare');
|
|
9
|
-
const {parseComments} = require('../../comment/comment');
|
|
10
|
-
const {maybeDecorators} = require('../../maybe/maybe-decorators');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {isNext} from '../../is.js';
|
|
3
|
+
import {markAfter} from '../../mark.js';
|
|
4
|
+
import {maybeDeclare} from '../../maybe/maybe-declare.js';
|
|
5
|
+
import {parseComments} from '../../comment/comment.js';
|
|
6
|
+
import {maybeDecorators} from '../../maybe/maybe-decorators.js';
|
|
11
7
|
|
|
12
8
|
const isInsideTSModuleBlock = (path) => {
|
|
13
9
|
return isTSModuleBlock(path.parentPath.parentPath);
|
|
@@ -89,9 +85,9 @@ const classVisitor = maybeDecorators((path, printer, semantics) => {
|
|
|
89
85
|
print('}');
|
|
90
86
|
});
|
|
91
87
|
|
|
92
|
-
|
|
88
|
+
export const ClassExpression = classVisitor;
|
|
93
89
|
|
|
94
|
-
|
|
90
|
+
export const ClassDeclaration = {
|
|
95
91
|
print: maybeDeclare((path, printer, semantics) => {
|
|
96
92
|
const {maybe} = printer;
|
|
97
93
|
maybe.indent(!isInsideExport(path));
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {maybeParens} from '../maybe/maybe-parens.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
module.exports.ConditionalExpression = maybeParens((path, {print}) => {
|
|
3
|
+
export const ConditionalExpression = maybeParens((path, {print}) => {
|
|
6
4
|
print('__test');
|
|
7
5
|
print.space();
|
|
8
6
|
print('?');
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {exists} from '../../is.js';
|
|
2
|
+
import {printParams} from './params.js';
|
|
3
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const {printParams} = require('./params');
|
|
5
|
-
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
6
|
-
|
|
7
|
-
module.exports.ArrowFunctionExpression = maybeParens((path, printer, semantics) => {
|
|
5
|
+
export const ArrowFunctionExpression = maybeParens((path, printer, semantics) => {
|
|
8
6
|
const {
|
|
9
7
|
print,
|
|
10
8
|
maybe,
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
isNext,
|
|
5
3
|
hasTrailingComment,
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const {printFunctionParams} = require('./print-function-params');
|
|
4
|
+
} from '../../is.js';
|
|
5
|
+
import {maybeDecorators} from '../../maybe/maybe-decorators.js';
|
|
6
|
+
import {printKey} from '../object-expression/print-key.js';
|
|
7
|
+
import {printKind} from './kind.js';
|
|
8
|
+
import {printFunctionParams} from './print-function-params.js';
|
|
12
9
|
|
|
13
10
|
const noTrailingCommentAndNext = (path) => {
|
|
14
11
|
if (hasTrailingComment(path))
|
|
@@ -17,7 +14,7 @@ const noTrailingCommentAndNext = (path) => {
|
|
|
17
14
|
return isNext(path);
|
|
18
15
|
};
|
|
19
16
|
|
|
20
|
-
const ClassMethod = {
|
|
17
|
+
export const ClassMethod = {
|
|
21
18
|
print: maybeDecorators((path, printer, semantics) => {
|
|
22
19
|
const {print} = printer;
|
|
23
20
|
const {node} = path;
|
|
@@ -62,5 +59,4 @@ const ClassMethod = {
|
|
|
62
59
|
},
|
|
63
60
|
};
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
module.exports.ClassMethod = ClassMethod;
|
|
62
|
+
export const ClassPrivateMethod = ClassMethod;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {isNext, isNextParent} = require('../../is');
|
|
6
|
-
const {printParams} = require('./params');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {markAfter} from '../../mark.js';
|
|
3
|
+
import {isNext, isNextParent} from '../../is.js';
|
|
4
|
+
import {printParams} from './params.js';
|
|
7
5
|
|
|
8
6
|
const not = (fn) => (...a) => !fn(...a);
|
|
9
7
|
const notInsideExportDefaultWithBody = not(isInsideExportDefaultWithBody);
|
|
@@ -20,7 +18,7 @@ const {
|
|
|
20
18
|
|
|
21
19
|
const isInsideNamedExport = ({parentPath}) => isExportNamedDeclaration(parentPath);
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export const FunctionDeclaration = {
|
|
24
22
|
print(path, printer, semantics) {
|
|
25
23
|
const {print, maybe} = printer;
|
|
26
24
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {exists} from '../../is.js';
|
|
2
|
+
import {printParams} from './params.js';
|
|
3
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const {printParams} = require('./params');
|
|
5
|
-
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
6
|
-
|
|
7
|
-
module.exports.FunctionExpression = maybeParens((path, printer, semantics) => {
|
|
5
|
+
export const FunctionExpression = maybeParens((path, printer, semantics) => {
|
|
8
6
|
const {
|
|
9
7
|
print,
|
|
10
8
|
maybe,
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
ClassMethod,
|
|
8
|
-
ClassPrivateMethod,
|
|
9
|
-
} = require('./class-method');
|
|
10
|
-
|
|
11
|
-
const {ObjectMethod} = require('./object-method');
|
|
12
|
-
const {FunctionExpression} = require('./function-expression');
|
|
13
|
-
|
|
14
|
-
module.exports.FunctionDeclaration = FunctionDeclaration;
|
|
15
|
-
module.exports.FunctionExpression = FunctionExpression;
|
|
16
|
-
module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
17
|
-
module.exports.ClassMethod = ClassMethod;
|
|
18
|
-
module.exports.ClassPrivateMethod = ClassPrivateMethod;
|
|
19
|
-
module.exports.ObjectMethod = ObjectMethod;
|
|
1
|
+
export {ArrowFunctionExpression} from './arrow-function-expression.js';
|
|
2
|
+
export {FunctionDeclaration} from './function-declaration.js';
|
|
3
|
+
export {ClassPrivateMethod, ClassMethod} from './class-method.js';
|
|
4
|
+
export {ObjectMethod} from './object-method.js';
|
|
5
|
+
export {FunctionExpression} from './function-expression.js';
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import {isNewlineBetweenSiblings} from '../../is.js';
|
|
2
|
+
import {printParams} from './params.js';
|
|
3
|
+
import {printKey} from '../object-expression/print-key.js';
|
|
4
|
+
import {printKind} from './kind.js';
|
|
2
5
|
|
|
3
|
-
const
|
|
4
|
-
const {printParams} = require('./params');
|
|
5
|
-
const {printKey} = require('../object-expression/print-key');
|
|
6
|
-
const {printKind} = require('./kind');
|
|
7
|
-
|
|
8
|
-
module.exports.ObjectMethod = {
|
|
6
|
+
export const ObjectMethod = {
|
|
9
7
|
beforeIf(path) {
|
|
10
8
|
return path.node.async;
|
|
11
9
|
},
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {parseComments} = require('../../comment/comment');
|
|
1
|
+
import {parseComments} from '../../comment/comment.js';
|
|
4
2
|
|
|
5
3
|
const noop = () => {};
|
|
6
4
|
const parseParams = (path) => path.get('params');
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
export const printParams = (path, printer, semantics, customization = {}) => {
|
|
9
7
|
const {extra, typeParameters} = path.node;
|
|
10
8
|
const {
|
|
11
9
|
print,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {printParams} = require('./params');
|
|
4
|
-
const {hasLeadingComment} = require('../../is');
|
|
1
|
+
import {printParams} from './params.js';
|
|
2
|
+
import {hasLeadingComment} from '../../is.js';
|
|
5
3
|
|
|
6
4
|
const isAllParamsHasLeadingComments = (path) => {
|
|
7
5
|
const params = path.get('params');
|
|
@@ -26,7 +24,7 @@ const isAllParamsHasLeadingComments = (path) => {
|
|
|
26
24
|
|
|
27
25
|
const hasDecorators = ({decorators}) => decorators?.length;
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
export const printFunctionParams = (path, printer, semantics) => {
|
|
30
28
|
const {params} = path.node;
|
|
31
29
|
const isNewline = params.filter(hasDecorators).length;
|
|
32
30
|
const isAllHasComments = isAllParamsHasLeadingComments(path);
|
|
@@ -81,7 +79,7 @@ const createPrintBeforeClose = ({isNewline, printer, isAllHasComments, type}) =>
|
|
|
81
79
|
print.breakline();
|
|
82
80
|
};
|
|
83
81
|
|
|
84
|
-
const createPrintSpace = ({isNewline, printer}) => () => {
|
|
82
|
+
export const createPrintSpace = ({isNewline, printer}) => () => {
|
|
85
83
|
const {print} = printer;
|
|
86
84
|
|
|
87
85
|
if (!isNewline)
|
|
@@ -89,5 +87,3 @@ const createPrintSpace = ({isNewline, printer}) => () => {
|
|
|
89
87
|
|
|
90
88
|
print.breakline();
|
|
91
89
|
};
|
|
92
|
-
|
|
93
|
-
module.exports.createPrintSpace = createPrintSpace;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export const ImportExpression = createImportExpression;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
module.exports.createImportExpression = createImportExpression;
|
|
5
|
-
|
|
6
|
-
function createImportExpression(path, printer) {
|
|
3
|
+
export function createImportExpression(path, printer) {
|
|
7
4
|
const {print, maybe} = printer;
|
|
8
5
|
const {options} = path.node;
|
|
9
6
|
|
|
@@ -1,78 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const memberExpressions = require('./member-expression/member-expressions');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
export * from './function/functions.js';
|
|
2
|
+
export * from './unary-expression/unary-expressions.js';
|
|
3
|
+
export * from './member-expression/member-expressions.js';
|
|
4
|
+
export {
|
|
8
5
|
ClassExpression,
|
|
9
6
|
ClassDeclaration,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const {
|
|
7
|
+
} from './class/class.js';
|
|
8
|
+
export {
|
|
13
9
|
CallExpression,
|
|
14
10
|
OptionalCallExpression,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
} from './call-expression/call-expression.js';
|
|
12
|
+
export {NewExpression} from './new-expression/new-expression.js';
|
|
13
|
+
export {ObjectExpression} from './object-expression/object-expression.js';
|
|
14
|
+
export {ObjectProperty} from './object-expression/object-property.js';
|
|
15
|
+
export {ObjectPattern} from './object-pattern/object-pattern.js';
|
|
16
|
+
export {AssignmentExpression} from './assignment-expression/assignment-expression.js';
|
|
17
|
+
export {ArrayExpression} from './array-expression/array-expression.js';
|
|
18
|
+
export {ArrayPattern} from './array-pattern/array-pattern.js';
|
|
19
|
+
export {AssignmentPattern} from './assignment-pattern.js';
|
|
20
|
+
export {RestElement} from './rest-element.js';
|
|
21
|
+
export {SpreadElement} from './spread-element.js';
|
|
22
|
+
export {SequenceExpression} from './sequence-expression/sequence-expression.js';
|
|
23
|
+
export {TaggedTemplateExpression} from './tagged-template-expression.js';
|
|
24
|
+
export {BinaryExpression} from './binary-expression/binary-expression.js';
|
|
25
|
+
export {LogicalExpression} from './logical-expression/logical-expression.js';
|
|
26
|
+
export {ConditionalExpression} from './conditional-expression.js';
|
|
27
|
+
export {StaticBlock} from './class/static-block.js';
|
|
28
|
+
export {ImportExpression} from './import-expression.js';
|
|
29
|
+
export {ParenthesizedExpression} from './parenthesized-expression/parenthesized-expression.js';
|
|
30
|
+
export {
|
|
24
31
|
ClassProperty,
|
|
25
32
|
ClassAccessorProperty,
|
|
26
33
|
ClassPrivateProperty,
|
|
27
34
|
PrivateName,
|
|
28
|
-
}
|
|
35
|
+
} from './class/class-property.js';
|
|
29
36
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const {ArrayPattern} = require('./array-pattern/array-pattern');
|
|
33
|
-
const {AssignmentPattern} = require('./assignment-pattern');
|
|
34
|
-
const {RestElement} = require('./rest-element');
|
|
35
|
-
const {SpreadElement} = require('./spread-element');
|
|
36
|
-
const {SequenceExpression} = require('./sequence-expression/sequence-expression');
|
|
37
|
-
const {TaggedTemplateExpression} = require('./tagged-template-expression');
|
|
38
|
-
const {BinaryExpression} = require('./binary-expression/binary-expression');
|
|
39
|
-
const {LogicalExpression} = require('./logical-expression/logical-expression');
|
|
40
|
-
const {ConditionalExpression} = require('./conditional-expression');
|
|
41
|
-
const {StaticBlock} = require('./class/static-block');
|
|
42
|
-
const {ImportExpression} = require('./import-expression');
|
|
43
|
-
const {ParenthesizedExpression} = require('./parenthesized-expression/parenthesized-expression');
|
|
44
|
-
|
|
45
|
-
module.exports = {
|
|
46
|
-
...functions,
|
|
47
|
-
...unaryExpressions,
|
|
48
|
-
...memberExpressions,
|
|
49
|
-
ArrayPattern,
|
|
50
|
-
ArrayExpression,
|
|
51
|
-
AssignmentExpression,
|
|
52
|
-
AssignmentPattern,
|
|
53
|
-
BinaryExpression,
|
|
54
|
-
CallExpression,
|
|
55
|
-
ClassExpression,
|
|
56
|
-
ClassProperty,
|
|
57
|
-
ClassAccessorProperty,
|
|
58
|
-
ClassPrivateProperty,
|
|
59
|
-
ClassDeclaration,
|
|
60
|
-
ConditionalExpression,
|
|
61
|
-
NewExpression,
|
|
62
|
-
LogicalExpression,
|
|
63
|
-
OptionalCallExpression,
|
|
64
|
-
ObjectExpression,
|
|
65
|
-
ObjectProperty,
|
|
66
|
-
ObjectPattern,
|
|
67
|
-
ParenthesizedExpression,
|
|
68
|
-
PrivateName,
|
|
69
|
-
RestElement,
|
|
70
|
-
ImportExpression,
|
|
71
|
-
SpreadElement,
|
|
72
|
-
SequenceExpression,
|
|
73
|
-
StaticBlock,
|
|
74
|
-
TaggedTemplateExpression,
|
|
75
|
-
ThisExpression(path, {write}) {
|
|
76
|
-
write('this');
|
|
77
|
-
},
|
|
37
|
+
export const ThisExpression = (path, {write}) => {
|
|
38
|
+
write('this');
|
|
78
39
|
};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {
|
|
5
4
|
isLogicalExpression,
|
|
6
5
|
isReturnStatement,
|
|
7
6
|
isVariableDeclarator,
|
|
8
7
|
} = types;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
export const isRootOk = (path) => {
|
|
11
10
|
return isReturnStatement(path) || isVariableDeclarator(path);
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
export const chain = (path) => {
|
|
15
14
|
const [downCount] = down(path);
|
|
16
15
|
const [upCount, root] = up(path);
|
|
17
16
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
2
|
+
import {chain, isRootOk} from './chain.js';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
const {chain, isRootOk} = require('./chain');
|
|
5
|
-
|
|
6
|
-
module.exports.LogicalExpression = maybeParens({
|
|
4
|
+
export const LogicalExpression = maybeParens({
|
|
7
5
|
condition(path) {
|
|
8
6
|
if (path.parentPath.isUnaryExpression())
|
|
9
7
|
return true;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {hasTrailingComment} from '../../is.js';
|
|
2
2
|
|
|
3
|
-
const {hasTrailingComment} = require('../../is');
|
|
4
3
|
const {assign} = Object;
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export const chain = (path) => {
|
|
7
6
|
const all = [
|
|
8
7
|
...down(path),
|
|
9
8
|
...up(path),
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const {chain} = require('./chain');
|
|
5
|
-
const {satisfy} = require('../../is');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {chain} from './chain.js';
|
|
3
|
+
import {satisfy} from '../../is.js';
|
|
6
4
|
|
|
7
5
|
const {
|
|
8
6
|
isUnaryExpression,
|
|
@@ -39,7 +37,7 @@ function isLastArgInCall(path) {
|
|
|
39
37
|
return path === parentPath.get('arguments').at(-1);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
export const isLooksLikeChain = (path) => {
|
|
43
41
|
const [root, properties] = chain(path);
|
|
44
42
|
|
|
45
43
|
if (isInsideMemberCall(path))
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
6
|
-
const {isLooksLikeChain} = require('./is-looks-like-chain');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {maybePrintComputed} from '../object-expression/maybe-print-computed.js';
|
|
3
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
4
|
+
import {isLooksLikeChain} from './is-looks-like-chain.js';
|
|
7
5
|
|
|
8
6
|
const {
|
|
9
7
|
isObjectExpression,
|
|
10
8
|
isArrowFunctionExpression,
|
|
11
9
|
} = types;
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
export const MemberExpression = maybeParens({
|
|
14
12
|
checkParens: false,
|
|
15
13
|
condition: (path) => isObjectInsideArrow(path),
|
|
16
14
|
print: (path, printer) => {
|
|
@@ -41,7 +39,7 @@ module.exports.MemberExpression = maybeParens({
|
|
|
41
39
|
},
|
|
42
40
|
});
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
export const OptionalMemberExpression = maybeParens((path, {print, maybe}) => {
|
|
45
43
|
const {computed, optional} = path.node;
|
|
46
44
|
|
|
47
45
|
print('__object');
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const {exists} = require('../../is');
|
|
5
|
-
const {isMarkedAfter} = require('../../mark');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {exists} from '../../is.js';
|
|
3
|
+
import {isMarkedAfter} from '../../mark.js';
|
|
6
4
|
|
|
7
5
|
const {
|
|
8
6
|
isExpressionStatement,
|
|
@@ -22,7 +20,7 @@ const getPrev = ({parentPath}) => {
|
|
|
22
20
|
];
|
|
23
21
|
};
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
export const NewExpression = {
|
|
26
24
|
beforeIf(path) {
|
|
27
25
|
if (!isInsideExpressionStatement(path))
|
|
28
26
|
return false;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {isArrayExpression} = types;
|
|
5
4
|
|
|
6
5
|
const TYPES = [
|
|
@@ -9,7 +8,7 @@ const TYPES = [
|
|
|
9
8
|
'BigIntLiteral',
|
|
10
9
|
];
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
export const isInsideTuple = (path) => {
|
|
13
12
|
const {parentPath} = path;
|
|
14
13
|
|
|
15
14
|
if (!isArrayExpression(parentPath))
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {
|
|
5
4
|
isArrayExpression,
|
|
6
5
|
isCallExpression,
|
|
7
6
|
isIdentifier,
|
|
8
7
|
} = types;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
export const isThirdObjectInsideArray = ({parentPath}) => {
|
|
11
10
|
if (!isArrayExpression(parentPath))
|
|
12
11
|
return false;
|
|
13
12
|
|