@putout/printer 8.13.0 → 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,8 @@
1
+ 2024.04.15, v8.14.0
2
+
3
+ feature:
4
+ - 214d6c7 @putout/printer: ObjectPattern: improve support of ArrayPattern tuple
5
+
1
6
  2024.04.11, v8.13.0
2
7
 
3
8
  feature:
@@ -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');
@@ -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
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.13.0",
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",