@putout/printer 15.12.0 → 15.14.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
+ 2025.07.26, v15.14.0
2
+
3
+ feature:
4
+ - b6adcd1 @putout/printer: types: namespace -> declare
5
+ - eb9c687 @putout/printer: TSModuleDeclaration: ClassDeclaration inside ExportNamedDeclaration
6
+
7
+ 2025.07.25, v15.13.0
8
+
9
+ feature:
10
+ - 8039e5d @putout/printer: TSModuleDeclaration: kind === global
11
+
1
12
  2025.07.19, v15.12.0
2
13
 
3
14
  feature:
package/lib/printer.d.ts CHANGED
@@ -22,16 +22,13 @@ type Print = (input: string | types.Node) => void;
22
22
  type Indent = () => void;
23
23
  type Traverse = (input: types.Node) => void;
24
24
 
25
+ type MaybeCondition = (condition: boolean) => void;
26
+
27
+ declare const MaybeIndent: {
28
+ inc: MaybeCondition;
29
+ dec: MaybeCondition;
30
+ };
25
31
  declare function MaybeIndent(condition: boolean): void;
26
- declare namespace MaybeIndent {
27
- type inc = (condition: boolean) => void;
28
- type dec = (condition: boolean) => void;
29
-
30
- export {
31
- inc,
32
- dec,
33
- };
34
- }
35
32
 
36
33
  type MaybePrint = (condition: boolean, input: string | types.Node) => void;
37
34
  type MaybeTraverse = (condition: boolean, input: types.Node) => void;
@@ -8,7 +8,16 @@ const {markAfter} = require('../../mark');
8
8
  const {maybeDeclare} = require('../../maybe/maybe-declare');
9
9
  const {parseComments} = require('../../comment/comment');
10
10
  const {maybeDecorators} = require('../../maybe/maybe-decorators');
11
- const {isFunction} = types;
11
+
12
+ const isInsideTSModuleBlock = (path) => {
13
+ return isTSModuleBlock(path.parentPath.parentPath);
14
+ };
15
+
16
+ const {
17
+ isFunction,
18
+ isTSModuleBlock,
19
+ } = types;
20
+
12
21
  const isInsideExport = ({parentPath}) => parentPath.isExportDeclaration();
13
22
  const isFunctionLike = (path) => isFunction(path.parentPath.parentPath);
14
23
  const hasBody = ({node}) => node.body.body.length;
@@ -72,18 +81,18 @@ module.exports.ClassExpression = classVisitor;
72
81
 
73
82
  module.exports.ClassDeclaration = {
74
83
  print: maybeDeclare((path, printer, semantics) => {
75
- const {indent} = printer;
76
- indent();
84
+ const {maybe} = printer;
85
+ maybe.indent(!isInsideExport(path));
77
86
  classVisitor(path, printer, semantics);
78
87
  }),
79
88
  afterIf(path) {
80
89
  if (isFunctionLike(path))
81
90
  return true;
82
91
 
83
- if (!isNext(path))
84
- return false;
92
+ if (isNext(path))
93
+ return true;
85
94
 
86
- return !isInsideExport(path);
95
+ return isInsideTSModuleBlock(path);
87
96
  },
88
97
  after(path, {write}) {
89
98
  write.newline();
@@ -39,4 +39,3 @@ function printAttributes(path, keyword, {write, traverse, indent}) {
39
39
  indent.dec();
40
40
  write('}');
41
41
  }
42
-
@@ -5,11 +5,12 @@ const {maybeDeclare} = require('../../maybe/maybe-declare');
5
5
 
6
6
  module.exports.TSModuleDeclaration = {
7
7
  print: maybeDeclare((path, {print}) => {
8
+ const {kind} = path.node;
8
9
  const id = path.get('id');
9
10
 
10
11
  if (id.isStringLiteral())
11
12
  print('module ');
12
- else
13
+ else if (kind === 'namespace')
13
14
  print('namespace ');
14
15
 
15
16
  print('__id');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.12.0",
3
+ "version": "15.14.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",