@putout/printer 8.13.0 → 8.15.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.16, v8.15.0
2
+
3
+ feature:
4
+ - e17158f @putout/printer: ObjectPattern: improve indentation
5
+
6
+ 2024.04.15, v8.14.0
7
+
8
+ feature:
9
+ - 214d6c7 @putout/printer: ObjectPattern: improve support of ArrayPattern tuple
10
+
1
11
  2024.04.11, v8.13.0
2
12
 
3
13
  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
- print: maybeTypeAnnotation((path, {indent, print, maybe}, semantics) => {
29
+ print: maybeTypeAnnotation((path, {print, maybe}, semantics) => {
26
30
  const {maxPropertiesInOneLine} = semantics;
31
+ const shouldIndent = isIndent(path);
27
32
 
28
- indent.inc();
33
+ maybe.indent.inc(shouldIndent);
29
34
  print('{');
30
35
 
31
36
  const properties = path.get('properties');
@@ -87,8 +92,11 @@ module.exports.ObjectPattern = {
87
92
  }
88
93
  }
89
94
 
90
- indent.dec();
95
+ maybe.indent.dec(shouldIndent);
96
+
97
+ maybe.indent.dec(!shouldIndent);
91
98
  maybe.indent(is);
99
+ maybe.indent.inc(!shouldIndent);
92
100
  print('}');
93
101
  }),
94
102
  afterIf(path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.13.0",
3
+ "version": "8.15.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",