@putout/printer 2.22.0 → 2.24.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.
Files changed (23) hide show
  1. package/ChangeLog +10 -0
  2. package/lib/tokenize/expressions/array-expression/new-line.js +2 -5
  3. package/lib/tokenize/expressions/assignment-expression.js +1 -4
  4. package/lib/tokenize/expressions/functions/class-method.js +1 -3
  5. package/lib/tokenize/expressions/functions/function-declaration.js +1 -4
  6. package/lib/tokenize/expressions/functions/function-expression.js +1 -4
  7. package/lib/tokenize/expressions/member-expressions/member-expressions.js +1 -4
  8. package/lib/tokenize/expressions/object-expression/object-property.js +1 -4
  9. package/lib/tokenize/expressions/object-pattern/max-properties-in-one-line.js +0 -1
  10. package/lib/tokenize/expressions/object-pattern/object-pattern.js +4 -4
  11. package/lib/tokenize/expressions/unary-expressions.js +2 -8
  12. package/lib/tokenize/literals/index.js +2 -8
  13. package/lib/tokenize/statements/break-statement.js +1 -4
  14. package/lib/tokenize/statements/export-declaration/export-declaration.js +2 -8
  15. package/lib/tokenize/statements/export-declaration/export-default-declaration.js +1 -3
  16. package/lib/tokenize/statements/import-declaration/import-declaration.js +2 -8
  17. package/lib/tokenize/statements/switch-statement.js +1 -3
  18. package/lib/tokenize/statements/variable-declaration/variable-declaration.js +3 -0
  19. package/lib/tokenize/tokenize.js +1 -4
  20. package/lib/tokenize/typescript/ts-interface-declaration.js +1 -3
  21. package/lib/tokenize/typescript/ts-mapped-type.js +1 -4
  22. package/lib/tokenize/typescript/ts-module-declaration.js +1 -3
  23. package/package.json +1 -1
package/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2023.06.16, v2.24.0
2
+
3
+ feature:
4
+ - 32d4852 @putout/printer: VariableDeclaration: newline
5
+
6
+ 2023.06.16, v2.23.0
7
+
8
+ feature:
9
+ - 8dd9ddf @putout/printer: ArrayExpression: newline
10
+
1
11
  2023.06.16, v2.22.0
2
12
 
3
13
  feature:
@@ -113,10 +113,7 @@ const isForOf = ({parentPath}) => parentPath.isForOfStatement();
113
113
  const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
114
114
 
115
115
  const isShortTwoSimplesInsideCall = (path, short) => {
116
- const {
117
- node,
118
- parentPath,
119
- } = path;
116
+ const {node, parentPath} = path;
120
117
 
121
118
  const {elements} = node;
122
119
  const {length} = elements;
@@ -139,7 +136,7 @@ function isOneSimple(path) {
139
136
 
140
137
  const [first] = elements;
141
138
 
142
- if (first.isIdentifier() && first.node.name.length < 5)
139
+ if (first.isIdentifier() && first.node.name.length < 15)
143
140
  return true;
144
141
 
145
142
  if (first.isStringLiteral() && first.node.value.length > 10)
@@ -4,10 +4,7 @@ const {isObjectPattern} = require('@babel/types');
4
4
 
5
5
  module.exports.AssignmentExpression = {
6
6
  condition: (path) => {
7
- const {
8
- left,
9
- extra,
10
- } = path.node;
7
+ const {left, extra} = path.node;
11
8
 
12
9
  if (isObjectPattern(left))
13
10
  return true;
@@ -26,9 +26,7 @@ const ClassMethod = {
26
26
  print.space();
27
27
  print('__body');
28
28
  },
29
- afterSatisfy: () => [
30
- isNext,
31
- ],
29
+ afterSatisfy: () => [isNext],
32
30
  after(path, {print}) {
33
31
  print.linebreak();
34
32
  },
@@ -2,10 +2,7 @@
2
2
 
3
3
  const {markAfter} = require('../../mark');
4
4
 
5
- const {
6
- isNext,
7
- isNextParent,
8
- } = require('../../is');
5
+ const {isNext, isNextParent} = require('../../is');
9
6
 
10
7
  const {printParams} = require('./params');
11
8
 
@@ -6,10 +6,7 @@ const {printParams} = require('./params');
6
6
  module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
7
7
  const {node} = path;
8
8
 
9
- const {
10
- generator,
11
- async,
12
- } = node;
9
+ const {generator, async} = node;
13
10
 
14
11
  maybe.write(async, 'async ');
15
12
  write('function');
@@ -41,10 +41,7 @@ module.exports.MemberExpression = (path, {print, maybe, traverse}) => {
41
41
  };
42
42
 
43
43
  module.exports.OptionalMemberExpression = (path, {print, maybe}) => {
44
- const {
45
- computed,
46
- optional,
47
- } = path.node;
44
+ const {computed, optional} = path.node;
48
45
 
49
46
  print('__object');
50
47
 
@@ -4,10 +4,7 @@ const {isConcatenation} = require('../binary-expression/concatanate');
4
4
  const {isOneLine} = require('./object-expression');
5
5
 
6
6
  module.exports.ObjectProperty = (path, {maybe, traverse, write}) => {
7
- const {
8
- shorthand,
9
- computed,
10
- } = path.node;
7
+ const {shorthand, computed} = path.node;
11
8
 
12
9
  const key = path.get('key');
13
10
  const value = path.get('value');
@@ -10,4 +10,3 @@ module.exports.checkMaxPropertiesInOneLine = (path, {maxPropertiesInOneLine}) =>
10
10
 
11
11
  return maxPropertiesInOneLine >= n;
12
12
  };
13
-
@@ -12,6 +12,7 @@ const {
12
12
  isCoupleLines,
13
13
  exists,
14
14
  } = require('../../is');
15
+
15
16
  const {checkMaxPropertiesInOneLine} = require('./max-properties-in-one-line');
16
17
 
17
18
  const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObjectProperty();
@@ -26,9 +27,11 @@ module.exports.ObjectPattern = {
26
27
 
27
28
  const properties = path.get('properties');
28
29
  const n = properties.length - 1;
30
+
29
31
  const is = shouldAddNewline(path, {
30
32
  maxPropertiesInOneLine,
31
33
  });
34
+
32
35
  const hasObject = n && hasObjectPattern(properties);
33
36
 
34
37
  maybe.print.newline(is);
@@ -45,10 +48,7 @@ module.exports.ObjectPattern = {
45
48
  const keyPath = property.get('key');
46
49
  const isAssign = valuePath.isAssignmentPattern();
47
50
 
48
- const {
49
- shorthand,
50
- computed,
51
- } = property.node;
51
+ const {shorthand, computed} = property.node;
52
52
 
53
53
  const couple = isCoupleLines(valuePath) && !exists(property.getPrevSibling()) && !path.parentPath.isObjectProperty();
54
54
 
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- isLast,
5
- isNext,
6
- } = require('../is');
3
+ const {isLast, isNext} = require('../is');
7
4
 
8
5
  module.exports.UnaryExpression = unaryExpression;
9
6
  module.exports.UpdateExpression = unaryExpression;
@@ -40,10 +37,7 @@ function printUnary(path, name, {print}) {
40
37
  const isWord = (a) => /^(delete|typeof|void)$/.test(a);
41
38
 
42
39
  function unaryExpression(path, {maybe, traverse}) {
43
- const {
44
- prefix,
45
- operator,
46
- } = path.node;
40
+ const {prefix, operator} = path.node;
47
41
 
48
42
  const argPath = path.get('argument');
49
43
 
@@ -20,10 +20,7 @@ module.exports = {
20
20
  write(path.node.value);
21
21
  },
22
22
  StringLiteral(path, {write}) {
23
- const {
24
- raw,
25
- value,
26
- } = path.node;
23
+ const {raw, value} = path.node;
27
24
 
28
25
  write(raw || `'${value}'`);
29
26
  },
@@ -31,10 +28,7 @@ module.exports = {
31
28
  const {node} = path;
32
29
  const parenthesized = node.extra?.parenthesized;
33
30
 
34
- const {
35
- name,
36
- optional,
37
- } = node;
31
+ const {name, optional} = node;
38
32
 
39
33
  maybe.write(parenthesized, '(');
40
34
  write(name);
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- isParentBlock,
5
- isNextParent,
6
- } = require('../is');
3
+ const {isParentBlock, isNextParent} = require('../is');
7
4
 
8
5
  const insideCase = (path) => path.parentPath.isSwitchCase();
9
6
 
@@ -7,10 +7,7 @@ const {
7
7
  isLast,
8
8
  } = require('../../is');
9
9
 
10
- const {
11
- markAfter,
12
- isMarkedAfter,
13
- } = require('../../mark');
10
+ const {markAfter, isMarkedAfter} = require('../../mark');
14
11
 
15
12
  const {isExportNamespaceSpecifier} = require('@babel/types');
16
13
 
@@ -23,10 +20,7 @@ const options = {
23
20
  };
24
21
 
25
22
  module.exports.ExportSpecifier = (path, {print}) => {
26
- const {
27
- local,
28
- exported,
29
- } = path.node;
23
+ const {local, exported} = path.node;
30
24
 
31
25
  print('__local');
32
26
 
@@ -23,9 +23,7 @@ module.exports.ExportDefaultDeclaration = {
23
23
  traverse(declaration);
24
24
  maybe.print(shouldAddSemi(declaration), ';');
25
25
  },
26
- afterSatisfy: () => [
27
- notClass,
28
- ],
26
+ afterSatisfy: () => [notClass],
29
27
  after(path, {print}) {
30
28
  print.newline();
31
29
  print.newline();
@@ -2,10 +2,7 @@
2
2
 
3
3
  const {markAfter} = require('../../mark');
4
4
 
5
- const {
6
- isLast,
7
- isNext,
8
- } = require('../../is');
5
+ const {isLast, isNext} = require('../../is');
9
6
 
10
7
  const {parseImportSpecifiers} = require('parse-import-specifiers');
11
8
 
@@ -53,10 +50,7 @@ module.exports.ImportDeclaration = {
53
50
  const last = index === importsCount;
54
51
  const notLast = !last;
55
52
 
56
- const {
57
- imported,
58
- local,
59
- } = spec.node;
53
+ const {imported, local} = spec.node;
60
54
 
61
55
  indent.inc();
62
56
 
@@ -59,9 +59,7 @@ module.exports.SwitchStatement = {
59
59
  if (!isNext(path) && !isLast(path))
60
60
  print.newline();
61
61
  },
62
- afterSatisfy: () => [
63
- isNext,
64
- ],
62
+ afterSatisfy: () => [isNext],
65
63
  after(path, {print}) {
66
64
  print.breakline();
67
65
  print.breakline();
@@ -130,6 +130,9 @@ function isNextCoupleLines(path) {
130
130
  const next = path.getNextSibling();
131
131
  const prev = path.getPrevSibling();
132
132
 
133
+ if (!exists(prev.getPrevSibling()) && next.isVariableDeclaration())
134
+ return false;
135
+
133
136
  if (path.node.loc?.start.line === prev.node?.loc?.start.line + 2)
134
137
  return false;
135
138
 
@@ -17,10 +17,7 @@ const {
17
17
  maybeThrow,
18
18
  } = require('./maybe');
19
19
 
20
- const {
21
- createDebug,
22
- createLog,
23
- } = require('./debug');
20
+ const {createDebug, createLog} = require('./debug');
24
21
 
25
22
  const {
26
23
  maybeMarkAfter,
@@ -8,9 +8,7 @@ module.exports.TSInterfaceDeclaration = {
8
8
  print('__id');
9
9
  print('__body');
10
10
  },
11
- afterSatisfy: () => [
12
- isNext,
13
- ],
11
+ afterSatisfy: () => [isNext],
14
12
  after(path, {print}) {
15
13
  print.breakline();
16
14
  print.breakline();
@@ -1,10 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports.TSMappedType = (path, {print, write, indent, maybe}) => {
4
- const {
5
- readonly,
6
- optional,
7
- } = path.node;
4
+ const {readonly, optional} = path.node;
8
5
 
9
6
  write('{');
10
7
  write.newline();
@@ -9,9 +9,7 @@ module.exports.TSModuleDeclaration = {
9
9
  print.space();
10
10
  print('__body');
11
11
  },
12
- afterSatisfy: () => [
13
- isNext,
14
- ],
12
+ afterSatisfy: () => [isNext],
15
13
  after(path, {print}) {
16
14
  print.newline();
17
15
  print.newline();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.22.0",
3
+ "version": "2.24.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",