@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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {parseComments} from '../../comment/comment.js';
|
|
3
|
+
import {
|
|
5
4
|
isCoupleLines,
|
|
6
5
|
isForOf,
|
|
7
6
|
isIf,
|
|
@@ -10,12 +9,10 @@ const {
|
|
|
10
9
|
noLeadingComment,
|
|
11
10
|
hasLeadingComment,
|
|
12
11
|
exists,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const {isLooksLikeChain} = require('../member-expression/is-looks-like-chain');
|
|
18
|
-
const {isThirdObjectInsideArray} = require('./is-third-object-inside-array');
|
|
12
|
+
} from '../../is.js';
|
|
13
|
+
import {isInsideTuple} from './is-inside-tuple.js';
|
|
14
|
+
import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
|
|
15
|
+
import {isThirdObjectInsideArray} from './is-third-object-inside-array.js';
|
|
19
16
|
|
|
20
17
|
const {
|
|
21
18
|
isStringLiteral,
|
|
@@ -58,7 +55,7 @@ function isInsideNestedTuple({parentPath}) {
|
|
|
58
55
|
return isStringLiteral(first);
|
|
59
56
|
}
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
export const ObjectExpression = (path, printer, semantics) => {
|
|
62
59
|
const {trailingComma} = semantics;
|
|
63
60
|
const {
|
|
64
61
|
print,
|
|
@@ -153,8 +150,7 @@ const notLastArgInsideCall = (path) => {
|
|
|
153
150
|
const ONE_LINE = true;
|
|
154
151
|
const MANY_LINES = false;
|
|
155
152
|
|
|
156
|
-
|
|
157
|
-
function isOneLine(path) {
|
|
153
|
+
export function isOneLine(path) {
|
|
158
154
|
const {length} = path.get('properties');
|
|
159
155
|
|
|
160
156
|
if (!length)
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {isConcatenation} from '../binary-expression/concatenate.js';
|
|
2
|
+
import {isOneLine} from './object-expression.js';
|
|
3
|
+
import {printKey} from './print-key.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const {isOneLine} = require('./object-expression');
|
|
5
|
-
const {printKey} = require('./print-key');
|
|
6
|
-
|
|
7
|
-
module.exports.ObjectProperty = (path, printer, semantics) => {
|
|
5
|
+
export const ObjectProperty = (path, printer, semantics) => {
|
|
8
6
|
const {trailingComma} = semantics;
|
|
9
7
|
const {shorthand} = path.node;
|
|
10
8
|
const {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {maybePrintComputed} from './maybe-print-computed.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
module.exports.printKey = (path, printer) => {
|
|
3
|
+
export const printKey = (path, printer) => {
|
|
6
4
|
const key = path.get('key');
|
|
7
5
|
|
|
8
6
|
maybePrintComputed(path, key, printer);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {
|
|
5
4
|
isAssignmentPattern,
|
|
6
5
|
isArrayExpression,
|
|
@@ -8,7 +7,7 @@ const {
|
|
|
8
7
|
isIdentifier,
|
|
9
8
|
} = types;
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
export const calculateAssigns = (property, semantics) => {
|
|
12
11
|
const currentAssign = isLongAssignPattern(property, semantics);
|
|
13
12
|
|
|
14
13
|
const {right} = property.node.value;
|
|
@@ -20,9 +19,7 @@ module.exports.calculateAssigns = (property, semantics) => {
|
|
|
20
19
|
};
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function isLongAssignPattern(path, semantics) {
|
|
22
|
+
export function isLongAssignPattern(path, semantics) {
|
|
26
23
|
const {key, value} = path.node;
|
|
27
24
|
|
|
28
25
|
if (!isAssignmentPattern(value))
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const createPrintCommentLine = (fn) => (value) => fn(`//${value}`);
|
|
4
2
|
const createPrintCommentBlock = (fn) => (value) => fn(`/*${value}*/`);
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
export const printLeadingComments = (path, {print}) => {
|
|
7
5
|
const printCommentLine = createPrintCommentLine(print);
|
|
8
6
|
const printCommentBlock = createPrintCommentBlock(print);
|
|
9
7
|
const {leadingComments} = path.node;
|
package/lib/tokenize/expressions/object-pattern/more-then-max-properties-length-in-one-line.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {
|
|
5
4
|
isAssignmentPattern,
|
|
6
5
|
isIdentifier,
|
|
@@ -16,7 +15,7 @@ function getLength(left, right) {
|
|
|
16
15
|
return 0;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
export const moreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengthInOneLine}) => {
|
|
20
19
|
const {properties} = path.node;
|
|
21
20
|
|
|
22
21
|
for (const {key, value} of properties) {
|
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {wrongShorthand} = require('./wrong-shorthand');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {wrongShorthand} from './wrong-shorthand.js';
|
|
3
|
+
import {
|
|
8
4
|
isForOf,
|
|
9
5
|
isCoupleLines,
|
|
10
6
|
exists,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const {printKey} = require('../object-expression/print-key');
|
|
18
|
-
|
|
19
|
-
const {
|
|
7
|
+
} from '../../is.js';
|
|
8
|
+
import {moreThenMaxPropertiesInOneLine} from './more-then-max-properties-in-one-line.js';
|
|
9
|
+
import {maybeTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
|
|
10
|
+
import {moreThenMaxPropertiesLengthInOneLine} from './more-then-max-properties-length-in-one-line.js';
|
|
11
|
+
import {printKey} from '../object-expression/print-key.js';
|
|
12
|
+
import {
|
|
20
13
|
calculateAssigns,
|
|
21
14
|
isLongAssignPattern,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const {printLeadingComments} = require('./comments');
|
|
15
|
+
} from './calculate-long-assign-pattern.js';
|
|
16
|
+
import {printLeadingComments} from './comments.js';
|
|
25
17
|
|
|
26
18
|
const {
|
|
27
19
|
isObjectExpression,
|
|
@@ -95,7 +87,7 @@ function isNextAssignObject(path) {
|
|
|
95
87
|
return isObjectExpression(right);
|
|
96
88
|
}
|
|
97
89
|
|
|
98
|
-
|
|
90
|
+
export const ObjectPattern = {
|
|
99
91
|
print: maybeTypeAnnotation((path, printer, semantics) => {
|
|
100
92
|
const shouldIndent = isIndent(path);
|
|
101
93
|
const {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {isJSXElement} = types;
|
|
5
4
|
|
|
6
5
|
const condition = (path) => {
|
|
@@ -8,7 +7,7 @@ const condition = (path) => {
|
|
|
8
7
|
return !isJSXElement(expression);
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
export const ParenthesizedExpression = {
|
|
12
11
|
before(path, {print}) {
|
|
13
12
|
print('(');
|
|
14
13
|
},
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {maybeTypeAnnotation} from '../maybe/maybe-type-annotation.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
module.exports.RestElement = maybeTypeAnnotation((path, {print}) => {
|
|
3
|
+
export const RestElement = maybeTypeAnnotation((path, {print}) => {
|
|
6
4
|
print('...');
|
|
7
5
|
print('__argument');
|
|
8
6
|
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import {hasLeadingComment} from '#is';
|
|
2
2
|
|
|
3
|
-
const {hasLeadingComment} = require('#is');
|
|
4
3
|
const noop = () => {};
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const printLeadingCommentLine = noop;
|
|
6
|
+
export const printLeadingCommentBlock = noop;
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export const maybePrintComments = (path, {print}) => {
|
|
10
9
|
if (hasLeadingComment(path)) {
|
|
11
10
|
const {leadingComments} = path.node;
|
|
12
11
|
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {condition} = require('./maybe-write-brace');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
import {hasLeadingComment} from '#is';
|
|
2
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
3
|
+
import {condition} from './maybe-write-brace.js';
|
|
4
|
+
import {
|
|
8
5
|
maybePrintComments,
|
|
9
6
|
printLeadingCommentLine,
|
|
10
7
|
printLeadingCommentBlock,
|
|
11
|
-
}
|
|
8
|
+
} from './sequence-expression-comments.js';
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
export const SequenceExpression = maybeParens({
|
|
14
11
|
checkParens: false,
|
|
15
12
|
condition,
|
|
16
13
|
print(path, printer) {
|
|
@@ -49,5 +46,5 @@ module.exports.SequenceExpression = maybeParens({
|
|
|
49
46
|
},
|
|
50
47
|
});
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
SequenceExpression.printLeadingCommentLine = printLeadingCommentLine;
|
|
50
|
+
SequenceExpression.printLeadingCommentBlock = printLeadingCommentBlock;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {hasTrailingComment} from '../is.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
module.exports.SpreadElement = (path, printer) => {
|
|
3
|
+
export const SpreadElement = (path, printer) => {
|
|
6
4
|
const {print} = printer;
|
|
7
5
|
print('...');
|
|
8
6
|
print('__argument');
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {isLast, isNext} = require('../../is');
|
|
4
|
-
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
1
|
+
import {isLast, isNext} from '../../is.js';
|
|
2
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
5
3
|
|
|
6
4
|
const isWord = (a) => /^(delete|typeof|void|throw)$/.test(a);
|
|
7
5
|
|
|
@@ -16,16 +14,16 @@ const unaryExpression = maybeParens((path, printer) => {
|
|
|
16
14
|
maybe.print(!prefix, operator);
|
|
17
15
|
});
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
export const UnaryExpression = unaryExpression;
|
|
18
|
+
export const UpdateExpression = unaryExpression;
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
export const AwaitExpression = maybeParens((path, {print}) => {
|
|
23
21
|
printUnary('await', {
|
|
24
22
|
print,
|
|
25
23
|
});
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
export const YieldExpression = maybeParens((path, {print, maybe}) => {
|
|
29
27
|
const {delegate} = path.node;
|
|
30
28
|
|
|
31
29
|
print(`yield`);
|
|
@@ -34,7 +32,7 @@ module.exports.YieldExpression = maybeParens((path, {print, maybe}) => {
|
|
|
34
32
|
print('__argument');
|
|
35
33
|
});
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
export const ThrowStatement = (path, {print, indent, maybe}) => {
|
|
38
36
|
indent();
|
|
39
37
|
|
|
40
38
|
printUnary('throw', {
|
package/lib/tokenize/is.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {
|
|
5
4
|
isStringLiteral,
|
|
6
5
|
isIdentifier,
|
|
@@ -14,10 +13,10 @@ const {
|
|
|
14
13
|
isLabeledStatement,
|
|
15
14
|
} = types;
|
|
16
15
|
|
|
17
|
-
const isParentProgram = (path) => path.parentPath?.isProgram();
|
|
18
|
-
const isParentBlock = (path) => path.parentPath.isBlockStatement();
|
|
16
|
+
export const isParentProgram = (path) => path.parentPath?.isProgram();
|
|
17
|
+
export const isParentBlock = (path) => path.parentPath.isBlockStatement();
|
|
19
18
|
|
|
20
|
-
const isNext = (path) => {
|
|
19
|
+
export const isNext = (path) => {
|
|
21
20
|
const next = path.getNextSibling();
|
|
22
21
|
|
|
23
22
|
if (!next.node)
|
|
@@ -26,35 +25,30 @@ const isNext = (path) => {
|
|
|
26
25
|
return !next.isEmptyStatement();
|
|
27
26
|
};
|
|
28
27
|
|
|
29
|
-
const isPrev = (path) => {
|
|
28
|
+
export const isPrev = (path) => {
|
|
30
29
|
const next = path.getPrevSibling();
|
|
31
30
|
return next.node;
|
|
32
31
|
};
|
|
33
32
|
|
|
34
|
-
const isNextParent = (path) => isNext(path.parentPath);
|
|
35
|
-
const isLast = (path) => isParentProgram(path) && !isNext(path);
|
|
33
|
+
export const isNextParent = (path) => isNext(path.parentPath);
|
|
34
|
+
export const isLast = (path) => isParentProgram(path) && !isNext(path);
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
export const isNextObject = (a) => a
|
|
38
37
|
.getNextSibling()
|
|
39
38
|
.isObjectExpression();
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
export const isPrevObject = (a) => a
|
|
42
41
|
.getPrevSibling()
|
|
43
42
|
.isObjectExpression();
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
export const isFirst = (path) => path.node === path.parentPath.node.body?.[0];
|
|
45
|
+
export const isPrevBody = (path) => path
|
|
47
46
|
.getPrevSibling()
|
|
48
47
|
.isBlockStatement();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
module.exports.isParentBlock = isParentBlock;
|
|
54
|
-
module.exports.isLast = isLast;
|
|
55
|
-
module.exports.isParentLast = (path) => isLast(path.parentPath);
|
|
56
|
-
|
|
57
|
-
module.exports.isIndented = (path = {}) => {
|
|
48
|
+
|
|
49
|
+
export const isParentLast = (path) => isLast(path.parentPath);
|
|
50
|
+
|
|
51
|
+
export const isIndented = (path = {}) => {
|
|
58
52
|
const {parentPath, node} = path;
|
|
59
53
|
|
|
60
54
|
if (!parentPath.node.loc)
|
|
@@ -63,18 +57,16 @@ module.exports.isIndented = (path = {}) => {
|
|
|
63
57
|
return node.loc?.start.column !== parentPath.node.loc.start.column;
|
|
64
58
|
};
|
|
65
59
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
function isCoupleLines(path) {
|
|
60
|
+
export function isCoupleLines(path) {
|
|
69
61
|
const start = path.node?.loc?.start?.line;
|
|
70
62
|
const end = path.node?.loc?.end?.line;
|
|
71
63
|
|
|
72
64
|
return end !== start;
|
|
73
65
|
}
|
|
74
66
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
function isStringAndIdentifier([a, b]) {
|
|
67
|
+
export const exists = (a) => a.node;
|
|
68
|
+
|
|
69
|
+
export function isStringAndIdentifier([a, b]) {
|
|
78
70
|
return isStringLiteral(a) && isIdentifier(b);
|
|
79
71
|
}
|
|
80
72
|
|
|
@@ -90,7 +82,7 @@ const checkObject = (elements) => {
|
|
|
90
82
|
return a.node.properties.length;
|
|
91
83
|
};
|
|
92
84
|
|
|
93
|
-
|
|
85
|
+
export const isSimpleAndNotEmptyObject = (elements) => {
|
|
94
86
|
const [a] = elements;
|
|
95
87
|
|
|
96
88
|
const simpleTypes = [
|
|
@@ -107,13 +99,13 @@ module.exports.isSimpleAndNotEmptyObject = (elements) => {
|
|
|
107
99
|
return checkObject(elements);
|
|
108
100
|
};
|
|
109
101
|
|
|
110
|
-
|
|
102
|
+
export const isIdentifierAndIdentifier = ([a, b]) => {
|
|
111
103
|
return isIdentifier(a) && isIdentifier(b);
|
|
112
104
|
};
|
|
113
105
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
106
|
+
export const isStringAndMember = ([a, b]) => isStringLiteral(a) && isMemberExpression(b);
|
|
107
|
+
export const isIdentifierAndString = ([a, b]) => isIdentifier(a) && isStringLiteral(b);
|
|
108
|
+
export const isStringAndArray = ([a, b]) => {
|
|
117
109
|
if (!isStringLiteral(a))
|
|
118
110
|
return false;
|
|
119
111
|
|
|
@@ -126,9 +118,9 @@ module.exports.isStringAndArray = ([a, b]) => {
|
|
|
126
118
|
const isIfOrStatement = (a) => isIfStatement(a) || isStatement(a);
|
|
127
119
|
const isForOfOrStatement = (a) => isForOfStatement(a) || isStatement(a);
|
|
128
120
|
|
|
129
|
-
|
|
121
|
+
export const isIf = (path) => isIfStatement(path.find(isIfOrStatement));
|
|
130
122
|
|
|
131
|
-
|
|
123
|
+
export const isForOf = (path) => {
|
|
132
124
|
const current = path.find(isForOfOrStatement);
|
|
133
125
|
|
|
134
126
|
if (isForOfStatement(current))
|
|
@@ -140,9 +132,9 @@ module.exports.isForOf = (path) => {
|
|
|
140
132
|
return false;
|
|
141
133
|
};
|
|
142
134
|
|
|
143
|
-
|
|
135
|
+
export const isInsideIf = (path) => path.parentPath?.isIfStatement();
|
|
144
136
|
|
|
145
|
-
|
|
137
|
+
export const isNewlineBetweenSiblings = (path) => {
|
|
146
138
|
const endCurrent = path.node?.loc?.end?.line;
|
|
147
139
|
const startNext = path.getNextSibling().node?.loc?.start?.line;
|
|
148
140
|
|
|
@@ -152,9 +144,9 @@ module.exports.isNewlineBetweenSiblings = (path) => {
|
|
|
152
144
|
return startNext - endCurrent > 1;
|
|
153
145
|
};
|
|
154
146
|
|
|
155
|
-
|
|
147
|
+
export const isInsideLabel = ({parentPath}) => isLabeledStatement(parentPath);
|
|
156
148
|
|
|
157
|
-
|
|
149
|
+
export const satisfy = (conditions) => (path) => {
|
|
158
150
|
for (const condition of conditions)
|
|
159
151
|
if (condition(path))
|
|
160
152
|
return true;
|
|
@@ -164,17 +156,17 @@ module.exports.satisfy = (conditions) => (path) => {
|
|
|
164
156
|
|
|
165
157
|
const parseNode = (path) => path.node || path;
|
|
166
158
|
|
|
167
|
-
|
|
159
|
+
export const hasCoupleTrailingComments = (path) => {
|
|
168
160
|
const node = parseNode(path);
|
|
169
161
|
return node?.trailingComments?.length > 1;
|
|
170
162
|
};
|
|
171
163
|
|
|
172
|
-
|
|
164
|
+
export const hasTrailingComment = (path) => {
|
|
173
165
|
const node = parseNode(path);
|
|
174
166
|
return node.trailingComments?.length;
|
|
175
167
|
};
|
|
176
168
|
|
|
177
|
-
|
|
169
|
+
export const hasLeadingComment = (path) => path.node?.leadingComments?.length;
|
|
178
170
|
|
|
179
|
-
|
|
180
|
-
|
|
171
|
+
export const noTrailingComment = (path) => !path.node.trailingComments?.length;
|
|
172
|
+
export const noLeadingComment = (path) => !path.node.leadingComments?.length;
|
|
@@ -1,48 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
import {isCoupleLines} from '#is';
|
|
2
|
+
import {parseComments} from '../comment/comment.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const {JSXText} = require('./jsx-text/jsx-text');
|
|
9
|
-
const {parseComments} = require('../comment/comment');
|
|
4
|
+
export {JSXElement} from './jsx-element.js';
|
|
5
|
+
export {JSXAttribute} from './jsx-attribute.js';
|
|
6
|
+
export {JSXOpeningElement} from './jsx-opening-element.js';
|
|
7
|
+
export * from './jsx-fragment.js';
|
|
8
|
+
export {JSXText} from './jsx-text/jsx-text.js';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
JSXElement,
|
|
14
|
-
JSXAttribute,
|
|
15
|
-
JSXOpeningElement,
|
|
16
|
-
JSXText,
|
|
17
|
-
JSXEmptyExpression(path, operations, semantics) {
|
|
18
|
-
parseComments(path, operations, semantics);
|
|
19
|
-
},
|
|
20
|
-
JSXExpressionContainer(path, {print}) {
|
|
21
|
-
print('{');
|
|
22
|
-
print('__expression');
|
|
23
|
-
print('}');
|
|
24
|
-
},
|
|
25
|
-
JSXIdentifier(path, {write}) {
|
|
26
|
-
write(path.node.name);
|
|
27
|
-
},
|
|
28
|
-
JSXMemberExpression(path, {print}) {
|
|
29
|
-
print('__object');
|
|
30
|
-
print('.');
|
|
31
|
-
print('__property');
|
|
32
|
-
},
|
|
33
|
-
JSXSpreadAttribute(path, {print, maybe}) {
|
|
34
|
-
const isNewline = isCoupleLines(path.parentPath);
|
|
35
|
-
maybe.indent.inc(isNewline);
|
|
36
|
-
maybe.print.breakline(isNewline);
|
|
37
|
-
print('{');
|
|
38
|
-
print('...');
|
|
39
|
-
print('__argument');
|
|
40
|
-
print('}');
|
|
41
|
-
maybe.indent.dec(isNewline);
|
|
42
|
-
},
|
|
43
|
-
JSXClosingElement(path, {print}) {
|
|
44
|
-
print('</');
|
|
45
|
-
print('__name');
|
|
46
|
-
print('>');
|
|
47
|
-
},
|
|
10
|
+
export const JSXEmptyExpression = (path, operations, semantics) => {
|
|
11
|
+
parseComments(path, operations, semantics);
|
|
48
12
|
};
|
|
13
|
+
export const JSXExpressionContainer = (path, {print}) => {
|
|
14
|
+
print('{');
|
|
15
|
+
print('__expression');
|
|
16
|
+
print('}');
|
|
17
|
+
};
|
|
18
|
+
export const JSXIdentifier = (path, {write}) => {
|
|
19
|
+
write(path.node.name);
|
|
20
|
+
};
|
|
21
|
+
export const JSXMemberExpression = (path, {print}) => {
|
|
22
|
+
print('__object');
|
|
23
|
+
print('.');
|
|
24
|
+
print('__property');
|
|
25
|
+
};
|
|
26
|
+
export const JSXSpreadAttribute = (path, {print, maybe}) => {
|
|
27
|
+
const isNewline = isCoupleLines(path.parentPath);
|
|
28
|
+
maybe.indent.inc(isNewline);
|
|
29
|
+
maybe.print.breakline(isNewline);
|
|
30
|
+
print('{');
|
|
31
|
+
print('...');
|
|
32
|
+
print('__argument');
|
|
33
|
+
print('}');
|
|
34
|
+
maybe.indent.dec(isNewline);
|
|
35
|
+
};
|
|
36
|
+
export const JSXClosingElement = (path, {print}) => {
|
|
37
|
+
print('</');
|
|
38
|
+
print('__name');
|
|
39
|
+
print('>');
|
|
40
|
+
};
|
|
41
|
+
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {
|
|
5
4
|
isJSXElement,
|
|
6
5
|
isJSXExpressionContainer,
|
|
@@ -10,7 +9,7 @@ const {
|
|
|
10
9
|
|
|
11
10
|
const isInsideArrow = ({parentPath}) => parentPath.isArrowFunctionExpression();
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
export const JSXElement = {
|
|
14
13
|
condition,
|
|
15
14
|
before(path, {write, indent, maybe}) {
|
|
16
15
|
const {leadingComments} = path.node;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports.JSXFragment = {
|
|
1
|
+
export const JSXFragment = {
|
|
4
2
|
condition,
|
|
5
3
|
before(path, {write, indent}) {
|
|
6
4
|
write('(');
|
|
@@ -19,11 +17,11 @@ module.exports.JSXFragment = {
|
|
|
19
17
|
},
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
export const JSXOpeningFragment = (path, {write}) => {
|
|
23
21
|
write('<>');
|
|
24
22
|
};
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
export const JSXClosingFragment = (path, {write}) => {
|
|
27
25
|
write('</>');
|
|
28
26
|
};
|
|
29
27
|
|