@putout/printer 10.4.0 → 10.5.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.11.28, v10.5.0
2
+
3
+ feature:
4
+ - 9e2a3c5 @putout/printer: ObjectPattern: nested
5
+
6
+ 2024.11.27, v10.4.1
7
+
8
+ fix:
9
+ - 2b128c2 @putout/printer: comments
10
+
1
11
  2024.11.27, v10.4.0
2
12
 
3
13
  feature:
@@ -76,8 +76,10 @@ function isCommentOnNextLine(path) {
76
76
  if (!loc)
77
77
  return true;
78
78
 
79
- const isNextLine = line === loc.start.line + 1;
80
- const isNextLineAfterNewline = line === loc.start.line + 2;
79
+ const startLine = loc.start.line;
80
+ const endLine = loc.end.line;
81
+ const isNextLine = line === startLine + 1 && line === endLine + 1;
82
+ const isNextLineAfterNewline = line === startLine + 2 && line === endLine + 2;
81
83
 
82
84
  return isNextLine || isNextLineAfterNewline;
83
85
  }
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {
4
5
  isAssignmentPattern,
5
6
  isIdentifier,
6
- } = require('@putout/babel').types;
7
+ } = types;
7
8
 
8
9
  module.exports.moreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengthInOneLine}) => {
9
10
  const {properties} = path.node;
@@ -4,6 +4,7 @@ const {
4
4
  isIdentifier,
5
5
  isObjectPattern,
6
6
  isAssignmentPattern,
7
+ isVariableDeclarator,
7
8
  } = require('@putout/babel').types;
8
9
 
9
10
  const {wrongShorthand} = require('./wrong-shortand');
@@ -20,9 +21,6 @@ const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
20
21
  const {moreThenMaxPropertiesLengthInOneLine} = require('./more-then-max-properties-length-in-one-line');
21
22
  const {printKey} = require('../object-expression/print-key');
22
23
 
23
- const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObjectProperty();
24
- const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties?.length === 1;
25
-
26
24
  function isIndent(path) {
27
25
  return !path.parentPath.isArrayPattern();
28
26
  }
@@ -34,6 +32,9 @@ const isCoupleProperties = ({path, valuePath, property}) => {
34
32
  if (exists(property.getPrevSibling()))
35
33
  return false;
36
34
 
35
+ if (path.parentPath.isVariableDeclarator() && !hasAssign(path.get('properties')))
36
+ return false;
37
+
37
38
  return !path.parentPath.isObjectProperty();
38
39
  };
39
40
 
@@ -103,7 +104,7 @@ module.exports.ObjectPattern = {
103
104
  maybe.print.newline(couple);
104
105
  }
105
106
 
106
- if (is || hasObject && !isAssign) {
107
+ if (is || hasObject) {
107
108
  print(',');
108
109
  print.newline();
109
110
 
@@ -121,18 +122,6 @@ module.exports.ObjectPattern = {
121
122
  maybe.indent.inc(!shouldIndent);
122
123
  print('}');
123
124
  }),
124
- afterIf(path) {
125
- if (!path.parentPath.isObjectProperty())
126
- return false;
127
-
128
- if (isTwoLevelsDeep(path))
129
- return false;
130
-
131
- return isOneParentProperty(path);
132
- },
133
- after(path, {print}) {
134
- print.newline();
135
- },
136
125
  };
137
126
 
138
127
  function checkLength(properties) {
@@ -192,7 +181,10 @@ function shouldAddNewline(path, semantics) {
192
181
 
193
182
  const fnParam = isFunctionParam(path);
194
183
 
195
- if (moreCount && !moreLength)
184
+ if (hasObjectPattern(properties))
185
+ return COUPLE_LINES;
186
+
187
+ if (moreCount && !moreLength && isVariableDeclarator(path.parentPath))
196
188
  return ONE_LINE;
197
189
 
198
190
  if (!fnParam && n && !isForOf(path) && checkLength(properties))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "10.4.0",
3
+ "version": "10.5.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",