@putout/printer 2.9.0 → 2.11.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.11.0
2
+
3
+ feature:
4
+ - e7a9a98 @putout/printer: TSDeclare: add support of declare
5
+
6
+ 2023.06.13, v2.10.0
7
+
8
+ feature:
9
+ - b7dbe6c @putout/printer: improve support of nested IfStatement
10
+
1
11
  2023.06.13, v2.9.0
2
12
 
3
13
  feature:
@@ -5,15 +5,16 @@ const {
5
5
  isParentProgram,
6
6
  isLast,
7
7
  exists,
8
- } = require('../is');
8
+ } = require('../../is');
9
9
 
10
10
  const {
11
11
  isArrowFunctionExpression,
12
12
  isObjectMethod,
13
13
  } = require('@babel/types');
14
14
 
15
- const {markAfter} = require('../mark');
16
- const {parseComments} = require('../comments');
15
+ const {markAfter} = require('../../mark');
16
+ const {parseComments} = require('../../comments');
17
+ const {insideIfWithNoBody} = require('./inside-if-with-no-body');
17
18
 
18
19
  const isFirstStatement = (path) => path.get('body.0')?.isStatement();
19
20
  const isMethodOrArrow = (path) => isArrowFunctionExpression(path) || isObjectMethod(path);
@@ -63,6 +64,9 @@ function shouldAddNewlineAfter(path) {
63
64
  if (!isNext(path) && !isNext(path.parentPath) && isParentProgram(path.parentPath))
64
65
  return false;
65
66
 
67
+ if (insideIfWithNoBody(path))
68
+ return false;
69
+
66
70
  if (path.parentPath.isIfStatement() && path.find(isMethodOrArrow))
67
71
  return true;
68
72
 
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const {exists} = require('../../is');
4
+
5
+ module.exports.insideIfWithNoBody = (path) => {
6
+ if (!path.parentPath.isIfStatement())
7
+ return false;
8
+
9
+ if (!path.parentPath.parentPath.isIfStatement())
10
+ return false;
11
+
12
+ const next = path.parentPath?.parentPath.getNextSibling();
13
+
14
+ return !exists(next);
15
+ };
@@ -4,7 +4,7 @@ const {ExpressionStatement} = require('./expression-statement');
4
4
  const {VariableDeclaration} = require('./variable-declaration/variable-declaration');
5
5
  const {IfStatement} = require('./if-statement/if-statement');
6
6
  const {ForOfStatement} = require('./for-of-statement');
7
- const {BlockStatement} = require('./block-statement');
7
+ const {BlockStatement} = require('./block-statement/block-statement');
8
8
  const {ReturnStatement} = require('./return-statement/return-statement');
9
9
  const TryStatements = require('./try-statements');
10
10
  const {DebuggerStatement} = require('./debugger-statement');
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports.TSDeclareFunction = (path, {print, maybe}) => {
4
+ const {declare} = path.node;
5
+
6
+ maybe.print(declare, 'declare ');
4
7
  print('function ');
5
8
  print('__id');
6
9
  print('(');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.9.0",
3
+ "version": "2.11.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",