@putout/printer 3.6.0 → 3.7.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,11 @@
1
+ 2023.08.31, v3.7.0
2
+
3
+ feature:
4
+ - 427e14f package: @putout/plugin-minify v4.0.0
5
+ - f3a6959 package: @putout/plugin-promises v12.0.0
6
+ - 52c04e4 package: @putout/plugin-printer v2.0.0
7
+ - 1c7171d @putout/printer: VariableDeclaration inside TSModuleDeclaration
8
+
1
9
  2023.08.11, v3.6.0
2
10
 
3
11
  feature:
@@ -15,8 +15,9 @@ const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
15
15
  const {isConcatenation} = require('../../expressions/binary-expression/concatanate');
16
16
  const {parseLeadingComments} = require('../../comment/comment');
17
17
 
18
+ const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
18
19
  const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
19
- const isInsideBlock = (path) => /^(Program|BlockStatement)$/.test(path.parentPath.type);
20
+ const isInsideBlock = (path) => /^(Program|BlockStatement|TSModuleBlock)$/.test(path.parentPath.type);
20
21
  const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
21
22
  const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
22
23
 
@@ -47,7 +48,7 @@ module.exports.VariableDeclaration = {
47
48
  for (const [index, declaration] of declarations.entries()) {
48
49
  const id = declaration.get('id');
49
50
  const init = declaration.get('init');
50
- const notLast = index < n;
51
+ const isLast = index === n;
51
52
 
52
53
  traverse(id);
53
54
 
@@ -58,7 +59,7 @@ module.exports.VariableDeclaration = {
58
59
  traverse(init);
59
60
  }
60
61
 
61
- if (notLast) {
62
+ if (!isLast) {
62
63
  const next = declarations[index + 1];
63
64
 
64
65
  write(',');
@@ -74,7 +75,9 @@ module.exports.VariableDeclaration = {
74
75
  }
75
76
 
76
77
  maybe.indent.dec(n);
77
- maybe.write(isParentBlock(path) || isParentSwitchCase(path), ';');
78
+
79
+ if (isParentBlock(path) || isParentSwitchCase(path) || isParentTSModuleBlock(path))
80
+ write(';');
78
81
 
79
82
  let wasNewline = false;
80
83
 
@@ -100,11 +103,12 @@ module.exports.VariableDeclaration = {
100
103
  notLastPrevVarNotNextVar,
101
104
  isNewlineBetweenSiblings,
102
105
  notLastParentExport,
106
+ isParentTSModuleBlock,
103
107
  ],
104
108
  after(path, {maybe, store}) {
105
109
  const wasNewline = store();
106
110
 
107
- if (isLast(path.parentPath) && !path.parentPath.isBlockStatement())
111
+ if (isLast(path.parentPath) && !path.parentPath.isBlockStatement() || !isParentBlock(path) && !isParentTSModuleBlock(path))
108
112
  return false;
109
113
 
110
114
  maybe.print.linebreak(wasNewline);
@@ -234,4 +234,3 @@ module.exports = {
234
234
  print('this');
235
235
  },
236
236
  };
237
-
@@ -3,8 +3,11 @@
3
3
  const {isNext} = require('../is');
4
4
 
5
5
  module.exports.TSModuleDeclaration = {
6
- print(path, {print}) {
7
- print('declare namespace ');
6
+ print(path, {print, maybe}) {
7
+ const {declare} = path.node;
8
+ maybe.print(declare, 'declare ');
9
+
10
+ print('namespace ');
8
11
  print('__id');
9
12
  print.space();
10
13
  print('__body');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "3.6.0",
3
+ "version": "3.7.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",
@@ -48,9 +48,9 @@
48
48
  ],
49
49
  "devDependencies": {
50
50
  "@babel/plugin-codemod-object-assign-to-object-spread": "^7.10.4",
51
- "@putout/plugin-minify": "^2.4.0",
52
- "@putout/plugin-printer": "^1.0.0",
53
- "@putout/plugin-promises": "^11.0.0",
51
+ "@putout/plugin-minify": "^4.0.0",
52
+ "@putout/plugin-printer": "^2.0.0",
53
+ "@putout/plugin-promises": "^12.0.0",
54
54
  "@putout/plugin-react-hook-form": "^3.4.1",
55
55
  "@putout/plugin-react-hooks": "^5.0.0",
56
56
  "acorn": "^8.8.2",