@putout/printer 1.18.1 → 1.19.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.04.03, v1.19.0
2
+
3
+ feature:
4
+ - c439209 @putout/printer: add support of TSTypeAliasDeclaration
5
+
6
+ 2023.04.02, v1.18.2
7
+
8
+ feature:
9
+ - dfbe134 @putout/printer: ArrayExpression tuple: improve support
10
+
1
11
  2023.04.02, v1.18.1
2
12
 
3
13
  feature:
@@ -21,13 +21,10 @@ function BinaryExpression(path, {write, traverse, maybe}) {
21
21
  maybe.write(isLeft, '(');
22
22
  traverse(left);
23
23
  maybe.write(isLeft, ')');
24
-
25
24
  write.space();
26
25
  write(path.node.operator);
27
26
  write.space();
28
-
29
27
  maybe.write(isRight, '(');
30
28
  traverse(right);
31
29
  maybe.write(isRight, ')');
32
30
  }
33
-
@@ -3,8 +3,15 @@
3
3
  module.exports.ClassExpression = classVisitor;
4
4
  module.exports.ClassDeclaration = classVisitor;
5
5
 
6
- function classVisitor(path, {print, indent}) {
6
+ module.exports.ClassDeclaration = (path, {print, indent}) => {
7
7
  indent();
8
+ classVisitor(path, {
9
+ print,
10
+ indent,
11
+ });
12
+ };
13
+
14
+ function classVisitor(path, {print, indent}) {
8
15
  print('class ');
9
16
  print('__id');
10
17
  print('__typeParameters');
@@ -16,7 +23,13 @@ function classVisitor(path, {print, indent}) {
16
23
  path.get('implements').forEach(print);
17
24
  }
18
25
 
19
- print(' {\n');
26
+ if (node.superClass) {
27
+ print('extends ');
28
+ print('__superClass');
29
+ }
30
+
31
+ print(' {');
32
+ print.newline();
20
33
  indent.inc();
21
34
 
22
35
  const body = path.get('body.body');
@@ -27,5 +40,6 @@ function classVisitor(path, {print, indent}) {
27
40
  }
28
41
 
29
42
  indent.dec();
43
+ indent();
30
44
  print('}');
31
45
  }
@@ -3,7 +3,7 @@
3
3
  const {hasPrevNewline} = require('../mark');
4
4
  const isFirst = (path) => !path.getPrevSibling().node;
5
5
 
6
- module.exports.FunctionExpression = (path, {print, maybe}) => {
6
+ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
7
7
  const {node} = path;
8
8
 
9
9
  const {
@@ -14,7 +14,16 @@ module.exports.FunctionExpression = (path, {print, maybe}) => {
14
14
  maybe.print(async, 'async ');
15
15
  print('function');
16
16
  maybe.print(generator, '*');
17
- print(' (');
17
+
18
+ const id = path.get('id');
19
+
20
+ write.space();
21
+
22
+ if (id.node) {
23
+ traverse(id);
24
+ }
25
+
26
+ print('(');
18
27
 
19
28
  const params = path.get('params');
20
29
  const n = params.length;
@@ -17,7 +17,17 @@ module.exports.MemberExpression = (path, {print}) => {
17
17
  };
18
18
 
19
19
  module.exports.OptionalMemberExpression = (path, {print}) => {
20
+ const {computed} = path.node;
20
21
  print('__object');
21
22
  print('?.');
23
+
24
+ if (computed) {
25
+ print('[');
26
+ print('__property');
27
+ print(']');
28
+
29
+ return;
30
+ }
31
+
22
32
  print('__property');
23
33
  };
@@ -43,7 +43,6 @@ function unaryExpression(path, {maybe, traverse}) {
43
43
 
44
44
  maybe.print(prefix, operator);
45
45
  maybe.print(isWord(operator), ' ');
46
-
47
46
  maybe.print(round, '(');
48
47
  traverse(argPath);
49
48
  maybe.print(round, ')');
@@ -25,7 +25,6 @@ module.exports.ForStatement = {
25
25
  print('__body');
26
26
  } else {
27
27
  const is = !path.get('body').isEmptyStatement();
28
-
29
28
  maybe.print.newline(is);
30
29
  maybe.indent.inc(is);
31
30
  print('__body');
@@ -20,7 +20,9 @@ module.exports.ImportDeclaration = {
20
20
  if (spec.isImportSpecifier()) {
21
21
  maybe.print(index, ', ');
22
22
  maybe.print(!wasSpecifier, '{');
23
+
23
24
  wasSpecifier = true;
25
+
24
26
  print(spec.get('imported'));
25
27
  maybe.print(index === n, '}');
26
28
 
@@ -23,13 +23,36 @@ module.exports = {
23
23
  TSAnyKeyword(path, {write}) {
24
24
  write('any');
25
25
  },
26
- TSTypeAnnotation(path, {print}) {
27
- print(':');
26
+ TSVoidKeyword(path, {write}) {
27
+ write('void');
28
+ },
29
+ TSFunctionType(path, {print}) {
30
+ print('(');
31
+ print(')');
32
+ print.space();
33
+ print('=>');
28
34
  print.space();
29
35
  print('__typeAnnotation');
30
36
  },
37
+ TSTypeAnnotation(path, {print}) {
38
+ if (!path.parentPath.isTSFunctionType()) {
39
+ print(':');
40
+ print.space();
41
+ }
42
+
43
+ print('__typeAnnotation');
44
+ },
31
45
  TSExpressionWithTypeArguments(path, {print}) {
32
46
  print('__expression');
33
47
  print('__typeParameters');
34
48
  },
49
+ TSTypeAliasDeclaration(path, {print}) {
50
+ print('type ');
51
+ print('__id');
52
+ print.space();
53
+ print('=');
54
+ print.space();
55
+ print('__typeAnnotation');
56
+ print(';');
57
+ },
35
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.18.1",
3
+ "version": "1.19.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",