@putout/printer 1.129.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,13 @@
1
+ 2023.06.03, v1.130.1
2
+
3
+ feature:
4
+ - ed75f1a ImportDeclaration: assertions, attributes
5
+
6
+ 2023.06.03, v1.130.0
7
+
8
+ feature:
9
+ - 6b68c30 @putout/printer: get back assertion in ImportDeclarations
10
+
1
11
  2023.06.02, v1.129.0
2
12
 
3
13
  feature:
@@ -1,26 +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}) => {
15
- const attributes = path.get('attributes');
10
+ module.exports.maybePrintAttributes = (path, {write, traverse}) => {
11
+ if (isAssertions(path))
12
+ return printAttributes(path, {
13
+ write,
14
+ traverse,
15
+ type: 'assertions',
16
+ keyword: 'assert',
17
+ });
18
+
19
+ printAttributes(path, {
20
+ write,
21
+ traverse,
22
+ type: 'attributes',
23
+ keyword: 'with',
24
+ });
25
+ };
26
+
27
+ const isAssertions = (path) => path.node.assertions.length;
28
+
29
+ function printAttributes(path, {write, traverse, type, keyword}) {
30
+ const attributes = path.get(type);
16
31
 
17
32
  if (!attributes.length)
18
33
  return;
19
34
 
20
- write(' with');
35
+ write(` ${keyword}`);
36
+ write.space();
37
+
38
+ write('{');
21
39
  write.space();
22
40
 
23
41
  for (const attr of attributes) {
24
42
  traverse(attr);
25
43
  }
26
- };
44
+
45
+ write.space();
46
+ write('}');
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.129.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",