@putout/printer 1.85.0 → 1.87.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,14 @@
1
+ 2023.05.09, v1.87.0
2
+
3
+ feature:
4
+ - 092bb3c @putout/printer: add support of StaticBlock
5
+ - 353a550 @putout/printer: improve support of SwitchStatement
6
+
7
+ 2023.05.09, v1.86.0
8
+
9
+ feature:
10
+ - d4e3b07 @putout/printer: ifStatement: space
11
+
1
12
  2023.05.08, v1.85.0
2
13
 
3
14
  feature:
@@ -6,6 +6,20 @@ const {markAfter} = require('../mark');
6
6
  module.exports.ClassExpression = classVisitor;
7
7
  module.exports.ClassDeclaration = classVisitor;
8
8
 
9
+ module.exports.StaticBlock = (path, {print, traverse}) => {
10
+ print('static ');
11
+ print('{');
12
+ print.breakline();
13
+
14
+ for (const child of path.get('body')) {
15
+ traverse(child);
16
+ }
17
+
18
+ print.indent();
19
+ print('}');
20
+ print.newline();
21
+ };
22
+
9
23
  module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => {
10
24
  indent();
11
25
 
@@ -57,3 +71,4 @@ function classVisitor(path, {print, indent, maybe}) {
57
71
  indent();
58
72
  print('}');
59
73
  }
74
+
@@ -7,6 +7,7 @@ const memberExpressions = require('./member-expressions/member-expressions');
7
7
  const {
8
8
  ClassExpression,
9
9
  ClassDeclaration,
10
+ StaticBlock,
10
11
  } = require('./class');
11
12
 
12
13
  const {
@@ -62,6 +63,7 @@ module.exports = {
62
63
  RestElement,
63
64
  SpreadElement,
64
65
  SequenceExpression,
66
+ StaticBlock,
65
67
  TaggedTemplateExpression,
66
68
  ThisExpression(path, {print}) {
67
69
  print('this');
@@ -37,7 +37,7 @@ function printUnary(path, name, {print}) {
37
37
  print('__argument');
38
38
  }
39
39
 
40
- const isWord = (a) => /delete|typeof|void/.test(a);
40
+ const isWord = (a) => /^(delete|typeof|void)$/.test(a);
41
41
 
42
42
  function unaryExpression(path, {maybe, traverse}) {
43
43
  const {
@@ -8,7 +8,9 @@ const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
8
8
  module.exports.IfStatement = {
9
9
  print: (path, {indent, print, maybe, write, traverse}) => {
10
10
  indent();
11
- print('if (');
11
+ print('if');
12
+ print.space();
13
+ print('(');
12
14
  print('__test');
13
15
  print(')');
14
16
 
@@ -1,11 +1,15 @@
1
1
  'use strict';
2
2
 
3
- const {isNext} = require('../is');
3
+ const {
4
+ isNext,
5
+ exists,
6
+ isLast,
7
+ } = require('../is');
4
8
 
5
9
  module.exports.SwitchStatement = {
6
- print(path, {print, maybe}) {
10
+ print(path, {print, maybe, indent, write, traverse}) {
11
+ indent();
7
12
  print('switch');
8
- print.space();
9
13
  print('(');
10
14
  print('__discriminant');
11
15
  print(') {');
@@ -15,9 +19,17 @@ module.exports.SwitchStatement = {
15
19
  const n = cases.length - 1;
16
20
 
17
21
  for (const [index, switchCase] of cases.entries()) {
18
- print('case');
19
- print.space();
20
- print(switchCase.get('test'));
22
+ const test = switchCase.get('test');
23
+
24
+ indent();
25
+
26
+ if (exists(test)) {
27
+ write('case ');
28
+ traverse(test);
29
+ } else {
30
+ write('default');
31
+ }
32
+
21
33
  print(':');
22
34
 
23
35
  const isBlock = switchCase
@@ -37,14 +49,15 @@ module.exports.SwitchStatement = {
37
49
  print(consequent);
38
50
  }
39
51
 
40
- if (index < n) {
41
- print.linebreak();
42
- }
43
-
44
52
  maybe.indent.dec(!isBlock);
53
+ maybe.write.linebreak(index < n);
45
54
  }
46
55
 
56
+ print.indent();
47
57
  print('}');
58
+
59
+ if (!isNext(path) && !isLast(path))
60
+ print.newline();
48
61
  },
49
62
  afterSatisfy: () => [
50
63
  isNext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.85.0",
3
+ "version": "1.87.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",