@putout/printer 1.147.0 → 1.148.1

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,16 @@
1
+ 2023.06.08, v1.148.1
2
+
3
+ feature:
4
+ - fe4b8f0 @putout/printer: ArrayExpression: plugins
5
+
6
+ 2023.06.08, v1.148.0
7
+
8
+ fix:
9
+ - 26795a8 @putout/printer: BinaryExpression: Strings
10
+
11
+ feature:
12
+ - 55cb78d @putout/printer: ArrayExpression: plugins
13
+
1
14
  2023.06.08, v1.146.0
2
15
 
3
16
  feature:
@@ -11,6 +11,7 @@ const {
11
11
  isBooleanLiteral,
12
12
  isNullLiteral,
13
13
  isObjectExpression,
14
+ isAwaitExpression,
14
15
  } = require('@babel/types');
15
16
 
16
17
  const {isSimple} = require('@putout/operate');
@@ -24,11 +25,26 @@ const {
24
25
 
25
26
  const isForOf = ({parentPath}) => parentPath.isForOfStatement();
26
27
 
27
- const isStringAndArray = ([a, b]) => isStringLiteral(a) && isArrayExpression(b);
28
+ const isStringAndArray = ([a, b]) => {
29
+ if (!isStringLiteral(a))
30
+ return false;
31
+
32
+ if (!isArrayExpression(b))
33
+ return false;
34
+
35
+ return !isStringAndIdentifier(b.node.elements);
36
+ };
28
37
  const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
29
38
  const isIdentifierAndIdentifier = ([a, b]) => isIdentifier(a) && isIdentifier(b);
30
39
  const isInsideArray = (path) => path.parentPath.isArrayExpression();
31
- const isSimpleAndCall = ([a, b]) => isSimple(a) && isCallExpression(b);
40
+
41
+ const isSimpleAndCall = ([a, b]) => {
42
+ if (!isSimple(a))
43
+ return;
44
+
45
+ return isCallExpression(b) || isAwaitExpression(b);
46
+ };
47
+
32
48
  const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
33
49
  const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
34
50
  const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
@@ -6,8 +6,6 @@ const {
6
6
  isBinaryExpression,
7
7
  } = require('@babel/types');
8
8
 
9
- const isBinary = (a) => isBinaryExpression(a);
10
-
11
9
  const isStringLike = (a) => {
12
10
  if (isStringLiteral(a))
13
11
  return true;
@@ -20,23 +18,24 @@ const isStringLike = (a) => {
20
18
 
21
19
  module.exports.isConcatenation = (path) => {
22
20
  const {parentPath} = path;
21
+ const {operator} = path.node;
23
22
 
24
- const {
25
- operator,
26
- left,
27
- right,
28
- } = path.node;
23
+ const startLine = path.node.loc?.start.line;
24
+ const endLine = path.node.loc?.end.line;
29
25
 
30
- if (operator !== '+')
26
+ if (startLine === endLine)
31
27
  return false;
32
28
 
33
- if (isStringLike(left) && isStringLike(right) && isBinary(parentPath))
34
- return true;
29
+ const left = path.get('left');
30
+ const right = path.get('right');
35
31
 
36
- if (isBinary(left) && isStringLike(right))
32
+ if (operator !== '+')
33
+ return false;
34
+
35
+ if (isStringLike(left) && isStringLike(right) && isBinaryExpression(parentPath))
37
36
  return true;
38
37
 
39
- return false;
38
+ return isBinaryExpression(left) && isStringLike(right);
40
39
  };
41
40
 
42
41
  module.exports.concatanate = (path, {print, indent}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.147.0",
3
+ "version": "1.148.1",
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",