@putout/printer 2.7.0 → 2.9.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.06.13, v2.9.0
2
+
3
+ feature:
4
+ - edfd3fa @putout/printer: literals: add support of braces round Identifier
5
+
6
+ 2023.06.13, v2.8.0
7
+
8
+ feature:
9
+ - 93b580e @putout/printer: improve node support
10
+
1
11
  2023.06.13, v2.7.0
2
12
 
3
13
  feature:
@@ -3,4 +3,3 @@
3
3
  module.exports.wrongShorthand = ({computed, isAssign, keyPath, valuePath}) => {
4
4
  return !computed && !isAssign && keyPath.node.name !== valuePath.node.name;
5
5
  };
6
-
@@ -28,14 +28,19 @@ module.exports = {
28
28
  write(raw || `'${value}'`);
29
29
  },
30
30
  Identifier(path, {write, print, maybe}) {
31
+ const {node} = path;
32
+ const parenthesized = node.extra?.parenthesized;
33
+
31
34
  const {
32
35
  name,
33
36
  optional,
34
- } = path.node;
37
+ } = node;
35
38
 
39
+ maybe.write(parenthesized, '(');
36
40
  write(name);
37
41
  maybe.write(optional, '?');
38
42
  print('__typeAnnotation');
43
+ maybe.write(parenthesized, ')');
39
44
  },
40
45
  RegExpLiteral(path, {print}) {
41
46
  print(path.node.raw);
@@ -9,6 +9,7 @@ const {
9
9
  File,
10
10
  ExpressionStatement,
11
11
  Program,
12
+ isStatement,
12
13
  } = require('@babel/types');
13
14
 
14
15
  const isFn = (a) => typeof a === 'function';
@@ -23,8 +24,10 @@ module.exports.maybeThrow = (a, path, b) => {
23
24
  }));
24
25
  };
25
26
 
27
+ const maybeStatement = (ast) => isStatement(ast) ? ast : ExpressionStatement(ast);
28
+
26
29
  const maybeProgram = (ast) => isProgram(ast) ? ast : Program([
27
- ExpressionStatement(ast),
30
+ maybeStatement(ast),
28
31
  ]);
29
32
 
30
33
  module.exports.maybeFile = (ast) => isFile(ast) ? ast : File(maybeProgram(ast));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.7.0",
3
+ "version": "2.9.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",