@putout/printer 2.40.0 → 2.41.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,8 @@
1
+ 2023.06.22, v2.41.0
2
+
3
+ feature:
4
+ - 9c7e82f @putout/printer: expressions: Decorator: add
5
+
1
6
  2023.06.22, v2.40.0
2
7
 
3
8
  feature:
@@ -17,6 +17,7 @@ module.exports.ArrowFunctionExpression = {
17
17
 
18
18
  printParams(path, {
19
19
  print,
20
+ traverse,
20
21
  });
21
22
 
22
23
  const returnType = path.get('returnType');
@@ -4,7 +4,7 @@ const {isNext} = require('../../is');
4
4
  const {printParams} = require('./params');
5
5
 
6
6
  const ClassMethod = {
7
- print(path, {print, maybe}) {
7
+ print(path, {print, maybe, traverse}) {
8
8
  const {kind, computed} = path.node;
9
9
  const isConstructor = kind === 'constructor';
10
10
  const isMethod = kind === 'method';
@@ -26,6 +26,7 @@ const ClassMethod = {
26
26
 
27
27
  printParams(path, {
28
28
  print,
29
+ traverse,
29
30
  });
30
31
 
31
32
  print.space();
@@ -39,3 +40,4 @@ const ClassMethod = {
39
40
 
40
41
  module.exports.ClassPrivateMethod = ClassMethod;
41
42
  module.exports.ClassMethod = ClassMethod;
43
+
@@ -7,7 +7,7 @@ const {isNext, isNextParent} = require('../../is');
7
7
  const {printParams} = require('./params');
8
8
 
9
9
  module.exports.FunctionDeclaration = {
10
- print(path, {print, maybe}) {
10
+ print(path, {print, maybe, traverse}) {
11
11
  const {async, generator} = path.node;
12
12
 
13
13
  maybe.print(async, 'async ');
@@ -20,6 +20,7 @@ module.exports.FunctionDeclaration = {
20
20
 
21
21
  printParams(path, {
22
22
  print,
23
+ traverse,
23
24
  });
24
25
 
25
26
  print.space();
@@ -31,3 +32,4 @@ module.exports.FunctionDeclaration = {
31
32
  markAfter(path);
32
33
  },
33
34
  };
35
+
@@ -21,6 +21,7 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
21
21
 
22
22
  printParams(path, {
23
23
  print,
24
+ traverse,
24
25
  });
25
26
 
26
27
  print.space();
@@ -10,7 +10,7 @@ module.exports.ObjectMethod = {
10
10
  before(path, {write}) {
11
11
  write('async ');
12
12
  },
13
- print(path, {print, maybe}) {
13
+ print(path, {print, maybe, traverse}) {
14
14
  const {
15
15
  kind,
16
16
  generator,
@@ -28,6 +28,7 @@ module.exports.ObjectMethod = {
28
28
 
29
29
  printParams(path, {
30
30
  print,
31
+ traverse,
31
32
  });
32
33
 
33
34
  print.space();
@@ -40,3 +41,4 @@ module.exports.ObjectMethod = {
40
41
  print.linebreak();
41
42
  },
42
43
  };
44
+
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- module.exports.printParams = (path, {print}) => {
3
+ module.exports.printParams = (path, {print, traverse}) => {
4
4
  printBraceOpen(path, {
5
5
  print,
6
6
  });
@@ -9,7 +9,7 @@ module.exports.printParams = (path, {print}) => {
9
9
  const n = params.length;
10
10
 
11
11
  for (let i = 0; i < n; i++) {
12
- print(params[i]);
12
+ traverse(params[i]);
13
13
 
14
14
  if (i < n - 1) {
15
15
  print(',');
@@ -48,3 +48,4 @@ function isOneArgArrow(path) {
48
48
 
49
49
  return param.type === 'Identifier';
50
50
  }
51
+
@@ -1,12 +1,23 @@
1
1
  'use strict';
2
2
 
3
3
  const {TemplateLiteral} = require('./template-literal');
4
+ const maybeDecorators = (path) => {
5
+ if (!path.node.decorators)
6
+ return [];
7
+
8
+ return path.get('decorators');
9
+ };
4
10
 
5
11
  module.exports = {
6
12
  TemplateLiteral,
7
13
  BigIntLiteral(path, {write}) {
8
14
  write(path.node.raw);
9
15
  },
16
+ Decorator(path, {print}) {
17
+ print('@');
18
+ print('__expression');
19
+ print(' ');
20
+ },
10
21
  NumericLiteral(path, {write}) {
11
22
  const {
12
23
  raw,
@@ -24,16 +35,20 @@ module.exports = {
24
35
 
25
36
  write(raw || `'${value}'`);
26
37
  },
27
- Identifier(path, {write, print, maybe}) {
38
+ Identifier(path, {write, maybe, traverse}) {
28
39
  const {node} = path;
29
- const parenthesized = node.extra?.parenthesized;
30
-
31
40
  const {name, optional} = node;
41
+ const parenthesized = node.extra?.parenthesized;
42
+ const typeAnnotation = path.get('typeAnnotation');
32
43
 
33
44
  maybe.write(parenthesized, '(');
45
+ for (const decorator of maybeDecorators(path)) {
46
+ traverse(decorator);
47
+ }
48
+
34
49
  write(name);
35
50
  maybe.write(optional, '?');
36
- print('__typeAnnotation');
51
+ traverse(typeAnnotation);
37
52
  maybe.write(parenthesized, ')');
38
53
  },
39
54
  RegExpLiteral(path, {print}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.40.0",
3
+ "version": "2.41.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",