@putout/printer 1.79.0 → 1.80.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.05.03, v1.80.0
2
+
3
+ feature:
4
+ - e6111ae @putout/printer: improve support of NumericLiteral, SequenceExpression
5
+
6
+ 2023.05.02, v1.79.1
7
+
8
+ fix:
9
+ - 1d1af3a @putout/printer: chaining
10
+
1
11
  2023.05.02, v1.79.0
2
12
 
3
13
  feature:
@@ -4,9 +4,11 @@ const {
4
4
  isUnaryExpression,
5
5
  isArrowFunctionExpression,
6
6
  isLogicalExpression,
7
+ isIfStatement,
7
8
  } = require('@babel/types');
8
9
 
9
10
  const {chain} = require('./chain');
11
+ const {satisfy} = require('../../is');
10
12
 
11
13
  module.exports.MemberExpression = (path, {print, maybe, traverse}) => {
12
14
  const {computed} = path.node;
@@ -56,16 +58,17 @@ module.exports.OptionalMemberExpression = (path, {print}) => {
56
58
 
57
59
  const isCall = (a) => a.type === 'CallExpression';
58
60
 
61
+ const isExcludedFromChain = satisfy([
62
+ isUnaryExpression,
63
+ isArrowFunctionExpression,
64
+ isLogicalExpression,
65
+ isIfStatement,
66
+ ]);
67
+
59
68
  function likeChain(path) {
60
69
  const [root, properties] = chain(path);
61
70
 
62
- if (isUnaryExpression(root))
63
- return false;
64
-
65
- if (isArrowFunctionExpression(root))
66
- return false;
67
-
68
- if (isLogicalExpression(root))
71
+ if (isExcludedFromChain(root))
69
72
  return false;
70
73
 
71
74
  const calls = properties.filter(isCall);
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {isIdentifier} = require('@babel/types');
4
+
4
5
  const {
5
6
  isForOf,
6
7
  isCoupleLines,
@@ -3,10 +3,15 @@
3
3
  module.exports.SequenceExpression = (path, {maybe, print}) => {
4
4
  const expressions = path.get('expressions');
5
5
  const n = expressions.length - 1;
6
+ const insideArrow = path.parentPath.isArrowFunctionExpression();
7
+
8
+ maybe.print(insideArrow, '(');
6
9
 
7
10
  for (const [index, expression] of expressions.entries()) {
8
11
  print(expression);
9
12
  maybe.print(index < n, ',');
10
13
  maybe.print(index < n, ' ');
11
14
  }
15
+
16
+ maybe.print(insideArrow, ')');
12
17
  };
@@ -11,9 +11,10 @@ module.exports = {
11
11
  const {
12
12
  raw,
13
13
  extra,
14
+ value,
14
15
  } = path.node;
15
16
 
16
- write(raw || extra.raw);
17
+ write(raw || extra?.raw || value);
17
18
  },
18
19
  BooleanLiteral(path, {write}) {
19
20
  write(path.node.value);
@@ -8,9 +8,7 @@ module.exports.ForInStatement = (path, {print}) => {
8
8
  print('__right');
9
9
  print(')');
10
10
 
11
- if (path
12
- .get('body')
13
- .isBlockStatement())
11
+ if (path.get('body').isBlockStatement())
14
12
  print.space();
15
13
 
16
14
  print('__body');
@@ -86,9 +86,7 @@ module.exports.ImportDeclaration = {
86
86
  if (isLast(path))
87
87
  return false;
88
88
 
89
- if (path
90
- .getNextSibling()
91
- .isImportDeclaration())
89
+ if (path.getNextSibling().isImportDeclaration())
92
90
  return false;
93
91
 
94
92
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.79.0",
3
+ "version": "1.80.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 fro 🐊Putout",
@@ -50,6 +50,7 @@
50
50
  "@putout/test": "^6.0.1",
51
51
  "acorn": "^8.8.2",
52
52
  "c8": "^7.5.0",
53
+ "escover": "^2.5.3",
53
54
  "eslint": "^8.0.1",
54
55
  "eslint-plugin-n": "^15.2.4",
55
56
  "eslint-plugin-putout": "^17.0.0",