@putout/printer 1.16.1 → 1.16.2

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
@@ -1,3 +1,8 @@
1
+ 2023.04.01, v1.16.2
2
+
3
+ feature:
4
+ - 6da9571 @putout/printer: improve support of ObjectExpression used as argument of CallExpression
5
+
1
6
  2023.04.01, v1.16.1
2
7
 
3
8
  feature:
@@ -27,7 +27,9 @@ const CallExpression = {
27
27
  maybe.indent.inc(isParentCall);
28
28
 
29
29
  for (const [i, arg] of args.entries()) {
30
- if (isParentCall) {
30
+ const isObject = arg.isObjectExpression();
31
+
32
+ if (isParentCall && !isObject) {
31
33
  print.newline();
32
34
  indent();
33
35
  }
@@ -80,7 +82,7 @@ function toLong(path) {
80
82
  const args = path.get('arguments');
81
83
 
82
84
  for (const arg of args) {
83
- if (arg.isIdentifier() && arg.node.name.length > 5)
85
+ if (arg.isIdentifier() && arg.node.name.length > 10)
84
86
  return true;
85
87
  }
86
88
 
@@ -3,6 +3,8 @@
3
3
  const {isCoupleLines} = require('../is');
4
4
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
5
5
  const isLogical = (path) => path.get('argument').isLogicalExpression();
6
+ const isValue = (path) => path.get('properties.0.value').node;
7
+ const isIf = (path) => path.parentPath.parentPath.isIfStatement();
6
8
 
7
9
  const isForOf = (path) => {
8
10
  if (path.parentPath.isForOfStatement())
@@ -74,18 +76,23 @@ module.exports.ObjectProperty = (path, {print, maybe}) => {
74
76
  maybe.print(manyLines, ',');
75
77
  };
76
78
 
79
+ const ONE_LINE = true;
80
+ const MANY_LINES = false;
81
+
77
82
  function isOneLine(path) {
78
- const isCall = path.parentPath.isCallExpression();
79
83
  const {length} = path.get('properties');
80
84
 
81
85
  if (!length)
82
86
  return true;
83
87
 
84
- if (isCoupleLines(path))
85
- return false;
88
+ if (isForOf(path))
89
+ return ONE_LINE;
86
90
 
87
- if (isCall && length < 2)
88
- return true;
91
+ if (isIf(path))
92
+ return ONE_LINE;
93
+
94
+ if (isCoupleLines(path))
95
+ return MANY_LINES;
89
96
 
90
- return isForOf(path);
97
+ return !isValue(path);
91
98
  }
@@ -12,32 +12,38 @@ const {
12
12
 
13
13
  const isParentBlock = (path) => /Program|BlockStatement/.test(path.parentPath.type);
14
14
 
15
- module.exports.VariableDeclaration = (path, {maybe, print}) => {
16
- if (shouldAddNewlineBefore(path))
15
+ module.exports.VariableDeclaration = {
16
+ beforeIf: shouldAddNewlineBefore,
17
+ before(path, {print}) {
17
18
  print.breakline();
18
-
19
- maybe.indent(isParentBlock(path));
20
- print(`${path.node.kind} `);
21
- print('__declarations.0.id');
22
-
23
- const initPath = path.get('declarations.0.init');
24
-
25
- maybe.print(initPath.node, ' = ');
26
- print(initPath);
27
- maybe.print(isParentBlock(path), ';');
28
-
29
- let wasNewline = false;
30
-
31
- if (isParentBlock(path) && isNext(path)) {
32
- print.newline();
33
- wasNewline = true;
34
- }
35
-
36
- if (shouldAddNewlineAfter(path)) {
19
+ },
20
+ print(path, {maybe, print, store}) {
21
+ maybe.indent(isParentBlock(path));
22
+ print(`${path.node.kind} `);
23
+ print('__declarations.0.id');
24
+
25
+ const initPath = path.get('declarations.0.init');
26
+
27
+ maybe.print(initPath.node, ' = ');
28
+ print(initPath);
29
+ maybe.print(isParentBlock(path), ';');
30
+
31
+ let wasNewline = false;
32
+
33
+ if (isParentBlock(path) && isNext(path)) {
34
+ print.newline();
35
+ wasNewline = true;
36
+ }
37
+
38
+ store(wasNewline);
39
+ },
40
+ afterIf: shouldAddNewlineAfter,
41
+ after(path, {maybe, store}) {
42
+ const wasNewline = store();
37
43
  maybe.print.linebreak(wasNewline);
38
44
  maybe.print.newline(!wasNewline);
39
45
  markAfter(path);
40
- }
46
+ },
41
47
  };
42
48
 
43
49
  function shouldAddNewlineAfter(path) {
@@ -53,7 +59,9 @@ function shouldAddNewlineAfter(path) {
53
59
  if (isNextAssign(path))
54
60
  return true;
55
61
 
56
- if (isCoupleLines(path.getNextSibling()))
62
+ const next = path.getNextSibling();
63
+
64
+ if (isCoupleLines(next))
57
65
  return true;
58
66
 
59
67
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.16.1",
3
+ "version": "1.16.2",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
@@ -44,6 +44,7 @@
44
44
  ],
45
45
  "devDependencies": {
46
46
  "@putout/test": "^6.0.1",
47
+ "acorn": "^8.8.2",
47
48
  "c8": "^7.5.0",
48
49
  "eslint": "^8.0.1",
49
50
  "eslint-plugin-n": "^15.2.4",
@@ -55,9 +56,9 @@
55
56
  "montag": "^1.0.0",
56
57
  "nodemon": "^2.0.1",
57
58
  "putout": "*",
59
+ "putout-plugin-apply-computed-print": "./rules/putout-plugin-apply-computed-print",
58
60
  "supertape": "^8.0.0",
59
- "try-catch": "^3.0.0",
60
- "putout-plugin-apply-computed-print": "./rules/putout-plugin-apply-computed-print"
61
+ "try-catch": "^3.0.0"
61
62
  },
62
63
  "license": "MIT",
63
64
  "engines": {