@putout/printer 1.92.4 → 1.94.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.11, v1.94.0
2
+
3
+ feature:
4
+ - 2df6b15 @putout/printer: improve support of newline in TSInterfaceDeclaration
5
+
6
+ 2023.05.11, v1.93.0
7
+
8
+ feature:
9
+ - 9822d55 @putout/printer: improve support computed property of ObjectPattern
10
+
1
11
  2023.05.11, v1.92.4
2
12
 
3
13
  feature:
@@ -8,55 +8,74 @@ const {
8
8
  exists,
9
9
  } = require('../is');
10
10
 
11
- module.exports.ObjectPattern = (path, {indent, print, maybe}) => {
12
- indent.inc();
13
- print('{');
14
-
15
- const properties = path.get('properties');
16
- const n = properties.length - 1;
17
- const is = shouldAddNewline(path);
18
-
19
- maybe.print(is, '\n');
20
-
21
- for (const [i, property] of properties.entries()) {
22
- if (property.isRestElement()) {
23
- print(property);
24
- continue;
25
- }
11
+ const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties.length === 1;
12
+
13
+ module.exports.ObjectPattern = {
14
+ print(path, {indent, print, maybe}) {
15
+ indent.inc();
16
+ print('{');
26
17
 
27
- const valuePath = property.get('value');
28
- const keyPath = property.get('key');
29
- const isAssign = valuePath.isAssignmentPattern();
30
- const {shorthand} = property.node;
31
- const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling());
18
+ const properties = path.get('properties');
19
+ const n = properties.length - 1;
20
+ const is = shouldAddNewline(path);
32
21
 
33
- maybe.indent(is);
34
- maybe.print.breakline(couple);
35
- print(keyPath);
22
+ maybe.print(is, '\n');
36
23
 
37
- if (!shorthand) {
38
- print(': ');
39
- print(valuePath);
40
- } else if (isAssign) {
41
- print(valuePath);
24
+ for (const [i, property] of properties.entries()) {
25
+ if (property.isRestElement()) {
26
+ print(property);
27
+ continue;
28
+ }
42
29
 
43
- maybe.print(couple, ',');
44
- maybe.print.newline(couple);
45
- }
46
-
47
- if (is) {
48
- print(',');
49
- print.newline();
30
+ const valuePath = property.get('value');
31
+ const keyPath = property.get('key');
32
+ const isAssign = valuePath.isAssignmentPattern();
33
+ const {
34
+ shorthand,
35
+ computed,
36
+ } = property.node;
37
+ const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling());
50
38
 
51
- continue;
39
+ maybe.indent(is);
40
+ maybe.print.breakline(couple);
41
+
42
+ maybe.print(computed, '[');
43
+ print(keyPath);
44
+ maybe.print(computed, ']');
45
+
46
+ if (!shorthand) {
47
+ print(': ');
48
+ print(valuePath);
49
+ } else if (isAssign) {
50
+ print(valuePath);
51
+
52
+ maybe.print(couple, ',');
53
+ maybe.print.newline(couple);
54
+ }
55
+
56
+ if (is) {
57
+ print(',');
58
+ print.newline();
59
+
60
+ continue;
61
+ }
62
+
63
+ maybe.print(i < n, ', ');
52
64
  }
53
65
 
54
- maybe.print(i < n, ', ');
55
- }
56
-
57
- indent.dec();
58
- maybe.indent(is);
59
- print('}');
66
+ indent.dec();
67
+ maybe.indent(is);
68
+ print('}');
69
+ },
70
+ afterIf(path) {
71
+ if (!path.parentPath.isObjectProperty())
72
+ return false;
73
+
74
+ return isOneParentProperty(path);
75
+ },
76
+ after(path, {print}) {
77
+ print.newline();
78
+ },
60
79
  };
61
80
 
62
81
  function checkLength(properties) {
@@ -12,6 +12,7 @@ const {
12
12
  TSModuleDeclaration,
13
13
  TSModuleBlock,
14
14
  } = require('./ts-module-declaration');
15
+ const {TSInterfaceDeclaration} = require('./ts-interface-declaration');
15
16
 
16
17
  module.exports = {
17
18
  TSTypeLiteral,
@@ -84,11 +85,7 @@ module.exports = {
84
85
  write(`${operator} `);
85
86
  print('__typeAnnotation');
86
87
  },
87
- TSInterfaceDeclaration(path, {print}) {
88
- print('interface ');
89
- print('__id');
90
- print('__body');
91
- },
88
+ TSInterfaceDeclaration,
92
89
  TSInterfaceBody(path, {traverse, write, indent}) {
93
90
  write(' {');
94
91
  write.newline();
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ module.exports.TSInterfaceDeclaration = (path, {print}) => {
4
+ print('interface ');
5
+ print('__id');
6
+ print('__body');
7
+
8
+ print.breakline();
9
+ print.breakline();
10
+ };
11
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.92.4",
3
+ "version": "1.94.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",