@putout/printer 1.5.3 → 1.5.4

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,8 @@
1
+ 2023.03.20, v1.5.4
2
+
3
+ feature:
4
+ - 96d7056 @putout/printer: split linebreak(\s\n) and breakline(\n\s)
5
+
1
6
  2023.03.20, v1.5.3
2
7
 
3
8
  feature:
@@ -11,7 +11,7 @@ module.exports.CallExpression = (path, {indent, print, maybe}) => {
11
11
  const isParentCall = toLong(path) && path.parentPath.isCallExpression();
12
12
 
13
13
  if (shouldAddNewLine(path) && !isMarkedParentBefore(path) && !isMarkedPrevAfter(path.parentPath))
14
- print.linebreak();
14
+ print.breakline();
15
15
 
16
16
  print(path.get('callee'));
17
17
  print('(');
@@ -6,7 +6,7 @@ const isFirst = (path) => path.node === path.parentPath.node.body[0];
6
6
 
7
7
  module.exports.ClassDeclaration = (path, {maybe, print, indent}) => {
8
8
  if (!isFirst(path)) {
9
- print.linebreak();
9
+ print.breakline();
10
10
  }
11
11
 
12
12
  indent();
@@ -7,9 +7,9 @@ const {
7
7
  } = require('../mark');
8
8
  const {isNext} = require('../is');
9
9
 
10
- module.exports.ExpressionStatement = (path, {write, indent, traverse}) => {
10
+ module.exports.ExpressionStatement = (path, {write, indent, traverse, print}) => {
11
11
  if (isCoupleLinesExpression(path) && !isFirst(path) && shouldAddNewLine(path) && !isMarkedPrevAfter(path)) {
12
- write.linebreak();
12
+ print.breakline();
13
13
  markBefore(path);
14
14
  }
15
15
 
@@ -62,3 +62,4 @@ function shouldAddNewLine(path) {
62
62
 
63
63
  return true;
64
64
  }
65
+
@@ -16,7 +16,7 @@ module.exports.TryStatement = (path, {print, maybe}) => {
16
16
  print.newline();
17
17
  }
18
18
 
19
- maybe.print.linebreak(isNext(path));
19
+ maybe.print.breakline(isNext(path));
20
20
  };
21
21
 
22
22
  module.exports.CatchClause = (path, {print}) => {
@@ -13,7 +13,7 @@ const isNextAssign = (path) => {
13
13
 
14
14
  module.exports.VariableDeclaration = (path, {maybe, print}) => {
15
15
  if (!isFirst(path) && shouldAddNewLine(path) && !hasPrevNewline(path))
16
- print.linebreak();
16
+ print.breakline();
17
17
 
18
18
  const isParentBlock = /Program|BlockStatement/.test(path.parentPath.type);
19
19
 
@@ -31,8 +31,7 @@ module.exports.VariableDeclaration = (path, {maybe, print}) => {
31
31
  const is = isNext(path) && isCoupleLines(path) && !isNextAssign(path);
32
32
 
33
33
  if (is) {
34
- print.indent();
35
- print.newline();
34
+ print.linebreak();
36
35
  markAfter(path);
37
36
  }
38
37
  };
@@ -37,7 +37,7 @@ module.exports.tokenize = (ast) => {
37
37
  const maybeIndentInc = (a) => a && indent.inc();
38
38
  const maybeIndentDec = (a) => a && indent.dec();
39
39
  const maybeNewline = (a) => a && newline();
40
- const maybeLinebreak = (a) => a && linebreak();
40
+ const maybeBreakline = (a) => a && breakline();
41
41
 
42
42
  let i = 0;
43
43
  const incIndent = () => ++i;
@@ -55,6 +55,13 @@ module.exports.tokenize = (ast) => {
55
55
  });
56
56
 
57
57
  const linebreak = () => {
58
+ tokens.push({
59
+ type: TYPES.NEWLINE,
60
+ value: `${printIndent(i)}\n`,
61
+ });
62
+ };
63
+
64
+ const breakline = () => {
58
65
  tokens.push({
59
66
  type: TYPES.NEWLINE,
60
67
  value: `\n${printIndent(i)}`,
@@ -72,6 +79,7 @@ module.exports.tokenize = (ast) => {
72
79
  indent,
73
80
  newline,
74
81
  linebreak,
82
+ breakline,
75
83
  });
76
84
  const print = (maybeLine) => {
77
85
  if (isString(maybeLine))
@@ -98,7 +106,7 @@ module.exports.tokenize = (ast) => {
98
106
  assign(print, write);
99
107
  assign(maybePrint, {
100
108
  newline: maybeNewline,
101
- linebreak: maybeLinebreak,
109
+ breakline: maybeBreakline,
102
110
  });
103
111
 
104
112
  const printer = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",