@putout/printer 1.53.0 → 1.54.1

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,14 @@
1
+ 2023.04.18, v1.54.1
2
+
3
+ feature:
4
+ - 7f6d7d4 @putout/printer: add support of Import used as object of MemberExpression
5
+ - c2b2e4b @putout/printer: VariableDeclaration: drop useless newline
6
+
7
+ 2023.04.18, v1.54.0
8
+
9
+ feature:
10
+ - 6c8bac0 @putout/printer add support of Import
11
+
1
12
  2023.04.17, v1.53.0
2
13
 
3
14
  feature:
@@ -1,10 +1,21 @@
1
1
  'use strict';
2
2
 
3
- module.exports.AssignmentExpression = (path, {print}) => {
4
- const {operator} = path.node;
5
- print('__left');
6
- print(' ');
7
- print(operator);
8
- print(' ');
9
- print('__right');
3
+ const {isObjectPattern} = require('@babel/types');
4
+
5
+ module.exports.AssignmentExpression = {
6
+ condition: (path) => isObjectPattern(path.node.left),
7
+ before(path, {write}) {
8
+ write('(');
9
+ },
10
+ print(path, {print}) {
11
+ const {operator} = path.node;
12
+ print('__left');
13
+ print(' ');
14
+ print(operator);
15
+ print(' ');
16
+ print('__right');
17
+ },
18
+ after(path, {write}) {
19
+ write(')');
20
+ },
10
21
  };
@@ -12,9 +12,14 @@ const {
12
12
  getTemplateValues,
13
13
  } = require('@putout/compare');
14
14
 
15
- module.exports.MemberExpression = (path, {print, indent, maybe}) => {
15
+ module.exports.MemberExpression = (path, {print, indent, maybe, traverse}) => {
16
16
  const {computed} = path.node;
17
- print('__object');
17
+ const object = path.get('object');
18
+ const isObjectAwait = object.isAwaitExpression();
19
+
20
+ maybe.print(isObjectAwait, '(');
21
+ traverse(object);
22
+ maybe.print(isObjectAwait, ')');
18
23
 
19
24
  if (computed) {
20
25
  print('[');
@@ -109,3 +114,4 @@ function isLooksLikeChain(path) {
109
114
 
110
115
  return !compare(parentPath, '__a.__b(__args)') || itMember || itExpression;
111
116
  }
117
+
@@ -78,10 +78,9 @@ module.exports.isNewlineBetweenStatements = (path) => {
78
78
  };
79
79
 
80
80
  module.exports.satisfy = (conditions) => (path) => {
81
- for (const condition of conditions) {
81
+ for (const condition of conditions)
82
82
  if (condition(path))
83
83
  return true;
84
- }
85
84
 
86
85
  return false;
87
86
  };
@@ -39,4 +39,7 @@ module.exports = {
39
39
  MetaProperty(path, {write}) {
40
40
  write('import.meta');
41
41
  },
42
+ Import(path, {write}) {
43
+ write('import');
44
+ },
42
45
  };
@@ -28,7 +28,7 @@ module.exports.ExpressionStatement = {
28
28
  }
29
29
  },
30
30
  afterSatisfy: () => [
31
- isParentOrNotLastORParentLast,
31
+ isParentBlockOrNotLastOrParentLast,
32
32
  isParentBlock,
33
33
  isNext,
34
34
  isNextUp,
@@ -49,7 +49,7 @@ function isNotLastBody(path) {
49
49
  return path.parentPath.get('body') === path;
50
50
  }
51
51
 
52
- function isParentOrNotLastORParentLast(path) {
52
+ function isParentBlockOrNotLastOrParentLast(path) {
53
53
  return isParentBlock(path) || !(isLast(path) || isParentLast(path));
54
54
  }
55
55
 
@@ -57,7 +57,10 @@ module.exports.VariableDeclaration = {
57
57
  };
58
58
 
59
59
  function noNextParentBlock(path) {
60
- return !isNext(path) && path.parentPath.isBlockStatement();
60
+ if (isNext(path))
61
+ return false;
62
+
63
+ return path.parentPath.isBlockStatement();
61
64
  }
62
65
 
63
66
  function notLastParentExport(path) {
@@ -68,7 +71,10 @@ function notLastParentExport(path) {
68
71
  }
69
72
 
70
73
  function notLastCoupleLines(path) {
71
- return !isLast(path) && isCoupleLines(path);
74
+ if (isLast(path))
75
+ return false;
76
+
77
+ return isCoupleLines(path);
72
78
  }
73
79
 
74
80
  function notLastPrevVarNotNextVar(path) {
@@ -83,7 +89,6 @@ function isNextCoupleLines(path) {
83
89
 
84
90
  return isCoupleLines(next);
85
91
  }
86
-
87
92
  const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
88
93
 
89
94
  function shouldAddNewlineBefore(path) {
@@ -116,6 +121,10 @@ const isNextAssign = (path) => {
116
121
  if (!nextPath.isExpressionStatement())
117
122
  return false;
118
123
 
119
- return nextPath
120
- .get('expression').isAssignmentExpression();
124
+ const {parentPath} = path;
125
+
126
+ if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
127
+ return false;
128
+
129
+ return nextPath.get('expression').isAssignmentExpression();
121
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.53.0",
3
+ "version": "1.54.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",