@putout/printer 1.17.1 → 1.18.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,13 @@
1
+ 2023.04.02, v1.18.1
2
+
3
+ feature:
4
+ - 37db57c @putout/printer: drop usless newlines after ImportDeclaration
5
+
6
+ 2023.04.02, v1.18.0
7
+
8
+ feature:
9
+ - 317a7cf @putout/printer: improve support of VariableDeclaration inside of ExportDeclaration
10
+
1
11
  2023.04.01, v1.17.1
2
12
 
3
13
  feature:
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {markAfter} = require('../mark');
4
+ const {isLast} = require('../is');
4
5
 
5
6
  module.exports.ImportDeclaration = {
6
7
  print(path, {print, maybe}) {
@@ -35,17 +36,21 @@ module.exports.ImportDeclaration = {
35
36
 
36
37
  print('__source');
37
38
  print(';');
38
- print.newline();
39
+
40
+ if (!isLast(path))
41
+ print.newline();
42
+ },
43
+ afterIf(path) {
44
+ if (isLast(path))
45
+ return false;
46
+
47
+ if (path.getNextSibling().isImportDeclaration())
48
+ return false;
49
+
50
+ return true;
39
51
  },
40
- afterIf: shouldAddNewlineAfter,
41
52
  after(path, {print}) {
42
53
  print.newline();
43
54
  markAfter(path);
44
55
  },
45
56
  };
46
- function shouldAddNewlineAfter(path) {
47
- if (path.getNextSibling().isImportDeclaration())
48
- return false;
49
-
50
- return true;
51
- }
@@ -10,7 +10,7 @@ const {
10
10
  markAfter,
11
11
  } = require('../mark');
12
12
 
13
- const isParentBlock = (path) => /Program|BlockStatement/.test(path.parentPath.type);
13
+ const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
14
14
 
15
15
  module.exports.VariableDeclaration = {
16
16
  beforeIf: shouldAddNewlineBefore,
@@ -88,7 +88,7 @@ function shouldAddNewlineBefore(path) {
88
88
  }
89
89
 
90
90
  function isFirst(path) {
91
- return path.node === path.parentPath.node.body[0];
91
+ return path.node === path.parentPath.node.body?.[0];
92
92
  }
93
93
  const isNextAssign = (path) => {
94
94
  const nextPath = path.getNextSibling();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.17.1",
3
+ "version": "1.18.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",