@putout/printer 7.1.1 → 7.2.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
+ 2023.12.14, v7.2.0
2
+
3
+ feature:
4
+ - 389b695 @putout/printer: var inside if (coderaiser/putout#194)
5
+
6
+ 2023.12.12, v7.1.2
7
+
8
+ feature:
9
+ - 7801ff7 @putout/printer: @putout/plugin-promises v14.0.0
10
+ - a34da40 @putout/printer: estree-to-babel v9.0.0
11
+
1
12
  2023.12.12, v7.1.1
2
13
 
3
14
  feature:
package/README.md CHANGED
@@ -52,7 +52,7 @@ To benefit from it.
52
52
 
53
53
  ```js
54
54
  const {print} = require('@putout/printer');
55
- const {parse} = require('@babel/parser');
55
+ const {parse} = require('@putout/babel');
56
56
  const ast = parse('const a = (b, c) => {const d = 5; return a;}');
57
57
 
58
58
  print(ast);
@@ -132,7 +132,7 @@ const overrides = {
132
132
  ```
133
133
 
134
134
  - `indent` - use two spaces, tabs, or anything you want;
135
- - `newline` - symbol for used for line separation;
135
+ - `newline` - symbol used for line separation;
136
136
  - `space` - default symbol used for space character;
137
137
  - `splitter` - mandatory symbol that used inside of statements like this:
138
138
  - `roundBraceOpen` and `roundBraceClose` symbols to output braces in a single argument arrow function expressions: `(a) => {}`.
@@ -32,6 +32,7 @@ module.exports.IfStatement = {
32
32
  const consequent = path.get('consequent');
33
33
  const alternate = path.get('alternate');
34
34
  const isConsequentBlock = consequent.isBlockStatement();
35
+ const isVar = consequent.isVariableDeclaration();
35
36
 
36
37
  if (isConsequentBlock) {
37
38
  print.space();
@@ -41,8 +42,10 @@ module.exports.IfStatement = {
41
42
  maybe.print.newline(isEmptyBody(consequent));
42
43
  } else {
43
44
  const is = !isEmptyConsequent(path);
45
+
44
46
  maybe.print.newline(is);
45
47
  maybe.indent.inc(is);
48
+ maybe.indent(isVar);
46
49
  print(consequent);
47
50
  maybe.indent.dec(is);
48
51
  }
@@ -56,6 +59,7 @@ module.exports.IfStatement = {
56
59
  write(' else ');
57
60
  traverse(alternate);
58
61
  } else if (exists(alternate)) {
62
+ maybe.write.newline(isVar);
59
63
  maybe.indent(!isConsequentBlock);
60
64
  maybe.write.space(isConsequentBlock);
61
65
  write('else');
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const {markAfter} = require('../../mark');
3
+ const {parseImportSpecifiers} = require('parse-import-specifiers');
4
4
 
5
+ const {markAfter} = require('../../mark');
5
6
  const {isLast, isNext} = require('../../is');
6
7
 
7
- const {parseImportSpecifiers} = require('parse-import-specifiers');
8
-
9
8
  const {
10
9
  maybePrintAttributes,
11
10
  ImportAttribute,
@@ -21,6 +21,7 @@ const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parent
21
21
  const isInsideBlock = (path) => /^(Program|BlockStatement|TSModuleBlock)$/.test(path.parentPath.type);
22
22
  const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
23
23
  const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
24
+ const isParentIf = (path) => path.parentPath.isIfStatement();
24
25
 
25
26
  module.exports.VariableDeclaration = {
26
27
  beforeIf: shouldAddNewlineBefore,
@@ -73,7 +74,7 @@ module.exports.VariableDeclaration = {
73
74
 
74
75
  maybe.indent.dec(n);
75
76
 
76
- if (isParentBlock(path) || isParentSwitchCase(path) || isParentTSModuleBlock(path))
77
+ if (isParentBlock(path) || isParentSwitchCase(path) || isParentTSModuleBlock(path) || isParentIf(path))
77
78
  write(';');
78
79
 
79
80
  let wasNewline = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "7.1.1",
3
+ "version": "7.2.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,7 +48,7 @@
48
48
  "@babel/plugin-codemod-object-assign-to-object-spread": "^7.10.4",
49
49
  "@putout/plugin-minify": "^6.2.0",
50
50
  "@putout/plugin-printer": "^3.0.0",
51
- "@putout/plugin-promises": "^13.0.0",
51
+ "@putout/plugin-promises": "^14.0.0",
52
52
  "@putout/plugin-react-hook-form": "^4.0.0",
53
53
  "@putout/plugin-react-hooks": "^5.0.0",
54
54
  "acorn": "^8.8.2",
@@ -58,7 +58,7 @@
58
58
  "eslint": "^8.0.1",
59
59
  "eslint-plugin-n": "^16.0.0",
60
60
  "eslint-plugin-putout": "^22.0.0",
61
- "estree-to-babel": "^8.0.0",
61
+ "estree-to-babel": "^9.0.0",
62
62
  "just-kebab-case": "^4.2.0",
63
63
  "madrun": "^10.0.0",
64
64
  "mock-require": "^3.0.3",