@putout/printer 5.32.0 → 5.34.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.10.24, v5.34.0
2
+
3
+ feature:
4
+ - 66a867a @putout/printer: comments: improve
5
+
6
+ 2023.10.24, v5.33.0
7
+
8
+ feature:
9
+ - 8bd4d6c @putout/printer: JSXText: raw
10
+
1
11
  2023.10.24, v5.32.0
2
12
 
3
13
  feature:
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
- module.exports.parseComments = (path, {write}, semantics) => {
3
+ const {isNext} = require('../is');
4
+
5
+ module.exports.parseComments = (path, {write, maybe}, semantics) => {
4
6
  if (!semantics.comments)
5
7
  return;
6
8
 
@@ -9,11 +11,20 @@ module.exports.parseComments = (path, {write}, semantics) => {
9
11
  if (!comments)
10
12
  return;
11
13
 
12
- for (const {type, value} of comments) {
14
+ const n = comments.length - 1;
15
+ const program = path.isProgram();
16
+
17
+ for (const [i, {type, value}] of comments.entries()) {
13
18
  if (type === 'CommentLine') {
14
- write.breakline();
19
+ maybe.write.breakline(isNext(path) || !program);
15
20
  write('//');
16
21
  write(value);
22
+
23
+ if (program) {
24
+ maybe.write.newline(i < n);
25
+ continue;
26
+ }
27
+
17
28
  write.newline();
18
29
  continue;
19
30
  }
@@ -31,8 +31,14 @@ const isMemberExpressionCallee = ({parentPath}) => {
31
31
  return likeChain(callee);
32
32
  };
33
33
 
34
- module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantics) => {
34
+ module.exports.ObjectExpression = (path, printer, semantics) => {
35
35
  const {trailingComma} = semantics;
36
+ const {
37
+ print,
38
+ maybe,
39
+ indent,
40
+ } = printer;
41
+
36
42
  indent.inc();
37
43
 
38
44
  const properties = path.get('properties');
@@ -42,7 +48,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantic
42
48
 
43
49
  maybe.print(parens, '(');
44
50
  print('{');
45
- parseComments(path, {write}, semantics);
51
+ parseComments(path, printer, semantics);
46
52
  maybe.print.newline(manyLines);
47
53
 
48
54
  const n = properties.length - 1;
@@ -21,6 +21,7 @@ module.exports.JSXElement = {
21
21
  path
22
22
  .get('children')
23
23
  .map(traverse);
24
+
24
25
  print('__closingElement');
25
26
 
26
27
  if (insideFn && insideCall) {
@@ -40,5 +41,8 @@ function condition(path) {
40
41
  if (path.parentPath.isReturnStatement())
41
42
  return true;
42
43
 
44
+ if (path.node.extra?.parenthesized)
45
+ return true;
46
+
43
47
  return path.parentPath.isVariableDeclarator();
44
48
  }
@@ -3,10 +3,14 @@
3
3
  const {isNext} = require('../is');
4
4
 
5
5
  module.exports.JSXText = (path, {write, indent}) => {
6
- const {value} = path.node;
6
+ const {node} = path;
7
+ const {value, extra} = node;
7
8
  const isSpacesOnly = /^\s+$/.test(value);
8
9
  const hasNext = isNext(path);
9
10
 
11
+ if (extra?.raw.startsWith('&'))
12
+ return write(extra.raw);
13
+
10
14
  if (isSpacesOnly && hasNext) {
11
15
  indent.inc();
12
16
  write.breakline();
@@ -17,7 +21,6 @@ module.exports.JSXText = (path, {write, indent}) => {
17
21
 
18
22
  if (isSpacesOnly) {
19
23
  write.breakline();
20
-
21
24
  return;
22
25
  }
23
26
 
@@ -29,7 +29,13 @@ const parentIfWithoutElse = ({parentPath}) => {
29
29
  };
30
30
 
31
31
  module.exports.BlockStatement = {
32
- print(path, {indent, maybe, write, traverse}, semantics) {
32
+ print(path, printer, semantics) {
33
+ const {
34
+ indent,
35
+ maybe,
36
+ write,
37
+ traverse,
38
+ } = printer;
33
39
  const body = path.get('body');
34
40
  const directives = getDirectives(path);
35
41
 
@@ -50,7 +56,7 @@ module.exports.BlockStatement = {
50
56
  traverse(element);
51
57
  }
52
58
 
53
- parseComments(path, {write}, semantics);
59
+ parseComments(path, printer, semantics);
54
60
 
55
61
  indent.dec();
56
62
  maybe.indent(body.length);
@@ -3,10 +3,16 @@
3
3
  const {parseComments} = require('../../comment/comment');
4
4
  const {getDirectives} = require('../block-statement/get-directives');
5
5
 
6
- module.exports.Program = (path, {print, write, traverse, maybe}, semantics) => {
6
+ module.exports.Program = (path, printer, semantics) => {
7
7
  const {body} = path.node;
8
+ const {
9
+ print,
10
+ traverse,
11
+ maybe,
12
+ } = printer;
13
+
8
14
  print('__interpreter');
9
- parseComments(path, {write}, semantics);
15
+ parseComments(path, printer, semantics);
10
16
 
11
17
  const directives = getDirectives(path);
12
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "5.32.0",
3
+ "version": "5.34.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",