@putout/printer 8.12.0 → 8.13.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.04.11, v8.13.0
2
+
3
+ feature:
4
+ - 454c659 @putout/printer: ArrayExpression: SpreadElement, ObjectExpression
5
+
6
+ 2024.04.11, v8.12.1
7
+
8
+ feature:
9
+ - cfb862d @putout/printer: tokenize: ArrayExpression: Identifier, Object: Tuple
10
+
1
11
  2024.04.11, v8.12.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -183,7 +183,10 @@ When you want to improve support of existing visitor or extend **Printer** with
183
183
  When you need to override behavior of existing visitor use:
184
184
 
185
185
  ```js
186
- import {print, visitors as v} from '@putout/printer';
186
+ import {
187
+ print,
188
+ visitors as v,
189
+ } from '@putout/printer';
187
190
 
188
191
  print(ast, {
189
192
  visitors: {
@@ -6,6 +6,7 @@ const {
6
6
  isStringAndIdentifier,
7
7
  isIdentifierAndIdentifier,
8
8
  isStringAndArray,
9
+ isSimpleAndEmptyObject,
9
10
  } = require('../../is');
10
11
 
11
12
  const {
@@ -115,6 +116,11 @@ module.exports.ArrayExpression = {
115
116
  maybe.indent(elements.length && isNewLine);
116
117
  }
117
118
 
119
+ if (isSimpleAndEmptyObject(elements)) {
120
+ print(',');
121
+ print.breakline();
122
+ }
123
+
118
124
  print(']');
119
125
  },
120
126
  afterIf(path) {
@@ -12,7 +12,6 @@ const {
12
12
  isNullLiteral,
13
13
  isStringLiteral,
14
14
  isSpreadElement,
15
- isIdentifier,
16
15
  } = require('@putout/babel').types;
17
16
 
18
17
  const {
@@ -22,7 +21,7 @@ const {
22
21
  isCoupleLines,
23
22
  isStringAndArray,
24
23
  isIdentifierAndIdentifier,
25
- isIdentifierAndObject,
24
+ isSimpleAndEmptyObject,
26
25
  } = require('../../is');
27
26
 
28
27
  const {round} = Math;
@@ -62,7 +61,7 @@ module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
62
61
  if (elements.length > 3 && !isObjectExpression(elements[0]))
63
62
  return MULTI_LINE;
64
63
 
65
- if (isIdentifierAndObject(elements))
64
+ if (isSimpleAndEmptyObject(elements))
66
65
  return MULTI_LINE;
67
66
 
68
67
  if (isOneSimple(path))
@@ -9,7 +9,6 @@ const {
9
9
  noLeadingComment,
10
10
  hasLeadingComment,
11
11
  exists,
12
- isIdentifierAndObject,
13
12
  } = require('../../is');
14
13
 
15
14
  const {parseComments} = require('../../comment/comment');
@@ -89,24 +88,10 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
89
88
  }
90
89
 
91
90
  indent.dec();
92
- const isInsideArrayWithIdentifierFirst = ({parentPath}) => {
93
- if (!parentPath.isArrayExpression())
94
- return false;
95
-
96
- return isIdentifierAndObject(parentPath.get('elements'));
97
- };
98
91
 
99
92
  maybe.indent(manyLines);
100
93
 
101
- if (isInsideArrayWithIdentifierFirst(path)) {
102
- print('},');
103
- indent.dec();
104
- print.breakline();
105
- indent.inc();
106
- } else {
107
- print('}');
108
- }
109
-
94
+ print('}');
110
95
  maybe.print(parens, ')');
111
96
 
112
97
  maybe.indent.dec(isMemberExpressionCallee(path));
@@ -166,4 +151,3 @@ function isParens(path) {
166
151
 
167
152
  return isParentExpression(path);
168
153
  }
169
-
@@ -1,7 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {
4
5
  isStringLiteral,
6
+ isSpreadElement,
5
7
  isIdentifier,
6
8
  isIfStatement,
7
9
  isStatement,
@@ -10,7 +12,7 @@ const {
10
12
  isMemberExpression,
11
13
  isArrayExpression,
12
14
  isObjectExpression,
13
- } = require('@putout/babel').types;
15
+ } = types;
14
16
 
15
17
  const isParentProgram = (path) => path.parentPath?.isProgram();
16
18
  const isParentBlock = (path) => path.parentPath.isBlockStatement();
@@ -61,8 +63,8 @@ function isStringAndIdentifier([a, b]) {
61
63
  return isStringLiteral(a) && isIdentifier(b);
62
64
  }
63
65
 
64
- module.exports.isIdentifierAndObject = ([a, b]) => {
65
- if (!isIdentifier(a))
66
+ module.exports.isSimpleAndEmptyObject = ([a, b]) => {
67
+ if (!isIdentifier(a) && !isSpreadElement(a))
66
68
  return false;
67
69
 
68
70
  if (!isObjectExpression(b))
@@ -83,7 +83,6 @@ module.exports.VariableDeclaration = {
83
83
  write.newline();
84
84
  wasNewline = true;
85
85
  } else if (isParentSwitchCase(path)) {
86
- //write.breakline();
87
86
  write.newline();
88
87
  }
89
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.12.0",
3
+ "version": "8.13.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",