@putout/printer 10.10.0 → 11.0.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
+ 2024.12.10, v11.0.0
2
+
3
+ feature:
4
+ - b2a249c @putout/printer: overrides: roundBraces: new
5
+ - 179df4d @putout/printer: align to babel v8 (https://github.com/babel/babel/blob/main/.github/CHANGELOG-v8.md#v800-alpha14-2024-12-06)
6
+
7
+ 2024.12.04, v10.11.0
8
+
9
+ feature:
10
+ - 7ce10f9 @putout/printer: improve support of comments inside VariableDeclarator
11
+
1
12
  2024.12.02, v10.10.0
2
13
 
3
14
  feature:
package/README.md CHANGED
@@ -106,6 +106,7 @@ print(ast, {
106
106
  arrow: true,
107
107
  sequence: true,
108
108
  assign: false,
109
+ new: true,
109
110
  },
110
111
  },
111
112
  visitors: {
@@ -182,6 +183,7 @@ Options used to configure logic of output, similar to ESLint rules:
182
183
  - `arrow`: In a single argument arrow function expressions enabled: `(a) => {}`, disabled: `a => {}`;
183
184
  - `sequence`: In sequence expressions: enabled: `for(let e of l) (a(), b())`, disabled: `for(let e of l) a(), b()`;
184
185
  - `assign`: In assignment expressions: enabled: `(e.o=w(e.o)`, disabled: `e.o=w(e.o)`;
186
+ - `new`: In new expressions: enabled: `new Date()`, disabled: `new Date`;
185
187
 
186
188
  ## Visitors API
187
189
 
@@ -26,6 +26,13 @@ const isProperty = satisfy([
26
26
  isSpreadElement,
27
27
  ]);
28
28
 
29
+ const isInsideVar = ({parentPath}) => {
30
+ if (isVariableDeclarator(parentPath))
31
+ return true;
32
+
33
+ return isVariableDeclarator(parentPath.parentPath);
34
+ };
35
+
29
36
  const hasDecorators = (path) => {
30
37
  const {parentPath} = path;
31
38
 
@@ -79,7 +86,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
79
86
  if (!looksLikeSwitchCase && hasTrailingComment(path.getPrevSibling()))
80
87
  return;
81
88
 
82
- const insideFn = path.parentPath.isFunction();
89
+ const insideFn = path.parentPath.isFunction() && !path.isTSTypeParameterDeclaration();
83
90
 
84
91
  const propIs = isProperty(path);
85
92
  const isIndent = isFirst(path) || !looksLikeSwitchCase && !path.isClassMethod() && !insideFn && !propIs;
@@ -102,6 +109,13 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
102
109
 
103
110
  maybe.print.breakline(propIs);
104
111
  maybe.print.newline(!propIs);
112
+
113
+ if (isInsideVar(path)) {
114
+ indent.inc();
115
+ indent();
116
+ indent.dec();
117
+ }
118
+
105
119
  continue;
106
120
  }
107
121
 
@@ -38,7 +38,7 @@ const classVisitor = maybeDecorators((path, printer, semantics) => {
38
38
  maybe.print(id, ' ');
39
39
  print('extends ');
40
40
  print('__superClass');
41
- print('__superTypeParameters');
41
+ print('__superTypeArguments');
42
42
  }
43
43
 
44
44
  if (node.implements) {
@@ -14,7 +14,7 @@ const {
14
14
  OptionalCallExpression,
15
15
  } = require('./call-expression/call-expression');
16
16
 
17
- const {NewExpression} = require('./new-expression');
17
+ const {NewExpression} = require('./new-expression/new-expression');
18
18
 
19
19
  const {ObjectExpression} = require('./object-expression/object-expression');
20
20
  const {ObjectProperty} = require('./object-expression/object-property');
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const {exists} = require('../is');
4
- const {isMarkedAfter} = require('../mark');
3
+ const {exists} = require('../../is');
4
+ const {isMarkedAfter} = require('../../mark');
5
5
  const isInsideExpressionStatement = ({parentPath}) => parentPath.isExpressionStatement();
6
6
  const notFirst = ({parentPath}) => exists(parentPath.getPrevSibling());
7
7
 
@@ -35,13 +35,14 @@ module.exports.NewExpression = {
35
35
  before(path, {print}) {
36
36
  print.breakline();
37
37
  },
38
- print(path, {print, maybe}) {
38
+ print(path, printer, semantics) {
39
+ const {print, maybe} = printer;
39
40
  print('new ');
40
41
  print('__callee');
41
42
  print('__typeParameters');
42
43
 
43
44
  const args = path.get('arguments');
44
- print('(');
45
+ maybePrintOpenBrace(path, printer, semantics);
45
46
 
46
47
  const n = args.length - 1;
47
48
 
@@ -50,6 +51,24 @@ module.exports.NewExpression = {
50
51
  maybe.print(i < n, ', ');
51
52
  }
52
53
 
53
- print(')');
54
+ maybePrintCloseBrace(path, printer, semantics);
54
55
  },
55
56
  };
57
+
58
+ function maybePrintOpenBrace(path, printer, semantics) {
59
+ maybePrintBrace('(', path, printer, semantics);
60
+ }
61
+
62
+ function maybePrintCloseBrace(path, printer, semantics) {
63
+ maybePrintBrace(')', path, printer, semantics);
64
+ }
65
+
66
+ function maybePrintBrace(brace, path, printer, semantics) {
67
+ const {maybe, print} = printer;
68
+ const {roundBraces} = semantics;
69
+
70
+ if (path.node.arguments.length)
71
+ return print(brace);
72
+
73
+ maybe.print(roundBraces.new, brace);
74
+ }
@@ -7,18 +7,21 @@ const ROUND_BRACES_DEFAULTS = {
7
7
  arrow: true,
8
8
  sequence: true,
9
9
  assign: false,
10
+ new: true,
10
11
  };
11
12
 
12
13
  const ROUND_BRACES_ENABLED = {
13
14
  arrow: true,
14
15
  sequence: true,
15
16
  assign: true,
17
+ new: true,
16
18
  };
17
19
 
18
20
  const ROUND_BRACES_DISABLED = {
19
21
  arrow: false,
20
22
  sequence: false,
21
23
  assign: false,
24
+ new: false,
22
25
  };
23
26
 
24
27
  module.exports.parseRoundBraces = ({roundBraces}) => {
@@ -2,5 +2,5 @@
2
2
 
3
3
  module.exports.TSTypeReference = (path, {print}) => {
4
4
  print('__typeName');
5
- print('__typeParameters');
5
+ print('__typeArguments');
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "10.10.0",
3
+ "version": "11.0.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",