@putout/printer 1.52.4 → 1.54.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
+ 2023.04.18, v1.54.0
2
+
3
+ feature:
4
+ - 6c8bac0 @putout/printer add support of Import
5
+
6
+ 2023.04.17, v1.53.0
7
+
8
+ feature:
9
+ - fd99eef @putout/printer: VariableDeclaration: use afterSatisfy
10
+
1
11
  2023.04.17, v1.52.4
2
12
 
3
13
  fix:
@@ -1,10 +1,22 @@
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
  };
22
+
@@ -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
  };
@@ -39,7 +39,15 @@ module.exports.VariableDeclaration = {
39
39
 
40
40
  store(wasNewline);
41
41
  },
42
- afterIf: shouldAddNewlineAfter,
42
+ afterSatisfy: () => [
43
+ noNextParentBlock,
44
+ notLastCoupleLines,
45
+ isNextAssign,
46
+ isNextCoupleLines,
47
+ notLastPrevVarNotNextVar,
48
+ isNewlineBetweenStatements,
49
+ notLastParentExport,
50
+ ],
43
51
  after(path, {maybe, store}) {
44
52
  const wasNewline = store();
45
53
  maybe.print.linebreak(wasNewline);
@@ -49,7 +57,10 @@ module.exports.VariableDeclaration = {
49
57
  };
50
58
 
51
59
  function noNextParentBlock(path) {
52
- return !isNext(path) && path.parentPath.isBlockStatement();
60
+ if (isNext(path))
61
+ return false;
62
+
63
+ return path.parentPath.isBlockStatement();
53
64
  }
54
65
 
55
66
  function notLastParentExport(path) {
@@ -59,35 +70,24 @@ function notLastParentExport(path) {
59
70
  return path.parentPath.isExportDeclaration();
60
71
  }
61
72
 
62
- function shouldAddNewlineAfter(path) {
63
- if (noNextParentBlock(path))
64
- return true;
65
-
73
+ function notLastCoupleLines(path) {
66
74
  if (isLast(path))
67
75
  return false;
68
76
 
69
- if (isCoupleLines(path))
70
- return true;
71
-
72
- if (isNextAssign(path))
73
- return true;
74
-
75
- const next = path.getNextSibling();
77
+ return isCoupleLines(path);
78
+ }
79
+
80
+ function notLastPrevVarNotNextVar(path) {
76
81
  const prev = path.getPrevSibling();
82
+ const next = path.getNextSibling();
77
83
 
78
- if (isCoupleLines(next))
79
- return true;
80
-
81
- if (prev.isVariableDeclaration() && !next.isVariableDeclaration())
82
- return true;
83
-
84
- if (isNewlineBetweenStatements(path))
85
- return true;
86
-
87
- if (notLastParentExport(path))
88
- return true;
84
+ return !isLast(path) && prev.isVariableDeclaration() && !next.isVariableDeclaration();
85
+ }
86
+
87
+ function isNextCoupleLines(path) {
88
+ const next = path.getNextSibling();
89
89
 
90
- return false;
90
+ return isCoupleLines(next);
91
91
  }
92
92
  const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
93
93
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.52.4",
3
+ "version": "1.54.0",
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",