@putout/printer 18.39.0 → 18.40.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
CHANGED
package/lib/printer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {tokenize} from './tokenize/tokenize.js';
|
|
2
2
|
import {printTokens} from './print-tokens/index.js';
|
|
3
3
|
import {maybeJSON} from './json.js';
|
|
4
|
+
import {maybeSQL} from './sql.js';
|
|
4
5
|
|
|
5
6
|
export {maybeVisitor} from './tokenize/maybe/index.js';
|
|
6
7
|
export * as visitors from './tokenize/visitors.js';
|
|
@@ -8,7 +9,11 @@ export * as visitors from './tokenize/visitors.js';
|
|
|
8
9
|
export const print = (ast, overrides = {}) => {
|
|
9
10
|
check(ast);
|
|
10
11
|
|
|
11
|
-
const options =
|
|
12
|
+
const options = {
|
|
13
|
+
...maybeJSON(ast, overrides),
|
|
14
|
+
...maybeSQL(ast, overrides),
|
|
15
|
+
};
|
|
16
|
+
|
|
12
17
|
const tokens = tokenize(ast, options);
|
|
13
18
|
|
|
14
19
|
return printTokens(tokens);
|
package/lib/sql.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {isSQL} from '@putout/operator-json';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
isCallExpression,
|
|
6
|
+
isIdentifier,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
export const maybeSQL = (ast, overrides) => {
|
|
10
|
+
if (isASTSQL(ast))
|
|
11
|
+
return {
|
|
12
|
+
...overrides,
|
|
13
|
+
semantics: {
|
|
14
|
+
...overrides?.semantics,
|
|
15
|
+
maxArgsInOneLine: 1,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return overrides;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function isASTSQL(ast) {
|
|
23
|
+
const {program} = ast;
|
|
24
|
+
|
|
25
|
+
if (!program)
|
|
26
|
+
return false;
|
|
27
|
+
|
|
28
|
+
const {body} = ast.program;
|
|
29
|
+
|
|
30
|
+
if (!body.length)
|
|
31
|
+
return false;
|
|
32
|
+
|
|
33
|
+
const {expression} = ast.program.body[0];
|
|
34
|
+
|
|
35
|
+
if (!isCallExpression(expression))
|
|
36
|
+
return false;
|
|
37
|
+
|
|
38
|
+
const {callee} = expression;
|
|
39
|
+
|
|
40
|
+
if (!isIdentifier(callee))
|
|
41
|
+
return false;
|
|
42
|
+
|
|
43
|
+
return isSQL(callee.name);
|
|
44
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
|
|
3
|
+
const {isArrayExpression} = types;
|
|
4
|
+
|
|
1
5
|
export const CallExpressionWithMaxArgs = (path, {write, indent, traverse}) => {
|
|
2
6
|
const {name} = path.node.callee;
|
|
3
7
|
const args = path.get('arguments');
|
|
@@ -7,7 +11,11 @@ export const CallExpressionWithMaxArgs = (path, {write, indent, traverse}) => {
|
|
|
7
11
|
indent.inc();
|
|
8
12
|
|
|
9
13
|
for (const arg of args) {
|
|
10
|
-
|
|
14
|
+
if (isArrayExpression(arg))
|
|
15
|
+
write.space();
|
|
16
|
+
else
|
|
17
|
+
write.breakline();
|
|
18
|
+
|
|
11
19
|
traverse(arg);
|
|
12
20
|
write(',');
|
|
13
21
|
}
|
|
@@ -16,3 +24,4 @@ export const CallExpressionWithMaxArgs = (path, {write, indent, traverse}) => {
|
|
|
16
24
|
write.breakline();
|
|
17
25
|
write(')');
|
|
18
26
|
};
|
|
27
|
+
|
package/package.json
CHANGED