@putout/printer 1.18.2 → 1.20.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.20.0
2
+
3
+ feature:
4
+ - 069b266 @putout/printer: add support of TSPropertySignature
5
+
6
+ 2023.04.03, v1.19.0
7
+
8
+ feature:
9
+ - c439209 @putout/printer: add support of TSTypeAliasDeclaration
10
+
1
11
  2023.04.02, v1.18.2
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
-
@@ -5,7 +5,10 @@ module.exports.ClassDeclaration = classVisitor;
5
5
 
6
6
  module.exports.ClassDeclaration = (path, {print, indent}) => {
7
7
  indent();
8
- classVisitor(path, {print, indent});
8
+ classVisitor(path, {
9
+ print,
10
+ indent,
11
+ });
9
12
  };
10
13
 
11
14
  function classVisitor(path, {print, indent}) {
@@ -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
 
@@ -234,11 +234,13 @@ const createPrint = (path, {traverse, write}) => (maybeLine) => {
234
234
  };
235
235
 
236
236
  const computePath = (path, maybeLine) => {
237
- if (isString(maybeLine) && maybeLine.startsWith(GET))
237
+ if (isString(maybeLine) && maybeLine.startsWith(GET)) {
238
238
  return get(path, maybeLine);
239
+ }
239
240
 
240
241
  if (isObject(maybeLine))
241
242
  return maybeLine;
242
243
 
243
244
  return maybeLine;
244
245
  };
246
+
@@ -23,13 +23,59 @@ 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.isIdentifier()) {
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
+ },
58
+ TSTypeLiteral(path, {indent, traverse, write}) {
59
+ write('{');
60
+ write.newline();
61
+ indent.inc();
62
+ for (const member of path.get('members')) {
63
+ indent();
64
+ traverse(member);
65
+ write(';');
66
+ }
67
+
68
+ write.newline();
69
+ indent.dec();
70
+ write('}');
71
+ },
72
+ TSPropertySignature(path, {print, maybe}) {
73
+ const {optional} = path.node;
74
+ print('__key');
75
+ maybe.print(optional, '?');
76
+ print(':');
77
+ print.space();
78
+ print('__typeAnnotation');
79
+ },
35
80
  };
81
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.18.2",
3
+ "version": "1.20.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",
@@ -56,7 +56,7 @@
56
56
  "montag": "^1.0.0",
57
57
  "nodemon": "^2.0.1",
58
58
  "putout": "*",
59
- "putout-plugin-apply-computed-print": "./rules/putout-plugin-apply-computed-print",
59
+ "putout-plugin-printer": "./rules",
60
60
  "supertape": "^8.0.0",
61
61
  "try-catch": "^3.0.0"
62
62
  },
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- const {assign} = Object;
4
-
5
- module.exports.report = () => `Use print('__path') instead of path.get(__path)`;
6
-
7
- module.exports.replace = () => ({
8
- 'print(path.get(__a))': ({__a}) => {
9
- const {
10
- raw,
11
- value,
12
- } = __a;
13
-
14
- assign(__a, {
15
- value: `__${value}`,
16
- raw: raw.replace(value, `__${value}`),
17
- });
18
-
19
- return 'print(__a)';
20
- },
21
- });