@putout/printer 5.43.0 → 6.0.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,14 @@
1
+ 2023.10.28, v6.0.0
2
+
3
+ feature:
4
+ - a739ffa package: eslint-plugin-putout v21.0.1
5
+ - 9c6dd07 @putout/printer: format: endOfFile
6
+
7
+ 2023.10.26, v5.44.0
8
+
9
+ feature:
10
+ - b9e05b0 @putout/printer: JSX: improve handling return with comment
11
+
1
12
  2023.10.25, v5.43.0
2
13
 
3
14
  feature:
package/README.md CHANGED
@@ -89,6 +89,7 @@ print(ast, {
89
89
  roundBraceOpen: '(',
90
90
  roundBraceClose: ')',
91
91
  quote: `'`,
92
+ endOfFile: '\n',
92
93
  },
93
94
  semantics: {
94
95
  comments: true,
@@ -124,6 +125,7 @@ const overrides = {
124
125
  splitter: '\n',
125
126
  roundBraceOpen: '(',
126
127
  roundBraceClose: ')',
128
+ endOfFile: '\n',
127
129
  },
128
130
  };
129
131
  ```
@@ -42,4 +42,3 @@ module.exports.JSXOpeningElement = {
42
42
  maybe.indent.dec(shouldIndent);
43
43
  },
44
44
  };
45
-
@@ -23,6 +23,7 @@ function initFormat(format) {
23
23
  roundBraceOpen: '(',
24
24
  roundBraceClose: ')',
25
25
  quote: `'`,
26
+ endOfFile: '\n',
26
27
  ...format,
27
28
  };
28
29
  }
@@ -6,27 +6,27 @@ const {getDirectives} = require('../block-statement/get-directives');
6
6
  module.exports.Program = (path, printer, semantics) => {
7
7
  const {body} = path.node;
8
8
  const {
9
- print,
10
9
  traverse,
11
10
  maybe,
11
+ write,
12
12
  } = printer;
13
13
 
14
- print('__interpreter');
14
+ traverse(path.get('interpreter'));
15
15
  parseComments(path, printer, semantics);
16
16
 
17
17
  const directives = getDirectives(path);
18
18
 
19
19
  for (const directive of directives) {
20
20
  traverse(directive);
21
- maybe.print.newline(body.length);
21
+ maybe.write.newline(body.length);
22
22
  }
23
23
 
24
24
  path
25
25
  .get('body')
26
- .forEach(print);
26
+ .forEach(traverse);
27
27
 
28
28
  if (directives.length && !body.length)
29
29
  return;
30
30
 
31
- print.newline();
31
+ write.endOfFile();
32
32
  };
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const {isJSXElement} = require('@putout/babel').types;
4
+
3
5
  const {
4
6
  isPrevBody,
5
7
  noTrailingComment,
@@ -24,6 +26,16 @@ module.exports.ReturnStatement = {
24
26
  maybeSpaceAfterKeyword(path, {
25
27
  print,
26
28
  });
29
+
30
+ if (isJSXWithComment(path)) {
31
+ print('(');
32
+ print.breakline();
33
+ print('__argument');
34
+ print(');');
35
+
36
+ return;
37
+ }
38
+
27
39
  print('__argument');
28
40
  print(';');
29
41
  },
@@ -37,3 +49,13 @@ module.exports.ReturnStatement = {
37
49
  print.newline();
38
50
  },
39
51
  };
52
+ function isJSXWithComment(path) {
53
+ const arg = path.node.argument;
54
+
55
+ if (!arg)
56
+ return;
57
+
58
+ const {leadingComments} = arg;
59
+
60
+ return isJSXElement(arg) && leadingComments?.length;
61
+ }
@@ -129,6 +129,13 @@ module.exports.tokenize = (ast, overrides) => {
129
129
  });
130
130
  };
131
131
 
132
+ const endOfFile = () => {
133
+ addToken({
134
+ type: TYPES.END_OF_FILE,
135
+ value: format.endOfFile,
136
+ });
137
+ };
138
+
132
139
  assign(write, {
133
140
  indent,
134
141
  newline,
@@ -137,6 +144,7 @@ module.exports.tokenize = (ast, overrides) => {
137
144
  space,
138
145
  splitter,
139
146
  quote,
147
+ endOfFile,
140
148
  });
141
149
 
142
150
  assign(maybeWrite, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "5.43.0",
3
+ "version": "6.0.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",
@@ -58,7 +58,7 @@
58
58
  "escover": "^3.0.0",
59
59
  "eslint": "^8.0.1",
60
60
  "eslint-plugin-n": "^16.0.0",
61
- "eslint-plugin-putout": "^20.0.0",
61
+ "eslint-plugin-putout": "^21.0.1",
62
62
  "estree-to-babel": "^8.0.0",
63
63
  "just-kebab-case": "^4.2.0",
64
64
  "madrun": "^9.0.0",