@putout/printer 1.128.0 → 1.129.0

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.02, v1.129.0
2
+
3
+ feature:
4
+ - 13e4315 @putout/printer: add support of ImportAttributes (https://babeljs.io/blog/2023/05/26/7.22.0#import-attributes-15536-15620)
5
+
6
+ 2023.06.01, v1.128.1
7
+
8
+ feature:
9
+ - 9de6e21 @putout/printer: ArrowFunctionExpression: braces
10
+
1
11
  2023.06.01, v1.128.0
2
12
 
3
13
  feature:
@@ -5,7 +5,9 @@ const isArg = (path) => path.parentPath.isFunction();
5
5
  module.exports.AssignmentPattern = {
6
6
  print(path, {print, maybe}) {
7
7
  maybe.print(shouldPrint(path), '__left');
8
- print(' = ');
8
+ print.space();
9
+ print('=');
10
+ print.space();
9
11
  print('__right');
10
12
  },
11
13
  };
@@ -1,14 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const isOneArgArrow = (path) => {
4
- if (path.type !== 'ArrowFunctionExpression')
5
- return false;
6
-
7
- return path.node.params.length === 1;
8
- };
9
-
10
3
  module.exports.printParams = (path, {print}) => {
11
- printBraceOpen(path, {print});
4
+ printBraceOpen(path, {
5
+ print,
6
+ });
12
7
 
13
8
  const params = path.get('params');
14
9
  const n = params.length;
@@ -22,7 +17,9 @@ module.exports.printParams = (path, {print}) => {
22
17
  }
23
18
  }
24
19
 
25
- printBraceClose(path, {print});
20
+ printBraceClose(path, {
21
+ print,
22
+ });
26
23
  };
27
24
 
28
25
  function printBraceOpen(path, {print}) {
@@ -38,3 +35,16 @@ function printBraceClose(path, {print}) {
38
35
 
39
36
  print(')');
40
37
  }
38
+
39
+ function isOneArgArrow(path) {
40
+ if (path.type !== 'ArrowFunctionExpression')
41
+ return false;
42
+
43
+ const {params} = path.node;
44
+ const [param] = params;
45
+
46
+ if (params.length !== 1)
47
+ return false;
48
+
49
+ return param.type === 'Identifier';
50
+ }
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ module.exports.ImportAttribute = (path, {print}) => {
4
+ print('{');
5
+ print.space();
6
+ print('__key');
7
+ print(':');
8
+ print.space();
9
+ print('__value');
10
+ print.space();
11
+ print('}');
12
+ };
13
+
14
+ module.exports.printAttributes = (path, {write, traverse}) => {
15
+ const attributes = path.get('attributes');
16
+
17
+ if (!attributes.length)
18
+ return;
19
+
20
+ write(' with');
21
+ write.space();
22
+
23
+ for (const attr of attributes) {
24
+ traverse(attr);
25
+ }
26
+ };
@@ -4,12 +4,18 @@ const {markAfter} = require('../../mark');
4
4
  const {isLast} = require('../../is');
5
5
  const {parseSpecifiers} = require('./parse-specifiers');
6
6
 
7
+ const {
8
+ printAttributes,
9
+ ImportAttribute,
10
+ } = require('./import-attribute');
11
+
7
12
  const options = {
8
13
  imports: {
9
14
  maxOneLineSpecifiers: 2,
10
15
  },
11
16
  };
12
17
 
18
+ module.exports.ImportAttribute = ImportAttribute;
13
19
  module.exports.ImportDeclaration = {
14
20
  print(path, {print, maybe, write, traverse, indent}) {
15
21
  const isType = path.node.importKind === 'type';
@@ -83,6 +89,10 @@ module.exports.ImportDeclaration = {
83
89
  print.space();
84
90
 
85
91
  print('__source');
92
+ printAttributes(path, {
93
+ write,
94
+ traverse,
95
+ });
86
96
  print(';');
87
97
 
88
98
  if (!isLast(path))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.128.0",
3
+ "version": "1.129.0",
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",