@putout/printer 1.87.0 → 1.89.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,16 @@
1
+ 2023.05.09, v1.89.0
2
+
3
+ fix:
4
+ - 17bae21 @putout/printer: rm useless condition
5
+
6
+ feature:
7
+ - bf25bda @putout/printer: ForOfStatement: newline
8
+
9
+ 2023.05.09, v1.88.0
10
+
11
+ feature:
12
+ - 64aa4a3 @putout/printer: add support of TSModuleDeclaration
13
+
1
14
  2023.05.09, v1.87.0
2
15
 
3
16
  feature:
@@ -71,4 +71,3 @@ function classVisitor(path, {print, indent, maybe}) {
71
71
  indent();
72
72
  print('}');
73
73
  }
74
-
@@ -27,7 +27,7 @@ module.exports.BlockStatement = {
27
27
  indent.inc();
28
28
  print('{');
29
29
 
30
- if (body.length > 1 || isFirstStatement(path))
30
+ if (isFirstStatement(path))
31
31
  print.newline();
32
32
 
33
33
  for (const element of body) {
@@ -36,6 +36,7 @@ module.exports.ExportNamedDeclaration = {
36
36
  const {exportKind} = path.node;
37
37
  const specifiers = path.get('specifiers');
38
38
 
39
+ indent();
39
40
  write('export ');
40
41
 
41
42
  if (exportKind === 'type' && specifiers.length) {
@@ -10,6 +10,7 @@ const {
10
10
  const {
11
11
  isFirst,
12
12
  isNext,
13
+ isLast,
13
14
  } = require('../is');
14
15
 
15
16
  module.exports.ForOfStatement = {
@@ -34,6 +35,9 @@ module.exports.ForOfStatement = {
34
35
  print(' ');
35
36
  print('__body');
36
37
 
38
+ const {length} = bodyPath.node.body;
39
+ maybe.print.newline(!length && !isLast(path) && !isNext(path));
40
+
37
41
  return;
38
42
  }
39
43
 
@@ -44,7 +48,12 @@ module.exports.ForOfStatement = {
44
48
 
45
49
  maybe.markAfter(isMarkedAfter(bodyPath), path);
46
50
  },
47
- afterIf: isNext,
51
+ afterIf: (path) => {
52
+ if (isNext(path))
53
+ return true;
54
+
55
+ return false;
56
+ },
48
57
  after(path, {print}) {
49
58
  print.linebreak();
50
59
  markAfter(path);
@@ -13,6 +13,7 @@ const {hasPrevNewline} = require('../mark');
13
13
  const {isExportDeclaration} = require('@babel/types');
14
14
 
15
15
  const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
16
+ const isInsideBlock = (path) => /^(Program|BlockStatement)$/.test(path.parentPath.type);
16
17
 
17
18
  module.exports.VariableDeclaration = {
18
19
  beforeIf: shouldAddNewlineBefore,
@@ -20,7 +21,7 @@ module.exports.VariableDeclaration = {
20
21
  print.breakline();
21
22
  },
22
23
  print(path, {maybe, store, write, traverse}) {
23
- maybe.indent(isParentBlock(path));
24
+ maybe.indent(isInsideBlock(path));
24
25
  write(`${path.node.kind} `);
25
26
 
26
27
  const declarations = path.get('declarations');
@@ -8,6 +8,11 @@ const {TSConditionalType} = require('./ts-conditional-type');
8
8
  const {TSTypeParameter} = require('./ts-type-parameter');
9
9
  const {TSDeclareFunction} = require('./ts-declare-function');
10
10
 
11
+ const {
12
+ TSModuleDeclaration,
13
+ TSModuleBlock,
14
+ } = require('./ts-module-declaration');
15
+
11
16
  module.exports = {
12
17
  TSTypeLiteral,
13
18
  TSTypeAliasDeclaration,
@@ -15,6 +20,12 @@ module.exports = {
15
20
  TSMappedType,
16
21
  TSConditionalType,
17
22
  TSDeclareFunction,
23
+ TSModuleDeclaration,
24
+ TSModuleBlock,
25
+ TSTypeQuery(path, {print}) {
26
+ print('typeof ');
27
+ print('__exprName');
28
+ },
18
29
  TSNeverKeyword(path, {write}) {
19
30
  write('never');
20
31
  },
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ module.exports.TSModuleBlock = (path, {print, traverse, indent}) => {
4
+ print('{');
5
+ print.breakline();
6
+ indent.inc();
7
+
8
+ for (const child of path.get('body'))
9
+ traverse(child);
10
+
11
+ indent.dec();
12
+ print('}');
13
+ };
14
+
15
+ module.exports.TSModuleDeclaration = (path, {print}) => {
16
+ print('declare namespace ');
17
+ print('__id');
18
+ print.space();
19
+ print('__body');
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.87.0",
3
+ "version": "1.89.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",