@putout/printer 1.130.0 → 1.130.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,8 @@
1
+ 2023.06.03, v1.130.1
2
+
3
+ feature:
4
+ - ed75f1a ImportDeclaration: assertions, attributes
5
+
1
6
  2023.06.03, v1.130.0
2
7
 
3
8
  feature:
@@ -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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.130.0",
3
+ "version": "1.130.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 for 🐊Putout",