@putout/printer 1.130.0 → 1.130.2

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.06.03, v1.130.2
2
+
3
+ feature:
4
+ - 7607ed8 @putout/printer: ExportDeclaration: newline
5
+
6
+ 2023.06.03, v1.130.1
7
+
8
+ feature:
9
+ - ed75f1a ImportDeclaration: assertions, attributes
10
+
1
11
  2023.06.03, v1.130.0
2
12
 
3
13
  feature:
@@ -4,6 +4,8 @@ const {
4
4
  isNewlineBetweenSiblings,
5
5
  exists,
6
6
  isNext,
7
+ isLast,
8
+
7
9
  } = require('../../is');
8
10
 
9
11
  const {
@@ -107,6 +109,9 @@ module.exports.ExportNamedDeclaration = {
107
109
  print('__declaration');
108
110
  },
109
111
  afterIf(path) {
112
+ if (isLast(path))
113
+ return false;
114
+
110
115
  if (isDeclarationNewline(path))
111
116
  return false;
112
117
 
@@ -1,48 +1,47 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports.ImportAttribute = (path, {print}) => {
4
- print('{');
5
- print.space();
6
4
  print('__key');
7
5
  print(':');
8
6
  print.space();
9
7
  print('__value');
10
- print.space();
11
- print('}');
12
8
  };
13
9
 
14
- module.exports.printAttributes = (path, {write, traverse}) => {
10
+ module.exports.maybePrintAttributes = (path, {write, traverse}) => {
15
11
  if (isAssertions(path))
16
- printAssertions(path, {
12
+ return printAttributes(path, {
17
13
  write,
18
14
  traverse,
15
+ type: 'assertions',
16
+ keyword: 'assert',
19
17
  });
20
18
 
21
- const attributes = path.get('attributes');
22
-
23
- if (!attributes.length)
24
- return;
25
-
26
- write(' with');
27
- write.space();
28
-
29
- for (const attr of attributes) {
30
- traverse(attr);
31
- }
19
+ printAttributes(path, {
20
+ write,
21
+ traverse,
22
+ type: 'attributes',
23
+ keyword: 'with',
24
+ });
32
25
  };
33
26
 
34
- const isAssertions = (path) => path.node.assertions;
27
+ const isAssertions = (path) => path.node.assertions.length;
35
28
 
36
- function printAssertions(path, {write, traverse}) {
37
- const attributes = path.get('assertions');
29
+ function printAttributes(path, {write, traverse, type, keyword}) {
30
+ const attributes = path.get(type);
38
31
 
39
32
  if (!attributes.length)
40
33
  return;
41
34
 
42
- write(' assert');
35
+ write(` ${keyword}`);
36
+ write.space();
37
+
38
+ write('{');
43
39
  write.space();
44
40
 
45
41
  for (const attr of attributes) {
46
42
  traverse(attr);
47
43
  }
44
+
45
+ write.space();
46
+ write('}');
48
47
  }
@@ -5,7 +5,7 @@ const {isLast} = require('../../is');
5
5
  const {parseSpecifiers} = require('./parse-specifiers');
6
6
 
7
7
  const {
8
- printAttributes,
8
+ maybePrintAttributes,
9
9
  ImportAttribute,
10
10
  } = require('./import-attribute');
11
11
 
@@ -89,7 +89,7 @@ module.exports.ImportDeclaration = {
89
89
  print.space();
90
90
 
91
91
  print('__source');
92
- printAttributes(path, {
92
+ maybePrintAttributes(path, {
93
93
  write,
94
94
  traverse,
95
95
  });
@@ -70,6 +70,10 @@ module.exports.VariableDeclaration = {
70
70
  ],
71
71
  after(path, {maybe, store}) {
72
72
  const wasNewline = store();
73
+
74
+ if (isLast(path.parentPath))
75
+ return false;
76
+
73
77
  maybe.print.linebreak(wasNewline);
74
78
  maybe.print.newline(!wasNewline);
75
79
  maybe.markAfter(wasNewline, path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.130.0",
3
+ "version": "1.130.2",
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",