@putout/printer 8.12.1 → 8.14.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.15, v8.14.0
2
+
3
+ feature:
4
+ - 214d6c7 @putout/printer: ObjectPattern: improve support of ArrayPattern tuple
5
+
6
+ 2024.04.11, v8.13.0
7
+
8
+ feature:
9
+ - 454c659 @putout/printer: ArrayExpression: SpreadElement, ObjectExpression
10
+
1
11
  2024.04.11, v8.12.1
2
12
 
3
13
  feature:
@@ -6,7 +6,7 @@ const {
6
6
  isStringAndIdentifier,
7
7
  isIdentifierAndIdentifier,
8
8
  isStringAndArray,
9
- isIdentifierAndObject,
9
+ isSimpleAndEmptyObject,
10
10
  } = require('../../is');
11
11
 
12
12
  const {
@@ -116,7 +116,7 @@ module.exports.ArrayExpression = {
116
116
  maybe.indent(elements.length && isNewLine);
117
117
  }
118
118
 
119
- if (isIdentifierAndObject(elements)) {
119
+ if (isSimpleAndEmptyObject(elements)) {
120
120
  print(',');
121
121
  print.breakline();
122
122
  }
@@ -21,7 +21,7 @@ const {
21
21
  isCoupleLines,
22
22
  isStringAndArray,
23
23
  isIdentifierAndIdentifier,
24
- isIdentifierAndObject,
24
+ isSimpleAndEmptyObject,
25
25
  } = require('../../is');
26
26
 
27
27
  const {round} = Math;
@@ -61,7 +61,7 @@ module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
61
61
  if (elements.length > 3 && !isObjectExpression(elements[0]))
62
62
  return MULTI_LINE;
63
63
 
64
- if (isIdentifierAndObject(elements))
64
+ if (isSimpleAndEmptyObject(elements))
65
65
  return MULTI_LINE;
66
66
 
67
67
  if (isOneSimple(path))
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {maybeTypeAnnotation} = require('../maybe/maybe-type-annotation');
3
+ const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
4
4
  const isForOf = ({parentPath}) => parentPath.parentPath.parentPath?.isForOfStatement();
5
5
 
6
6
  module.exports.ArrayPattern = maybeTypeAnnotation((path, {indent, maybe, print}, options) => {
@@ -29,7 +29,7 @@ const {
29
29
 
30
30
  const {AssignmentExpression} = require('./assignment-expression');
31
31
  const {ArrayExpression} = require('./array-expression/array-expression');
32
- const {ArrayPattern} = require('./array-pattern');
32
+ const {ArrayPattern} = require('./array-pattern/array-pattern');
33
33
  const {AssignmentPattern} = require('./assignment-pattern');
34
34
  const {RestElement} = require('./rest-element');
35
35
  const {SpreadElement} = require('./spread-element');
@@ -1,8 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const {types} = require('@putout/babel');
4
- const {isIdentifier} = types;
5
-
6
3
  const {
7
4
  isCoupleLines,
8
5
  isForOf,
@@ -21,11 +21,16 @@ const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObj
21
21
 
22
22
  const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties?.length === 1;
23
23
 
24
+ function isIndent(path) {
25
+ return !path.parentPath.isArrayPattern();
26
+ }
27
+
24
28
  module.exports.ObjectPattern = {
25
29
  print: maybeTypeAnnotation((path, {indent, print, maybe}, semantics) => {
26
30
  const {maxPropertiesInOneLine} = semantics;
27
31
 
28
- indent.inc();
32
+ const shouldIndent = isIndent(path);
33
+ maybe.indent.inc(shouldIndent);
29
34
  print('{');
30
35
 
31
36
  const properties = path.get('properties');
@@ -87,8 +92,8 @@ module.exports.ObjectPattern = {
87
92
  }
88
93
  }
89
94
 
90
- indent.dec();
91
- maybe.indent(is);
95
+ maybe.indent.dec(shouldIndent);
96
+ maybe.indent(is && shouldIndent);
92
97
  print('}');
93
98
  }),
94
99
  afterIf(path) {
@@ -158,3 +163,4 @@ function shouldAddNewline(path, {maxPropertiesInOneLine}) {
158
163
 
159
164
  return parentPath.isObjectProperty();
160
165
  }
166
+
@@ -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))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.12.1",
3
+ "version": "8.14.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",