@putout/printer 1.70.4 → 1.71.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.25, v1.71.1
2
+
3
+ feature:
4
+ - 8391092 @putout/printer: improve support of trailingComments
5
+
6
+ 2023.04.25, v1.71.0
7
+
8
+ feature:
9
+ - b56cdb1 @putout/printer: ImportDeclaration: improve support of ImportSpecifier
10
+
1
11
  2023.04.25, v1.70.4
2
12
 
3
13
  feature:
@@ -1,8 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {isNext} = require('./is');
4
-
5
- const {markBefore} = require('./mark');
4
+ const {markBefore, isMarkedAfter} = require('./mark');
6
5
 
7
6
  module.exports.parseLeadingComments = (path, {print, maybe, indent}) => {
8
7
  const {leadingComments} = path.node;
@@ -60,6 +59,11 @@ module.exports.parseTrailingComments = (path, {write, maybe}) => {
60
59
 
61
60
  maybe.write.space(sameLine);
62
61
  maybe.indent(!sameLine);
62
+
63
+ if (!isMarkedAfter(path) && !sameLine) {
64
+ write.newline();
65
+ }
66
+
63
67
  write(`//${value}`);
64
68
  write.newline();
65
69
  }
@@ -11,6 +11,7 @@ const {
11
11
  isArrowFunctionExpression,
12
12
  isObjectMethod,
13
13
  } = require('@babel/types');
14
+ const {markAfter} = require('../mark');
14
15
 
15
16
  const isFirstStatement = (path) => path.get('body.0')?.isStatement();
16
17
  const isMethodOrArrow = (path) => isArrowFunctionExpression(path) || isObjectMethod(path);
@@ -45,6 +46,7 @@ module.exports.BlockStatement = {
45
46
  },
46
47
  after(path, {print}) {
47
48
  print.newline();
49
+ markAfter(path.parentPath);
48
50
  },
49
51
  };
50
52
 
@@ -23,12 +23,21 @@ module.exports.ImportDeclaration = {
23
23
  }
24
24
 
25
25
  if (spec.isImportSpecifier()) {
26
+ const {
27
+ imported,
28
+ local,
29
+ } = spec.node;
26
30
  maybe.print(index, ', ');
27
31
  maybe.print(!wasSpecifier, '{');
28
32
 
29
33
  wasSpecifier = true;
34
+ print(imported.name);
35
+
36
+ if (imported.name !== local.name) {
37
+ print(' as ');
38
+ print(spec.node.local.name);
39
+ }
30
40
 
31
- print(spec.get('imported'));
32
41
  maybe.print(index === n, '}');
33
42
 
34
43
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.70.4",
3
+ "version": "1.71.1",
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 fro 🐊Putout",