@putout/printer 8.35.2 → 8.37.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
+ 2024.05.21, v8.37.0
2
+
3
+ feature:
4
+ - 97bcc9e @putout/printer: VariableDeclaration: add support of LabeledStatement
5
+
6
+ 2024.05.19, v8.36.0
7
+
8
+ feature:
9
+ - 51eb249 @putout/printer: ReturnStatement inside IfStatement: improve support
10
+
1
11
  2024.05.16, v8.35.2
2
12
 
3
13
  fix:
@@ -6,7 +6,7 @@ const {IfStatement} = require('./if-statement/if-statement');
6
6
  const {ForOfStatement} = require('./for-of-statement/for-of-statement');
7
7
  const {BlockStatement} = require('./block-statement/block-statement');
8
8
  const {ReturnStatement} = require('./return-statement/return-statement');
9
- const TryStatements = require('./try-statements');
9
+ const TryStatements = require('./try-statement/try-statements');
10
10
  const {DebuggerStatement} = require('./debugger-statement');
11
11
  const {ForStatement} = require('./for-statement');
12
12
  const importDeclarations = require('./import-declaration/import-declaration');
@@ -13,6 +13,8 @@ const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
13
13
 
14
14
  const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
15
15
 
16
+ const isInsideIfWithElse = ({parentPath}) => parentPath.isIfStatement() && parentPath.node.alternate;
17
+
16
18
  module.exports.ReturnStatement = {
17
19
  beforeIf(path) {
18
20
  return !hasPrevNewline(path) && isBodyLength(path) || isPrevBody(path);
@@ -40,6 +42,9 @@ module.exports.ReturnStatement = {
40
42
  print(';');
41
43
  },
42
44
  afterIf: (path) => {
45
+ if (isInsideIfWithElse(path))
46
+ return true;
47
+
43
48
  if (isLast(path))
44
49
  return false;
45
50
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isNext} = require('../is');
3
+ const {isNext} = require('../../is');
4
4
 
5
5
  module.exports.TryStatement = {
6
6
  print(path, {print}) {
@@ -17,7 +17,7 @@ const {parseLeadingComments} = require('../../comment/comment');
17
17
  const {maybeDeclare} = require('../../maybe/maybe-declare');
18
18
 
19
19
  const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
20
- const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
20
+ const isParentBlock = (path) => /Program|BlockStatement|Export|LabeledStatement/.test(path.parentPath.type);
21
21
  const isInsideBlock = (path) => /^(Program|BlockStatement|TSModuleBlock|SwitchCase)$/.test(path.parentPath.type);
22
22
  const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
23
23
  const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.35.2",
3
+ "version": "8.37.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",