@putout/printer 1.119.0 → 1.120.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,9 @@
1
+ 2023.05.29, v1.120.0
2
+
3
+ feature:
4
+ - da33669 @putout/printer: ObjectProperty: improve support when one line inside LogicalExpression
5
+ - db06c37 @putout/printer: ObjectPattern: improve RestElement support
6
+
1
7
  2023.05.29, v1.119.0
2
8
 
3
9
  feature:
@@ -91,7 +91,8 @@ module.exports.ObjectProperty = (path, {print, maybe}) => {
91
91
  shorthand,
92
92
  computed,
93
93
  } = path.node;
94
-
94
+ const properties = path.parentPath.get('properties');
95
+ const isLast = path === properties.at(-1);
95
96
  const manyLines = !isOneLine(path.parentPath);
96
97
 
97
98
  maybe.print(computed, '[');
@@ -104,7 +105,10 @@ module.exports.ObjectProperty = (path, {print, maybe}) => {
104
105
  print('__value');
105
106
  }
106
107
 
107
- maybe.print(manyLines, ',');
108
+ if (manyLines)
109
+ print(',');
110
+ else if (!isLast && properties.length)
111
+ print(', ');
108
112
  };
109
113
 
110
114
  const ONE_LINE = true;
@@ -137,3 +141,4 @@ function isParens(path) {
137
141
 
138
142
  return false;
139
143
  }
144
+
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const {isIdentifier} = require('@babel/types');
3
+ const {
4
+ isIdentifier,
5
+ isObjectPattern,
6
+ } = require('@babel/types');
4
7
 
5
8
  const {
6
9
  isForOf,
@@ -22,14 +25,15 @@ module.exports.ObjectPattern = {
22
25
  const properties = path.get('properties');
23
26
  const n = properties.length - 1;
24
27
  const is = shouldAddNewline(path);
28
+ const hasObject = n && hasObjectPattern(properties);
25
29
 
26
30
  maybe.print(is, '\n');
27
31
 
28
32
  for (const [i, property] of properties.entries()) {
29
33
  if (property.isRestElement()) {
30
- maybe.indent(n > 1);
34
+ maybe.indent(hasObject);
31
35
  print(property);
32
- maybe.print.newline(n > 1);
36
+ maybe.print.newline(hasObject);
33
37
  continue;
34
38
  }
35
39
 
@@ -62,7 +66,7 @@ module.exports.ObjectPattern = {
62
66
  maybe.print.newline(couple);
63
67
  }
64
68
 
65
- if (is) {
69
+ if (is || hasObject) {
66
70
  print(',');
67
71
  print.newline();
68
72
 
@@ -83,7 +87,10 @@ module.exports.ObjectPattern = {
83
87
  if (!path.parentPath.isObjectProperty())
84
88
  return false;
85
89
 
86
- return isOneParentProperty(path);
90
+ if (isOneParentProperty(path))
91
+ return true;
92
+
93
+ return false;
87
94
  },
88
95
  after(path, {print}) {
89
96
  print.newline();
@@ -104,6 +111,15 @@ function checkLength(properties) {
104
111
  return false;
105
112
  }
106
113
 
114
+ function hasObjectPattern(properties) {
115
+ for (const property of properties) {
116
+ if (isObjectPattern(property.node.value))
117
+ return true;
118
+ }
119
+
120
+ return false;
121
+ }
122
+
107
123
  function shouldAddNewline(path) {
108
124
  const properties = path.get('properties');
109
125
  const n = properties.length - 1;
@@ -116,4 +132,3 @@ function shouldAddNewline(path) {
116
132
 
117
133
  return false;
118
134
  }
119
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.119.0",
3
+ "version": "1.120.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",