@putout/printer 11.6.0 → 11.8.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,15 @@
1
+ 2024.12.17, v11.8.0
2
+
3
+ feature:
4
+ - 0ed288d @putout/printer: LabeledStatement: nexted
5
+
6
+ 2024.12.17, v11.7.0
7
+
8
+ feature:
9
+ - 8fd4fd6 @putout/printer: FunctionDeclaration inside TSModuleDeclarationExportnamed
10
+ - ab8c280 @putout/printer: @putout/plugin-promises v16.0.0
11
+ - ba04427 @putout/printer: LabeledStatement: indent
12
+
1
13
  2024.12.16, v11.6.0
2
14
 
3
15
  feature:
@@ -1,16 +1,20 @@
1
1
  'use strict';
2
2
 
3
+ const {
4
+ isTSModuleBlock,
5
+ isBlockStatement,
6
+ isExportNamedDeclaration,
7
+ } = require('@putout/babel').types;
8
+
3
9
  const {markAfter} = require('../../mark');
4
10
  const {isNext, isNextParent} = require('../../is');
5
11
  const {printParams} = require('./params');
6
12
 
13
+ const isInsideNamedExport = ({parentPath}) => isExportNamedDeclaration(parentPath);
14
+
7
15
  module.exports.FunctionDeclaration = {
8
16
  print(path, printer, semantics) {
9
- const {
10
- print,
11
- maybe,
12
- indent,
13
- } = printer;
17
+ const {print, maybe} = printer;
14
18
 
15
19
  const {
16
20
  async,
@@ -18,7 +22,7 @@ module.exports.FunctionDeclaration = {
18
22
  returnType,
19
23
  } = path.node;
20
24
 
21
- indent();
25
+ maybe.indent(!isInsideNamedExport(path));
22
26
  maybe.print(async, 'async ');
23
27
 
24
28
  print('function');
@@ -49,7 +53,12 @@ module.exports.FunctionDeclaration = {
49
53
  };
50
54
 
51
55
  function isInsideBlockStatement(path) {
52
- if (!path.parentPath.isBlockStatement())
56
+ const {parentPath} = path;
57
+
58
+ if (isTSModuleBlock(parentPath.parentPath))
59
+ return true;
60
+
61
+ if (!isBlockStatement(parentPath))
53
62
  return false;
54
63
 
55
64
  return !path.node.body.body.length;
@@ -51,4 +51,3 @@ function printUnary(path, name, {print}) {
51
51
  print(`${name} `);
52
52
  print('__argument');
53
53
  }
54
-
@@ -12,6 +12,7 @@ const {
12
12
  isMemberExpression,
13
13
  isArrayExpression,
14
14
  isObjectExpression,
15
+ isLabeledStatement,
15
16
  } = types;
16
17
 
17
18
  const isParentProgram = (path) => path.parentPath?.isProgram();
@@ -124,6 +125,8 @@ module.exports.isNewlineBetweenSiblings = (path) => {
124
125
  return startNext - endCurrent > 1;
125
126
  };
126
127
 
128
+ module.exports.isInsideLabel = ({parentPath}) => isLabeledStatement(parentPath);
129
+
127
130
  module.exports.satisfy = (conditions) => (path) => {
128
131
  for (const condition of conditions)
129
132
  if (condition(path))
@@ -26,4 +26,3 @@ const maybeParensCondition = ({print, condition}) => ({
26
26
  ...maybeParensPrint(print),
27
27
  condition: (path) => condition?.(path) || isParens(path),
28
28
  });
29
-
@@ -10,6 +10,7 @@ const {
10
10
  noTrailingComment,
11
11
  hasTrailingComment,
12
12
  isCoupleLines,
13
+ isInsideLabel,
13
14
  } = require('../is');
14
15
 
15
16
  const isBeforeElse = (path) => {
@@ -36,8 +37,8 @@ const shouldBreakline = satisfy([
36
37
  ]);
37
38
 
38
39
  module.exports.ExpressionStatement = {
39
- print(path, {indent, print, maybe, store}) {
40
- indent();
40
+ print(path, {print, maybe, store}) {
41
+ maybe.indent(!isInsideLabel(path));
41
42
 
42
43
  print('__expression');
43
44
  print(';');
@@ -21,6 +21,7 @@ const {BreakStatement} = require('./break-statement');
21
21
  const {DoWhileStatement} = require('./do-while-statement');
22
22
  const {Program} = require('./program/program');
23
23
  const {ContinueStatement} = require('./continue-statement');
24
+ const {LabeledStatement} = require('./labeled-statement/labeled-satement');
24
25
 
25
26
  const {
26
27
  ExportNamespaceSpecifier,
@@ -44,12 +45,7 @@ module.exports = {
44
45
  ForOfStatement,
45
46
  ReturnStatement,
46
47
  DebuggerStatement,
47
- LabeledStatement(path, {print}) {
48
- print('__label');
49
- print(':');
50
- print.space();
51
- print('__body');
52
- },
48
+ LabeledStatement,
53
49
  Program,
54
50
  EmptyStatement(path, {write}) {
55
51
  write(';');
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const {isInsideLabel} = require('../../is');
4
+
5
+ module.exports.LabeledStatement = (path, {print, maybe}) => {
6
+ maybe.indent(!isInsideLabel(path));
7
+ print('__label');
8
+ print(':');
9
+ print.space();
10
+ print('__body');
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "11.6.0",
3
+ "version": "11.8.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",
@@ -54,7 +54,7 @@
54
54
  "@putout/eslint": "^3.5.0",
55
55
  "@putout/plugin-minify": "^9.0.0",
56
56
  "@putout/plugin-printer": "^3.0.0",
57
- "@putout/plugin-promises": "^15.0.0",
57
+ "@putout/plugin-promises": "^16.0.0",
58
58
  "@putout/plugin-react-hook-form": "^4.0.0",
59
59
  "@putout/plugin-react-hooks": "^6.0.0",
60
60
  "acorn": "^8.8.2",