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