@putout/printer 2.41.0 → 2.42.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,13 @@
1
+ 2023.07.03, v2.42.1
2
+
3
+ feature:
4
+ - cd274b2 @putout/printer: BinaryExpression: spaces: in (coderaiser/minify#109)
5
+
6
+ 2023.06.22, v2.42.0
7
+
8
+ feature:
9
+ - ae2311d @putout/printer: Decorator: add
10
+
1
11
  2023.06.22, v2.41.0
2
12
 
3
13
  feature:
@@ -30,6 +30,14 @@ const BinaryExpression = {
30
30
  return;
31
31
  }
32
32
 
33
+ if (operator === 'in') {
34
+ print('__left');
35
+ print(' in ');
36
+ print('__right');
37
+
38
+ return;
39
+ }
40
+
33
41
  if (isConcatenation(path))
34
42
  return concatanate(path, {
35
43
  print,
@@ -2,6 +2,7 @@
2
2
 
3
3
  const {isNext} = require('../is');
4
4
  const {markAfter} = require('../mark');
5
+ const {maybeDecorators} = require('../maybe-get');
5
6
 
6
7
  module.exports.ClassExpression = classVisitor;
7
8
  module.exports.ClassDeclaration = classVisitor;
@@ -20,13 +21,14 @@ module.exports.StaticBlock = (path, {print, traverse}) => {
20
21
  print.newline();
21
22
  };
22
23
 
23
- module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => {
24
+ module.exports.ClassDeclaration = (path, {print, indent, maybe, write, traverse}) => {
24
25
  indent();
25
26
 
26
27
  classVisitor(path, {
27
28
  print,
28
29
  indent,
29
30
  maybe,
31
+ traverse,
30
32
  });
31
33
 
32
34
  if (!path.parentPath.isExportDeclaration() && isNext(path)) {
@@ -36,7 +38,12 @@ module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => {
36
38
  }
37
39
  };
38
40
 
39
- function classVisitor(path, {print, indent, maybe}) {
41
+ function classVisitor(path, {print, indent, maybe, traverse}) {
42
+ for (const decorator of maybeDecorators(path)) {
43
+ traverse(decorator);
44
+ print.breakline();
45
+ }
46
+
40
47
  print('class ');
41
48
  print('__id');
42
49
  print('__typeParameters');
@@ -64,7 +71,7 @@ function classVisitor(path, {print, indent, maybe}) {
64
71
 
65
72
  for (const item of body) {
66
73
  indent();
67
- print(item);
74
+ traverse(item);
68
75
  }
69
76
 
70
77
  indent.dec();
@@ -40,4 +40,3 @@ const ClassMethod = {
40
40
 
41
41
  module.exports.ClassPrivateMethod = ClassMethod;
42
42
  module.exports.ClassMethod = ClassMethod;
43
-
@@ -32,4 +32,3 @@ module.exports.FunctionDeclaration = {
32
32
  markAfter(path);
33
33
  },
34
34
  };
35
-
@@ -41,4 +41,3 @@ module.exports.ObjectMethod = {
41
41
  print.linebreak();
42
42
  },
43
43
  };
44
-
@@ -48,4 +48,3 @@ function isOneArgArrow(path) {
48
48
 
49
49
  return param.type === 'Identifier';
50
50
  }
51
-
@@ -1,19 +1,51 @@
1
1
  'use strict';
2
2
 
3
- module.exports.NewExpression = (path, {print, maybe}) => {
4
- print('new ');
5
- print('__callee');
6
- print('__typeParameters');
7
-
8
- const args = path.get('arguments');
9
- print('(');
10
-
11
- const n = args.length - 1;
12
-
13
- for (const [i, arg] of args.entries()) {
14
- print(arg);
15
- maybe.print(i < n, ', ');
16
- }
3
+ const {exists} = require('../is');
4
+ const isInsideExpressionStatement = ({parentPath}) => parentPath.isExpressionStatement();
5
+ const notFirst = ({parentPath}) => exists(parentPath.getPrevSibling());
6
+
7
+ const getPrev = ({parentPath}) => {
8
+ const prev = parentPath.getPrevSibling();
17
9
 
18
- print(')');
10
+ return [
11
+ prev.node,
12
+ prev,
13
+ ];
14
+ };
15
+
16
+ module.exports.NewExpression = {
17
+ beforeIf(path) {
18
+ if (!isInsideExpressionStatement(path))
19
+ return false;
20
+
21
+ const [exists, prev] = getPrev(path);
22
+
23
+ if (!exists)
24
+ return false;
25
+
26
+ if (prev.isExpressionStatement())
27
+ return false;
28
+
29
+ return notFirst(path);
30
+ },
31
+ before(path, {print}) {
32
+ print.breakline();
33
+ },
34
+ print(path, {print, maybe}) {
35
+ print('new ');
36
+ print('__callee');
37
+ print('__typeParameters');
38
+
39
+ const args = path.get('arguments');
40
+ print('(');
41
+
42
+ const n = args.length - 1;
43
+
44
+ for (const [i, arg] of args.entries()) {
45
+ print(arg);
46
+ maybe.print(i < n, ', ');
47
+ }
48
+
49
+ print(')');
50
+ },
19
51
  };
@@ -1,12 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {TemplateLiteral} = require('./template-literal');
4
- const maybeDecorators = (path) => {
5
- if (!path.node.decorators)
6
- return [];
7
-
8
- return path.get('decorators');
9
- };
4
+ const {maybeDecorators} = require('../maybe-get');
10
5
 
11
6
  module.exports = {
12
7
  TemplateLiteral,
@@ -16,7 +11,6 @@ module.exports = {
16
11
  Decorator(path, {print}) {
17
12
  print('@');
18
13
  print('__expression');
19
- print(' ');
20
14
  },
21
15
  NumericLiteral(path, {write}) {
22
16
  const {
@@ -35,7 +29,7 @@ module.exports = {
35
29
 
36
30
  write(raw || `'${value}'`);
37
31
  },
38
- Identifier(path, {write, maybe, traverse}) {
32
+ Identifier(path, {write, maybe, traverse, print}) {
39
33
  const {node} = path;
40
34
  const {name, optional} = node;
41
35
  const parenthesized = node.extra?.parenthesized;
@@ -44,6 +38,7 @@ module.exports = {
44
38
  maybe.write(parenthesized, '(');
45
39
  for (const decorator of maybeDecorators(path)) {
46
40
  traverse(decorator);
41
+ print(' ');
47
42
  }
48
43
 
49
44
  write(name);
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports.maybeDecorators = (path) => {
4
+ if (!path.node.decorators)
5
+ return [];
6
+
7
+ return path.get('decorators');
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.41.0",
3
+ "version": "2.42.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",