@putout/printer 5.28.0 → 5.30.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 +10 -0
- package/lib/printer.d.ts +66 -0
- package/lib/tokenize/expressions/call-expression.js +13 -5
- package/package.json +3 -1
package/ChangeLog
CHANGED
package/lib/printer.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
|
|
3
|
+
interface Format {
|
|
4
|
+
indent: string;
|
|
5
|
+
newline: string;
|
|
6
|
+
space: string;
|
|
7
|
+
splitter: string;
|
|
8
|
+
roundBraceOpen: string;
|
|
9
|
+
roundBraceClose: string;
|
|
10
|
+
quote: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface Semantics {
|
|
14
|
+
comments: boolean;
|
|
15
|
+
maxPropertiesInOneLine: number;
|
|
16
|
+
maxSpecifiersInOneLine: number;
|
|
17
|
+
maxElementsInOneLine: number;
|
|
18
|
+
maxVariablesInOneLine: number;
|
|
19
|
+
trailingComma: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Print = (input: string | types.Node) => void;
|
|
23
|
+
type Indent = () => void;
|
|
24
|
+
type Traverse = (input: types.Node) => void;
|
|
25
|
+
|
|
26
|
+
declare function MaybeIndent(condition: boolean): void;
|
|
27
|
+
declare namespace MaybeIndent {
|
|
28
|
+
type inc = () => void;
|
|
29
|
+
type dec = () => void;
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
inc,
|
|
33
|
+
dec,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type MaybePrint = (condition: boolean, input: string | types.Node) => void;
|
|
38
|
+
type MaybeTraverse = (condition: boolean, input: types.Node) => void;
|
|
39
|
+
|
|
40
|
+
interface Maybe {
|
|
41
|
+
print: MaybePrint;
|
|
42
|
+
traverse: MaybeTraverse;
|
|
43
|
+
indent: typeof MaybeIndent;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface Printer {
|
|
47
|
+
print: Print;
|
|
48
|
+
maybe: Maybe;
|
|
49
|
+
indent: Indent;
|
|
50
|
+
traverse: Traverse;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type Visitor = (path: types.Node, printer: Printer, semantics?: Semantics) => void;
|
|
54
|
+
|
|
55
|
+
interface Visitors {
|
|
56
|
+
[name: string]: Visitor;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface Options {
|
|
60
|
+
format?: Format;
|
|
61
|
+
semantics?: Semantics;
|
|
62
|
+
visitors?: Visitors;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function print(ast: types.Node, options?: Options): string;
|
|
66
|
+
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isArray} = Array;
|
|
3
4
|
const {exists} = require('../is');
|
|
4
5
|
|
|
6
|
+
const parseArgs = (path) => {
|
|
7
|
+
const argsPath = path.get('arguments');
|
|
8
|
+
|
|
9
|
+
if (!isArray(argsPath))
|
|
10
|
+
return [];
|
|
11
|
+
|
|
12
|
+
return argsPath;
|
|
13
|
+
};
|
|
14
|
+
|
|
5
15
|
function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
6
|
-
const
|
|
16
|
+
const args = parseArgs(path);
|
|
17
|
+
const isParentCall = tooLong(args) && path.parentPath.isCallExpression();
|
|
7
18
|
|
|
8
19
|
const callee = path.get('callee');
|
|
9
20
|
const typeParameters = path.get('typeParameters');
|
|
@@ -18,7 +29,6 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
|
18
29
|
|
|
19
30
|
print('(');
|
|
20
31
|
|
|
21
|
-
const args = path.get('arguments');
|
|
22
32
|
const n = args.length - 1;
|
|
23
33
|
|
|
24
34
|
maybe.indent.inc(isParentCall);
|
|
@@ -54,9 +64,7 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
|
54
64
|
module.exports.OptionalCallExpression = CallExpression;
|
|
55
65
|
module.exports.CallExpression = CallExpression;
|
|
56
66
|
|
|
57
|
-
function tooLong(
|
|
58
|
-
const args = path.get('arguments');
|
|
59
|
-
|
|
67
|
+
function tooLong(args) {
|
|
60
68
|
for (const arg of args) {
|
|
61
69
|
if (arg.isIdentifier() && arg.node.name.length > 10)
|
|
62
70
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.30.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"wisdom": "madrun wisdom",
|
|
18
18
|
"test": "madrun test",
|
|
19
|
+
"test:dts": "madrun test:dts",
|
|
19
20
|
"watch:test": "madrun watch:test",
|
|
20
21
|
"lint": "madrun lint",
|
|
21
22
|
"fresh:lint": "madrun fresh:lint",
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
"@putout/plugin-react-hooks": "^5.0.0",
|
|
54
55
|
"acorn": "^8.8.2",
|
|
55
56
|
"c8": "^8.0.0",
|
|
57
|
+
"check-dts": "^0.7.2",
|
|
56
58
|
"escover": "^3.0.0",
|
|
57
59
|
"eslint": "^8.0.1",
|
|
58
60
|
"eslint-plugin-n": "^16.0.0",
|