@putout/printer 1.37.0 → 1.39.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.12, v1.39.0
2
+
3
+ feature:
4
+ - b14f85d @putout/printer: add support of TSQualifiedName
5
+
6
+ 2023.04.12, v1.38.0
7
+
8
+ feature:
9
+ - 9977169 @putout/printer: improve support of IIFE
10
+
1
11
  2023.04.11, v1.37.0
2
12
 
3
13
  feature:
@@ -1,9 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  const CallExpression = {
4
- print(path, {indent, print, maybe}) {
4
+ print(path, {indent, print, maybe, traverse}) {
5
5
  const isParentCall = toLong(path) && path.parentPath.isCallExpression();
6
- print('__callee');
6
+ const callee = path.get('callee');
7
+ const isFn = callee.isFunction();
8
+
9
+ maybe.write(isFn, '(');
10
+ traverse(callee);
11
+ maybe.write(isFn, ')');
7
12
 
8
13
  if (path.node.optional)
9
14
  print('?.');
@@ -11,14 +11,14 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
11
11
  async,
12
12
  } = node;
13
13
 
14
- maybe.print(async, 'async ');
15
- print('function');
16
- maybe.print(generator, '*');
14
+ maybe.write(async, 'async ');
15
+ write('function');
16
+ maybe.write(generator, '*');
17
17
 
18
18
  const id = path.get('id');
19
- write.space();
20
19
 
21
20
  if (id.node) {
21
+ write.space();
22
22
  traverse(id);
23
23
  }
24
24
 
@@ -106,13 +106,13 @@ module.exports.FunctionDeclaration = (path, {print, maybe}) => {
106
106
  print('__body');
107
107
  };
108
108
 
109
- module.exports.ClassMethod = (path, {print}) => {
109
+ module.exports.ClassMethod = (path, {print, maybe}) => {
110
110
  const {kind} = path.node;
111
+ const notMethod = kind !== 'method';
112
+ const notConstructor = kind !== 'constructor';
111
113
 
112
- if (kind !== 'method')
113
- print(`${kind} `);
114
-
115
- print('__key');
114
+ maybe.print(notMethod, `${kind} `);
115
+ maybe.print(notConstructor, '__key');
116
116
  print('(');
117
117
 
118
118
  const params = path.get('params');
@@ -128,3 +128,4 @@ module.exports.ClassMethod = (path, {print}) => {
128
128
  print(') ');
129
129
  print('__body');
130
130
  };
131
+
@@ -1,7 +1,16 @@
1
1
  'use strict';
2
2
 
3
- module.exports.ExportDefaultDeclaration = (path, {print}) => {
4
- print('export default ');
5
- print('__declaration');
6
- print(';');
3
+ module.exports.ExportDefaultDeclaration = {
4
+ beforeIf(path) {
5
+ return path.getPrevSibling().isTSTypeAliasDeclaration();
6
+ },
7
+ before(path, {print}) {
8
+ print.breakline();
9
+ },
10
+ print(path, {print, traverse, maybe}) {
11
+ const declaration = path.get('declaration');
12
+ print('export default ');
13
+ traverse(declaration);
14
+ maybe.print(!declaration.isClassDeclaration(), ';');
15
+ },
7
16
  };
@@ -2,9 +2,11 @@
2
2
 
3
3
  const {exists} = require('../is');
4
4
  const {TSTypeLiteral} = require('./ts-type-literal');
5
+ const {TSTypeAliasDeclaration} = require('./ts-type-alias-declaration');
5
6
 
6
7
  module.exports = {
7
8
  TSTypeLiteral,
9
+ TSTypeAliasDeclaration,
8
10
  TSTypeParameterDeclaration(path, {print}) {
9
11
  print('<');
10
12
 
@@ -50,6 +52,16 @@ module.exports = {
50
52
  print.space();
51
53
  print('__typeAnnotation');
52
54
  },
55
+ TSQualifiedName(path, {print}) {
56
+ print('__left');
57
+ print('.');
58
+ print('__right');
59
+ },
60
+ TSParameterProperty(path, {write, print}) {
61
+ write(path.node.accessibility);
62
+ write.space();
63
+ print('__parameter');
64
+ },
53
65
  TSTypeAnnotation(path, {print}) {
54
66
  if (path.parentPath.isIdentifier()) {
55
67
  print(':');
@@ -62,15 +74,6 @@ module.exports = {
62
74
  print('__expression');
63
75
  print('__typeParameters');
64
76
  },
65
- TSTypeAliasDeclaration(path, {print}) {
66
- print('type ');
67
- print('__id');
68
- print.space();
69
- print('=');
70
- print.space();
71
- print('__typeAnnotation');
72
- print(';');
73
- },
74
77
  TSPropertySignature(path, {print, maybe, traverse}) {
75
78
  const {optional} = path.node;
76
79
  const typeAnnotation = path.get('typeAnnotation');
@@ -85,3 +88,4 @@ module.exports = {
85
88
  }
86
89
  },
87
90
  };
91
+
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const {isLast} = require('../is');
4
+ module.exports.TSTypeAliasDeclaration = {
5
+ print(path, {print}) {
6
+ print('type ');
7
+ print('__id');
8
+ print.space();
9
+ print('=');
10
+ print.space();
11
+ print('__typeAnnotation');
12
+ print(';');
13
+ },
14
+ afterIf(path) {
15
+ return !isLast(path);
16
+ },
17
+ after(path, {print}) {
18
+ print.newline();
19
+ },
20
+ };
21
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.37.0",
3
+ "version": "1.39.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",