@putout/printer 8.24.0 → 8.26.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
@@ -1,3 +1,13 @@
1
+ 2024.05.01, v8.26.0
2
+
3
+ feature:
4
+ - 510df22 @putout/printer: ArrayExpression: [boolean, object]
5
+
6
+ 2024.05.01, v8.25.0
7
+
8
+ feature:
9
+ - 095a130 @putout/printer: ImportDeclaration: maxPropertiesLengthInOneLine
10
+
1
11
  2024.04.30, v8.24.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -296,7 +296,7 @@ This is the same as `print('__left')` but more low-level, and supports only obje
296
296
  About speed, for file `speed.js`:
297
297
 
298
298
  ```js
299
- const {readFileSync} = require('fs');
299
+ const {readFileSync} = require('node:fs');
300
300
 
301
301
  const putout = require('putout');
302
302
  const parser = require('@babel/parser');
@@ -43,6 +43,7 @@ const isSimpleAndCall = ([a, b]) => {
43
43
  };
44
44
 
45
45
  const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
46
+ const isBooleanAndObject = ([a, b]) => isBooleanLiteral(a) && isObjectExpression(b);
46
47
  const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
47
48
  const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
48
49
  const ONE_LINE = false;
@@ -258,6 +259,9 @@ function isIncreaseIndent(path) {
258
259
  if (!elements.length)
259
260
  return false;
260
261
 
262
+ if (isBooleanAndObject(elements))
263
+ return true;
264
+
261
265
  if (isInsideCallLoop(path))
262
266
  return false;
263
267
 
@@ -53,7 +53,8 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
53
53
 
54
54
  const n = properties.length - 1;
55
55
 
56
- maybe.indent.inc(isMemberExpressionCallee(path));
56
+ const memberCallee = isMemberExpressionCallee(path);
57
+ maybe.indent.inc(memberCallee);
57
58
 
58
59
  for (const [index, property] of properties.entries()) {
59
60
  if (property.isSpreadElement()) {
@@ -94,7 +95,7 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
94
95
  print('}');
95
96
  maybe.print(parens, ')');
96
97
 
97
- maybe.indent.dec(isMemberExpressionCallee(path));
98
+ maybe.indent.dec(memberCallee);
98
99
  };
99
100
 
100
101
  const hasNextLeadingComment = (path) => {
@@ -168,6 +168,7 @@ function shouldAddNewline(path, semantics) {
168
168
  const moreLength = moreThenMaxPropertiesLengthInOneLine(path, {
169
169
  maxPropertiesLengthInOneLine,
170
170
  });
171
+
171
172
  const moreCount = moreThenMaxPropertiesInOneLine(path, {
172
173
  maxPropertiesInOneLine,
173
174
  });
@@ -12,7 +12,15 @@ const {
12
12
 
13
13
  module.exports.ImportAttribute = ImportAttribute;
14
14
  module.exports.ImportDeclaration = {
15
- print(path, {print, maybe, write, traverse, indent}, options) {
15
+ print(path, printer, semantics) {
16
+ const {
17
+ print,
18
+ maybe,
19
+ write,
20
+ traverse,
21
+ indent,
22
+ } = printer;
23
+
16
24
  const {phase} = path.node;
17
25
  const isType = path.node.importKind === 'type';
18
26
  const specifiers = path.get('specifiers');
@@ -44,7 +52,7 @@ module.exports.ImportDeclaration = {
44
52
  traverse(spec.get('local'));
45
53
  }
46
54
 
47
- const maxSpecifiersInOneLine = parseMaxSpecifiers(imports, options);
55
+ const maxSpecifiersInOneLine = parseMaxSpecifiers(imports, semantics);
48
56
  const importsCount = imports.length - 1;
49
57
 
50
58
  for (const [index, spec] of imports.entries()) {
@@ -75,9 +83,9 @@ module.exports.ImportDeclaration = {
75
83
  maybe.write(n, ',');
76
84
 
77
85
  const last = index === n;
78
- const penult = index === n - 1;
86
+ const penulty = index === n - 1;
79
87
 
80
- maybe.write.newline(penult && defaults.length);
88
+ maybe.write.newline(penulty && defaults.length);
81
89
  maybe.write.newline(last);
82
90
  }
83
91
 
@@ -110,12 +118,18 @@ module.exports.ImportDeclaration = {
110
118
  },
111
119
  };
112
120
 
113
- function parseMaxSpecifiers(imports, options) {
114
- const {maxSpecifiersInOneLine} = options;
121
+ function parseMaxSpecifiers(imports, semantics) {
122
+ const {
123
+ maxSpecifiersInOneLine,
124
+ maxPropertiesLengthInOneLine,
125
+ } = semantics;
115
126
 
116
127
  for (const {node} of imports) {
117
128
  if (node.imported.name !== node.local.name)
118
129
  return 1;
130
+
131
+ if (node.imported.name.length >= maxPropertiesLengthInOneLine)
132
+ return 1;
119
133
  }
120
134
 
121
135
  return maxSpecifiersInOneLine;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.24.0",
3
+ "version": "8.26.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",