@putout/printer 1.40.1 → 1.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,13 @@
1
+ 2023.04.13, v1.41.0
2
+
3
+ feature:
4
+ - 99adbd5 @putout/printer: add support of TSArrayType
5
+
6
+ 2023.04.13, v1.40.2
7
+
8
+ feature:
9
+ - 6d8d812 @putout/printer: comments: newline after CommentLine
10
+
1
11
  2023.04.13, v1.40.1
2
12
 
3
13
  fix:
@@ -45,7 +45,7 @@ module.exports.parseLeadingComments = (path, {print, maybe}) => {
45
45
  }
46
46
  };
47
47
 
48
- module.exports.parseTrailingComments = (path, {print}) => {
48
+ module.exports.parseTrailingComments = (path, {write, maybe}) => {
49
49
  const {trailingComments} = path.node;
50
50
 
51
51
  if (!trailingComments || !trailingComments.length)
@@ -54,10 +54,13 @@ module.exports.parseTrailingComments = (path, {print}) => {
54
54
  if (isNext(path))
55
55
  return;
56
56
 
57
- for (const {type, value} of trailingComments) {
57
+ for (const {type, value, loc} of trailingComments) {
58
58
  if (type === 'CommentLine') {
59
- print.space();
60
- print(`//${value}`);
59
+ const sameLine = isSameLine(path, loc);
60
+ maybe.write.space(sameLine);
61
+ maybe.indent(!sameLine);
62
+ write(`//${value}`);
63
+ maybe.write.newline(!sameLine);
61
64
 
62
65
  continue;
63
66
  }
@@ -67,3 +70,7 @@ module.exports.parseTrailingComments = (path, {print}) => {
67
70
  function shouldAddNewlineBefore(path) {
68
71
  return path.isStatement() && !isFirst(path) && !hasPrevNewline(path);
69
72
  }
73
+
74
+ function isSameLine(path, loc) {
75
+ return path.node.loc.start.line === loc.start.line;
76
+ }
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {hasPrevNewline} = require('../mark');
4
+ const {exists} = require('../is');
4
5
  const isFirst = (path) => !path.getPrevSibling().node;
5
6
 
6
7
  module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
@@ -40,7 +41,7 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
40
41
 
41
42
  module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
42
43
 
43
- function ArrowFunctionExpression(path, {print, maybe}) {
44
+ function ArrowFunctionExpression(path, {print, maybe, write, traverse}) {
44
45
  const {async} = path.node;
45
46
  maybe.print(async, 'async ');
46
47
  print('(');
@@ -55,7 +56,18 @@ function ArrowFunctionExpression(path, {print, maybe}) {
55
56
  print(', ');
56
57
  }
57
58
 
58
- print(') => ');
59
+ print(')');
60
+ const returnType = path.get('returnType');
61
+
62
+ if (exists(returnType)) {
63
+ write(':');
64
+ write.space();
65
+ traverse(returnType);
66
+ }
67
+
68
+ print.space();
69
+ print('=>');
70
+ print.space();
59
71
  print('__body');
60
72
  }
61
73
  module.exports.ObjectMethod = (path, {print}) => {
@@ -128,3 +140,4 @@ module.exports.ClassMethod = (path, {print, maybe}) => {
128
140
  print(') ');
129
141
  print('__body');
130
142
  };
143
+
@@ -27,6 +27,11 @@ module.exports = {
27
27
  },
28
28
  TSTypeReference(path, {print}) {
29
29
  print('__typeName');
30
+ print('__typeParameters');
31
+ },
32
+ TSArrayType(path, {print}) {
33
+ print('__elementType');
34
+ print('[]');
30
35
  },
31
36
  TSTypeParameter(path, {write}) {
32
37
  write(path.node.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.40.1",
3
+ "version": "1.41.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",