@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
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2026.01.04, v17.0.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- b33d062 @putout/printer: migrate to ESM
|
|
5
|
+
- dcd78dd @putout/printer: redlint v5.0.2
|
|
6
|
+
- 45b4570 @putout/printer: goldstein v7.0.0
|
|
7
|
+
- 97a49eb @putout/printer: madrun v12.0.0
|
|
8
|
+
- 063fda0 @putout/printer: samadhi v4.0.2
|
|
9
|
+
- 3ff6ea5 @putout/printer: try-catch v4.0.6
|
|
10
|
+
- 09f5c5a @putout/printer: @putout/eslint v5.0.2
|
|
11
|
+
|
|
1
12
|
2026.01.03, v16.6.0
|
|
2
13
|
|
|
3
14
|
feature:
|
package/README.md
CHANGED
|
@@ -54,8 +54,8 @@ To benefit from it.
|
|
|
54
54
|
## Example
|
|
55
55
|
|
|
56
56
|
```js
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
import {print} from '@putout/printer';
|
|
58
|
+
import {parse} from 'putout';
|
|
59
59
|
const ast = parse('const a = (b, c) => {const d = 5; return a;}');
|
|
60
60
|
|
|
61
61
|
print(ast);
|
|
@@ -309,10 +309,10 @@ This is the same as `print('__left')` but more low-level, and supports only obje
|
|
|
309
309
|
About speed, for file `speed.js`:
|
|
310
310
|
|
|
311
311
|
```js
|
|
312
|
-
|
|
312
|
+
import {readFileSync} from 'node:fs';
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
314
|
+
import {putout} from 'putout';
|
|
315
|
+
import parser from '@babel/parser';
|
|
316
316
|
|
|
317
317
|
const code = readFileSync('./lib/tokenize/tokenize.js', 'utf8');
|
|
318
318
|
const ast = parser.parse(code);
|
package/lib/json.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
const {isJSON} = require('@putout/operator-json');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {isJSON} from '@putout/operator-json';
|
|
5
3
|
|
|
6
4
|
const {
|
|
7
5
|
isCallExpression,
|
|
8
6
|
isIdentifier,
|
|
9
7
|
} = types;
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
export const maybeJSON = (ast, overrides) => {
|
|
12
10
|
if (isASTJSON(ast))
|
|
13
11
|
return {
|
|
14
12
|
...overrides,
|
package/lib/print-tokens/cook.js
CHANGED
package/lib/printer.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import {tokenize} from './tokenize/tokenize.js';
|
|
2
|
+
import {printTokens} from './print-tokens/index.js';
|
|
3
|
+
import {maybeJSON} from './json.js';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {maybeJSON} = require('./json');
|
|
5
|
+
export {maybeVisitor} from './tokenize/maybe/index.js';
|
|
6
|
+
export * as visitors from './tokenize/visitors.js';
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
-
const visitors = require('./tokenize/visitors');
|
|
9
|
-
|
|
10
|
-
module.exports.print = (ast, overrides = {}) => {
|
|
8
|
+
export const print = (ast, overrides = {}) => {
|
|
11
9
|
check(ast);
|
|
12
10
|
|
|
13
11
|
const options = maybeJSON(ast, overrides);
|
|
@@ -16,9 +14,6 @@ module.exports.print = (ast, overrides = {}) => {
|
|
|
16
14
|
return printTokens(tokens);
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
module.exports.visitors = visitors;
|
|
20
|
-
module.exports.maybeVisitor = maybeVisitor;
|
|
21
|
-
|
|
22
17
|
function check(ast) {
|
|
23
18
|
if (typeof ast !== 'object')
|
|
24
19
|
throw Error('☝️Looks like ast not an object');
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const {parseTrailingComments} = require('./parse-trailing-comments');
|
|
5
|
-
const {parseComments} = require('./parse-comments');
|
|
6
|
-
|
|
7
|
-
module.exports.parseLeadingComments = parseLeadingComments;
|
|
8
|
-
module.exports.parseTrailingComments = parseTrailingComments;
|
|
9
|
-
module.exports.parseComments = parseComments;
|
|
1
|
+
export {parseLeadingComments} from './parse-leading-comments.js';
|
|
2
|
+
export {parseTrailingComments} from './parse-trailing-comments.js';
|
|
3
|
+
export {parseComments} from './parse-comments.js';
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const createPrintCommentLine = (fn, value) => () => fn(`//${value}`);
|
|
4
2
|
const createPrintCommentBlock = (fn, value) => () => fn(`/*${value}*/\n`);
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
export const hasTrailingCommentsPrinter = (currentTraverse) => {
|
|
7
5
|
const {
|
|
8
6
|
printTrailingCommentBlock,
|
|
9
7
|
printTrailingCommentLine,
|
|
@@ -15,7 +13,7 @@ module.exports.hasTrailingCommentsPrinter = (currentTraverse) => {
|
|
|
15
13
|
return Boolean(printTrailingCommentLine);
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
export const hasLeadingCommentsPrinter = (currentTraverse) => {
|
|
19
17
|
const {
|
|
20
18
|
printLeadingCommentLine,
|
|
21
19
|
printLeadingCommentBlock,
|
|
@@ -27,7 +25,7 @@ module.exports.hasLeadingCommentsPrinter = (currentTraverse) => {
|
|
|
27
25
|
return Boolean(printLeadingCommentBlock);
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
export const printLeadingComments = (path, printer, semantics, {currentTraverse}) => {
|
|
31
29
|
const {print} = printer;
|
|
32
30
|
const {
|
|
33
31
|
leadingComments = [],
|
|
@@ -58,7 +56,7 @@ module.exports.printLeadingComments = (path, printer, semantics, {currentTravers
|
|
|
58
56
|
}
|
|
59
57
|
};
|
|
60
58
|
|
|
61
|
-
|
|
59
|
+
export const printTrailingComments = (path, printer, semantics, {currentTraverse}) => {
|
|
62
60
|
const {print} = printer;
|
|
63
61
|
const {
|
|
64
62
|
trailingComments = []} = path.node;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {isNext} from '../is.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
module.exports.parseComments = (path, {write, maybe}, semantics) => {
|
|
3
|
+
export const parseComments = (path, {write, maybe}, semantics) => {
|
|
6
4
|
if (!semantics.comments)
|
|
7
5
|
return;
|
|
8
6
|
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {
|
|
5
3
|
hasTrailingComment,
|
|
6
4
|
satisfy,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const {
|
|
5
|
+
} from '../is.js';
|
|
6
|
+
import {markBefore} from '../mark.js';
|
|
7
|
+
import {maybeInsideFn} from './maybe-inside-fn.js';
|
|
8
|
+
import {
|
|
13
9
|
printLeadingComments,
|
|
14
10
|
hasLeadingCommentsPrinter,
|
|
15
|
-
}
|
|
11
|
+
} from './comments-printer/comments-printer.js';
|
|
16
12
|
|
|
17
13
|
const {
|
|
18
14
|
isArrowFunctionExpression,
|
|
@@ -86,7 +82,7 @@ const isFirst = (path) => {
|
|
|
86
82
|
return false;
|
|
87
83
|
};
|
|
88
84
|
|
|
89
|
-
|
|
85
|
+
export const parseLeadingComments = (path, printer, semantics, {currentTraverse = {}} = {}) => {
|
|
90
86
|
const {
|
|
91
87
|
print,
|
|
92
88
|
maybe,
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
|
|
5
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {
|
|
6
3
|
isLast,
|
|
7
4
|
isCoupleLines,
|
|
8
5
|
isNext,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const {
|
|
6
|
+
} from '../is.js';
|
|
7
|
+
import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain.js';
|
|
8
|
+
import {
|
|
14
9
|
printTrailingComments,
|
|
15
10
|
hasTrailingCommentsPrinter,
|
|
16
|
-
}
|
|
11
|
+
} from './comments-printer/comments-printer.js';
|
|
17
12
|
|
|
18
13
|
const {
|
|
19
14
|
isDecorator,
|
|
@@ -42,7 +37,7 @@ function isSameLine(path, loc) {
|
|
|
42
37
|
return path.node.loc?.start.line === loc.start.line || path.node.loc?.end.line === loc.end.line;
|
|
43
38
|
}
|
|
44
39
|
|
|
45
|
-
const isTrailingIsLeading = (path) => path.node.trailingComments === path.getNextSibling().node?.leadingComments;
|
|
40
|
+
export const isTrailingIsLeading = (path) => path.node.trailingComments === path.getNextSibling().node?.leadingComments;
|
|
46
41
|
|
|
47
42
|
const isNewlineAfter = (path) => {
|
|
48
43
|
const {parentPath} = path;
|
|
@@ -58,8 +53,6 @@ const isNewlineAfter = (path) => {
|
|
|
58
53
|
return !isLast(path);
|
|
59
54
|
};
|
|
60
55
|
|
|
61
|
-
module.exports.isTrailingIsLeading = isTrailingIsLeading;
|
|
62
|
-
|
|
63
56
|
function isCommentOnNextLine(path) {
|
|
64
57
|
const {node} = path;
|
|
65
58
|
const {
|
|
@@ -95,7 +88,7 @@ function isCommentOnNextLine(path) {
|
|
|
95
88
|
return isNextLine || isNextLineAfterNewline;
|
|
96
89
|
}
|
|
97
90
|
|
|
98
|
-
|
|
91
|
+
export const parseTrailingComments = (path, printer, semantics, {currentTraverse} = {}) => {
|
|
99
92
|
const {parentPath} = path;
|
|
100
93
|
const {
|
|
101
94
|
write,
|
package/lib/tokenize/debug.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {codeFrameColumns} = require('@putout/babel');
|
|
6
|
-
const {TYPES} = require('../types');
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import toSnakeCase from 'just-snake-case';
|
|
3
|
+
import {codeFrameColumns} from '@putout/babel';
|
|
4
|
+
import {TYPES} from '../types.js';
|
|
7
5
|
|
|
8
6
|
const {stringify} = JSON;
|
|
9
7
|
const {
|
|
@@ -14,7 +12,7 @@ const {
|
|
|
14
12
|
LOG_DEBUG,
|
|
15
13
|
} = process.env;
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
export const createDebug = (tokens) => (a) => {
|
|
18
16
|
if (!LOG_DEBUG)
|
|
19
17
|
return;
|
|
20
18
|
|
|
@@ -24,7 +22,7 @@ module.exports.createDebug = (tokens) => (a) => {
|
|
|
24
22
|
});
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
export const createLog = ({newline = '\n', store = createStore()} = {}) => ({type, value}) => {
|
|
28
26
|
if (LOG_TOKENS) {
|
|
29
27
|
console.log(codeFrameColumns(stringify({
|
|
30
28
|
type,
|
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
const {
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {
|
|
5
3
|
isCoupleLines,
|
|
6
4
|
isStringAndIdentifier,
|
|
7
5
|
isIdentifierAndIdentifier,
|
|
8
6
|
isStringAndArray,
|
|
9
7
|
isSimpleAndNotEmptyObject,
|
|
10
8
|
isNextObject,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const {
|
|
9
|
+
} from '#is';
|
|
10
|
+
import {
|
|
14
11
|
isIncreaseIndent,
|
|
15
12
|
isCurrentNewLine,
|
|
16
13
|
isMultiLine,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const {
|
|
14
|
+
} from './newline.js';
|
|
15
|
+
import {
|
|
20
16
|
isInsideArray,
|
|
21
17
|
isArrayInsideArray,
|
|
22
18
|
isArrayIndented,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const {
|
|
19
|
+
} from './indent.js';
|
|
20
|
+
import {
|
|
26
21
|
isObjectAfterSimple,
|
|
27
22
|
isNextSimple,
|
|
28
|
-
}
|
|
23
|
+
} from './is-object-after-simple.js';
|
|
29
24
|
|
|
30
25
|
const {
|
|
31
26
|
isObjectExpression,
|
|
@@ -79,7 +74,7 @@ const isNextSimpleBetweenObjects = (a) => {
|
|
|
79
74
|
|
|
80
75
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
81
76
|
|
|
82
|
-
|
|
77
|
+
export const ArrayExpression = {
|
|
83
78
|
beforeIf(path) {
|
|
84
79
|
const {parentPath} = path;
|
|
85
80
|
const {elements} = path.node;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
const {isIndented} = require('../../is');
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {isIndented} from '../../is.js';
|
|
5
3
|
|
|
6
4
|
const {
|
|
7
5
|
isStringLiteral,
|
|
8
6
|
isArrayExpression,
|
|
9
7
|
} = types;
|
|
10
8
|
|
|
11
|
-
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
12
|
-
|
|
13
|
-
module.exports.isInsideArray = isInsideArray;
|
|
9
|
+
export const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
export const isArrayIndented = (path) => {
|
|
16
12
|
const elements = path.get('elements');
|
|
17
13
|
|
|
18
14
|
if (isArrayInsideArray(path))
|
|
@@ -23,9 +19,7 @@ module.exports.isArrayIndented = (path) => {
|
|
|
23
19
|
return !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(first);
|
|
24
20
|
};
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function isArrayInsideArray(path) {
|
|
22
|
+
export function isArrayInsideArray(path) {
|
|
29
23
|
if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
|
|
30
24
|
return false;
|
|
31
25
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {isNextObject, isPrevObject} = require('../../is');
|
|
1
|
+
import {isNextObject, isPrevObject} from '../../is.js';
|
|
4
2
|
|
|
5
3
|
const SIMPLE_TYPES = [
|
|
6
4
|
'ArrayExpression',
|
|
@@ -11,7 +9,7 @@ const SIMPLE_TYPES = [
|
|
|
11
9
|
'NewExpression',
|
|
12
10
|
];
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
export const isObjectAfterSimple = (a) => {
|
|
15
13
|
const {type} = a;
|
|
16
14
|
|
|
17
15
|
if (!isNextObject(a) || isPrevObject(a))
|
|
@@ -20,7 +18,7 @@ module.exports.isObjectAfterSimple = (a) => {
|
|
|
20
18
|
return SIMPLE_TYPES.includes(type);
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export const isNextSimple = (a) => {
|
|
24
22
|
const {type} = a.getNextSibling();
|
|
25
23
|
|
|
26
24
|
return SIMPLE_TYPES.includes(type);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const {types} = require('@putout/babel');
|
|
5
|
-
|
|
6
|
-
const {
|
|
1
|
+
import {isSimple} from '@putout/operate';
|
|
2
|
+
import {types} from '@putout/babel';
|
|
3
|
+
import {
|
|
7
4
|
isStringAndMember,
|
|
8
5
|
isStringAndIdentifier,
|
|
9
6
|
isIdentifierAndString,
|
|
@@ -11,7 +8,7 @@ const {
|
|
|
11
8
|
isStringAndArray,
|
|
12
9
|
isIdentifierAndIdentifier,
|
|
13
10
|
isSimpleAndNotEmptyObject,
|
|
14
|
-
}
|
|
11
|
+
} from '../../is.js';
|
|
15
12
|
|
|
16
13
|
const {
|
|
17
14
|
isObjectExpression,
|
|
@@ -72,7 +69,7 @@ function isMaxElementLengthInOneLine(elements, maxElementLengthInOneLine) {
|
|
|
72
69
|
return first.node.name.length < maxElementLengthInOneLine;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
|
|
72
|
+
export const isMultiLine = (path, {elements, maxElementsInOneLine, maxElementLengthInOneLine}) => {
|
|
76
73
|
const [first] = elements;
|
|
77
74
|
|
|
78
75
|
if (isMaxElementLengthInOneLine(elements, maxElementLengthInOneLine))
|
|
@@ -270,8 +267,7 @@ const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
|
|
|
270
267
|
|
|
271
268
|
const isParentProperty = (path) => path.find(isObjectProperty);
|
|
272
269
|
|
|
273
|
-
|
|
274
|
-
function isIncreaseIndent(path) {
|
|
270
|
+
export function isIncreaseIndent(path) {
|
|
275
271
|
const elements = path.get('elements');
|
|
276
272
|
|
|
277
273
|
if (!elements.length)
|
|
@@ -306,7 +302,7 @@ const isStringAndObject = (elements) => {
|
|
|
306
302
|
return isStringLiteral(first) && isObjectExpression(last);
|
|
307
303
|
};
|
|
308
304
|
|
|
309
|
-
|
|
305
|
+
export const isCurrentNewLine = (path) => {
|
|
310
306
|
if (path.isSpreadElement())
|
|
311
307
|
return true;
|
|
312
308
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {maybeTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
|
|
2
2
|
|
|
3
|
-
const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
|
|
4
3
|
const isForOf = ({parentPath}) => parentPath.parentPath.parentPath?.isForOfStatement();
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export const ArrayPattern = maybeTypeAnnotation((path, {indent, maybe, print}, semantics) => {
|
|
7
6
|
const {maxElementsInOneLine} = semantics;
|
|
8
7
|
|
|
9
8
|
print('[');
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {hasLeadingComment} from '#is';
|
|
2
3
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
|
-
const {hasLeadingComment} = require('#is');
|
|
5
4
|
const {isReturnStatement} = types;
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
export const printLeadingCommentLine = (path, printer, semantics, {printComment, isLast}) => {
|
|
8
7
|
const {parentPath} = path;
|
|
9
8
|
const {print, maybe} = printer;
|
|
10
9
|
|
|
@@ -16,7 +15,7 @@ module.exports.printLeadingCommentLine = (path, printer, semantics, {printCommen
|
|
|
16
15
|
print.breakline();
|
|
17
16
|
};
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
export const printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
20
19
|
const {parentPath} = path;
|
|
21
20
|
const {print} = printer;
|
|
22
21
|
|
|
@@ -27,7 +26,7 @@ module.exports.printLeadingCommentBlock = (path, printer, semantics, {printComme
|
|
|
27
26
|
print.indent();
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
export const maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
|
|
31
30
|
const {parentPath} = path;
|
|
32
31
|
const is = isReturnStatement(parentPath);
|
|
33
32
|
|
|
@@ -47,7 +46,7 @@ module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
|
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
export const maybeInsideReturnWithCommentEnd = (path, {print, indent}) => {
|
|
51
50
|
const {parentPath} = path;
|
|
52
51
|
const is = isReturnStatement(parentPath);
|
|
53
52
|
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {condition} = require('./maybe-parens-condition');
|
|
4
|
-
|
|
5
|
-
const {
|
|
1
|
+
import {condition} from './maybe-parens-condition.js';
|
|
2
|
+
import {
|
|
6
3
|
printLeadingCommentLine,
|
|
7
4
|
maybeInsideReturnWithCommentEnd,
|
|
8
5
|
maybeInsideReturnWithCommentStart,
|
|
9
6
|
printLeadingCommentBlock,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const {printSeparator} = require('./print-separator');
|
|
7
|
+
} from './assignment-expression-comments.js';
|
|
8
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
9
|
+
import {printSeparator} from './print-separator.js';
|
|
14
10
|
|
|
15
11
|
const isInsideBlock = ({parentPath}) => /BlockStatement|Program/.test(parentPath.type);
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
export const AssignmentExpression = maybeParens({
|
|
18
14
|
checkParens: false,
|
|
19
15
|
condition,
|
|
20
16
|
print(path, printer) {
|
|
@@ -38,5 +34,5 @@ module.exports.AssignmentExpression = maybeParens({
|
|
|
38
34
|
},
|
|
39
35
|
});
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
|
|
38
|
+
AssignmentExpression.printLeadingCommentBlock = printLeadingCommentBlock;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import {hasLeadingComment} from '#is';
|
|
2
|
+
import {isParens} from '../../maybe/maybe-parens.js';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const {isParens} = require('../../maybe/maybe-parens');
|
|
6
|
-
|
|
7
|
-
module.exports.condition = (path, printer, semantics) => {
|
|
4
|
+
export const condition = (path, printer, semantics) => {
|
|
8
5
|
const {parentPath} = path;
|
|
9
6
|
const {type} = parentPath;
|
|
10
7
|
const {roundBraces} = semantics;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {
|
|
5
4
|
isAssignmentExpression,
|
|
6
5
|
isExpressionStatement,
|
|
7
6
|
} = types;
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export const printSeparator = (path, {print}) => {
|
|
10
9
|
if (isMultiline(path))
|
|
11
10
|
print.breakline();
|
|
12
11
|
else
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
concatenate,
|
|
5
3
|
isConcatenation,
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
4
|
+
} from './concatenate.js';
|
|
5
|
+
import {maybeSpace} from './maybe-space.js';
|
|
6
|
+
import {maybeParens} from '../../maybe/maybe-parens.js';
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
export const BinaryExpression = maybeParens((path, {print, indent, maybe}) => {
|
|
12
9
|
const {operator} = path.node;
|
|
13
10
|
|
|
14
11
|
if (operator === 'in' || operator === 'instanceof') {
|
|
@@ -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
|
isTemplateLiteral,
|
|
@@ -14,7 +13,7 @@ const isStringLike = (a) => {
|
|
|
14
13
|
return isTemplateLiteral(a);
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
export const isConcatenation = (path) => {
|
|
18
17
|
const {parentPath} = path;
|
|
19
18
|
const {operator} = path.node;
|
|
20
19
|
|
|
@@ -36,7 +35,7 @@ module.exports.isConcatenation = (path) => {
|
|
|
36
35
|
return isBinaryExpression(left) && isStringLike(right);
|
|
37
36
|
};
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
export const concatenate = (path, {print, indent}) => {
|
|
40
39
|
if (!path.parentPath.isBinaryExpression()) {
|
|
41
40
|
indent.inc();
|
|
42
41
|
print.breakline();
|