@putout/printer 1.81.0 → 1.81.2

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.05.04, v1.81.2
2
+
3
+ feature:
4
+ - 4033f37 @putout/printer: plugin: add satisfy
5
+
6
+ 2023.05.04, v1.81.1
7
+
8
+ feature:
9
+ - 12f7943 @putout/printer: improve comments support
10
+
1
11
  2023.05.04, v1.81.0
2
12
 
3
13
  feature:
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isNext} = require('./is');
3
+ const {hasTrailingComment} = require('./is');
4
4
 
5
5
  const {markBefore} = require('./mark');
6
6
 
@@ -10,7 +10,10 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, format) =>
10
10
 
11
11
  const {leadingComments} = path.node;
12
12
 
13
- if (!leadingComments || !leadingComments.length)
13
+ if (!leadingComments?.length)
14
+ return;
15
+
16
+ if (hasTrailingComment(path.getPrevSibling()))
14
17
  return;
15
18
 
16
19
  const insideFn = path.parentPath.isFunction();
@@ -54,10 +57,7 @@ module.exports.parseTrailingComments = (path, {write, maybe}, format) => {
54
57
 
55
58
  const {trailingComments} = path.node;
56
59
 
57
- if (!trailingComments || !trailingComments.length)
58
- return;
59
-
60
- if (isNext(path))
60
+ if (!trailingComments?.length)
61
61
  return;
62
62
 
63
63
  for (const {type, value, loc} of trailingComments) {
@@ -69,6 +69,12 @@ module.exports.parseTrailingComments = (path, {write, maybe}, format) => {
69
69
 
70
70
  write(`//${value}`);
71
71
  write.newline();
72
+ continue;
73
+ }
74
+
75
+ if (type === 'CommentBlock') {
76
+ write(`/*${value}*/`);
77
+ write.newline();
72
78
  }
73
79
  }
74
80
  };
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
+ const insideArrow = ({parentPath}) => parentPath.isArrowFunctionExpression();
4
+ const insideExport = ({parentPath}) => parentPath.isExportDeclaration();
5
+ const insideConst = ({parentPath}) => parentPath.isVariableDeclarator();
6
+
3
7
  module.exports.SequenceExpression = {
4
- condition({parentPath}) {
5
- if (parentPath.isArrowFunctionExpression())
6
- return true;
7
-
8
- if (parentPath.isExportDeclaration())
9
- return true;
10
-
11
- return false;
12
- },
8
+ satisfy: () => [
9
+ insideArrow,
10
+ insideExport,
11
+ insideConst,
12
+ ],
13
13
  before(path, {write}) {
14
14
  write('(');
15
15
  },
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isLast} = require('../is');
3
+ const {isLast, isNext} = require('../is');
4
4
 
5
5
  module.exports.UnaryExpression = unaryExpression;
6
6
  module.exports.UpdateExpression = unaryExpression;
@@ -26,6 +26,7 @@ module.exports.ThrowStatement = (path, {print, indent, maybe}) => {
26
26
 
27
27
  print(';');
28
28
  maybe.print.newline(!isLast(path));
29
+ maybe.print.breakline(isNext(path));
29
30
  };
30
31
 
31
32
  function printUnary(path, name, {print}) {
@@ -3,12 +3,18 @@
3
3
  const {satisfy} = require('../is');
4
4
 
5
5
  module.exports = (plugin) => {
6
- if (!plugin.afterSatisfy && !plugin.beforeSatisfy)
6
+ if (!plugin.afterSatisfy && !plugin.beforeSatisfy && !plugin.satisfy)
7
7
  return plugin;
8
8
 
9
+ const {
10
+ satisfy,
11
+ afterSatisfy = satisfy,
12
+ beforeSatisfy = satisfy,
13
+ } = plugin;
14
+
9
15
  return {
10
- afterIf: createIf(plugin.afterSatisfy),
11
- beforeIf: createIf(plugin.beforeSatisfy),
16
+ afterIf: createIf(afterSatisfy),
17
+ beforeIf: createIf(beforeSatisfy),
12
18
  ...plugin,
13
19
  };
14
20
  };
@@ -17,3 +23,4 @@ const createIf = (getConditions) => {
17
23
  const conditions = getConditions?.() || [];
18
24
  return satisfy(conditions);
19
25
  };
26
+
@@ -5,6 +5,7 @@ const {
5
5
  isCoupleLines,
6
6
  isNewlineBetweenSiblings,
7
7
  exists,
8
+ noTrailingComment,
8
9
  } = require('../is');
9
10
 
10
11
  const {hasPrevNewline} = require('../mark');
@@ -36,7 +37,7 @@ module.exports.VariableDeclaration = {
36
37
 
37
38
  let wasNewline = false;
38
39
 
39
- if (isParentBlock(path) && isNext(path)) {
40
+ if (isParentBlock(path) && isNext(path) && (noTrailingComment(path) || isNewlineBetweenSiblings(path))) {
40
41
  print.newline();
41
42
  wasNewline = true;
42
43
  }
@@ -136,4 +137,3 @@ const isNextAssign = (path) => {
136
137
  .get('expression')
137
138
  .isAssignmentExpression();
138
139
  };
139
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.81.0",
3
+ "version": "1.81.2",
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 fro 🐊Putout",