@putout/printer 1.10.0 → 1.11.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,9 @@
1
+ 2023.03.29, v1.11.0
2
+
3
+ feature:
4
+ - a2250dd @putout/printer: add newline at eof
5
+ - c1fb26f @putout/printer: use '__array.entries()' instead of 'entries(__array)'
6
+
1
7
  2023.03.28, v1.10.0
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -60,7 +60,7 @@ print(ast, {
60
60
  });
61
61
 
62
62
  // returns
63
- 'const {a /* [hello world] */= 5} = b;';
63
+ 'const {a /* [hello world] */= 5} = b;\n';
64
64
  ```
65
65
 
66
66
  ## License
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const {entries} = Object;
4
-
5
3
  module.exports.NewExpression = (path, {indent, print, maybe}) => {
6
4
  indent();
7
5
  print('new ');
@@ -12,7 +10,7 @@ module.exports.NewExpression = (path, {indent, print, maybe}) => {
12
10
 
13
11
  const n = args.length - 1;
14
12
 
15
- for (const [i, arg] of entries(args)) {
13
+ for (const [i, arg] of args.entries()) {
16
14
  print(arg);
17
15
  maybe.print(i < n, ', ');
18
16
  }
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const {entries} = Object;
4
3
  const isForOf = (path) => path.parentPath?.parentPath?.parentPath?.isForOfStatement();
5
4
 
6
5
  module.exports.ObjectPattern = (path, {indent, print, maybe}) => {
@@ -13,7 +12,7 @@ module.exports.ObjectPattern = (path, {indent, print, maybe}) => {
13
12
  const is = !isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties);
14
13
  maybe.print(is, '\n');
15
14
 
16
- for (const [i, property] of entries(properties)) {
15
+ for (const [i, property] of properties.entries()) {
17
16
  if (property.isRestElement()) {
18
17
  print(property);
19
18
  continue;
@@ -3,37 +3,43 @@
3
3
  const {
4
4
  isNext,
5
5
  isParentProgram,
6
+ isLast,
7
+
6
8
  } = require('../is');
7
9
 
8
10
  const isFirstStatement = (path) => path.get('body.0')?.isStatement();
9
11
 
10
- module.exports.BlockStatement = (path, {indent, maybe, print}) => {
11
- const body = path.get('body');
12
-
13
- if (path.parentPath.isBlockStatement())
14
- indent();
15
-
16
- indent.inc();
17
- print('{');
18
-
19
- if (body.length > 1 || isFirstStatement(path))
12
+ module.exports.BlockStatement = {
13
+ print(path, {indent, maybe, print}) {
14
+ const body = path.get('body');
15
+
16
+ if (path.parentPath.isBlockStatement())
17
+ indent();
18
+
19
+ indent.inc();
20
+ print('{');
21
+
22
+ if (body.length > 1 || isFirstStatement(path))
23
+ print.newline();
24
+
25
+ for (const element of body) {
26
+ print(element);
27
+ }
28
+
29
+ indent.dec();
30
+ maybe.indent(body.length);
31
+ print('}');
32
+
33
+ if (path.parentPath.isObjectMethod()) {
34
+ print(',');
35
+ }
36
+ },
37
+ afterIf(path) {
38
+ return shouldAddNewlineAfter(path);
39
+ },
40
+ after(path, {print}) {
20
41
  print.newline();
21
-
22
- for (const element of body) {
23
- print(element);
24
- }
25
-
26
- indent.dec();
27
- maybe.indent(body.length);
28
- print('}');
29
-
30
- if (path.parentPath.isObjectMethod()) {
31
- print(',');
32
- }
33
-
34
- if (shouldAddNewlineAfter(path)) {
35
- print.newline();
36
- }
42
+ },
37
43
  };
38
44
 
39
45
  function shouldAddNewlineAfter(path) {
@@ -48,6 +54,9 @@ function shouldAddNewlineAfter(path) {
48
54
  if (isTry(path) || /FunctionExpression/.test(path.parentPath.type))
49
55
  return false;
50
56
 
57
+ if (isLast(path))
58
+ return false;
59
+
51
60
  return true;
52
61
  }
53
62
 
@@ -1,20 +1,19 @@
1
1
  'use strict';
2
2
 
3
3
  const {markAfter} = require('../mark');
4
- const {entries} = Object;
5
4
 
6
5
  module.exports.ImportDeclaration = (path, {print, maybe}) => {
7
6
  const specifiers = path.get('specifiers');
8
7
  print('import ');
9
8
 
10
- for (const [index, spec] of entries(specifiers)) {
9
+ for (const [index, spec] of specifiers.entries()) {
11
10
  if (spec.isImportDefaultSpecifier()) {
12
11
  print(spec.get('local'));
13
12
  continue;
14
13
  }
15
14
 
16
15
  if (spec.isImportSpecifier()) {
17
- maybe.print(Number(index), ', ');
16
+ maybe.print(index, ', ');
18
17
  print('{');
19
18
  print(spec.get('imported'));
20
19
  print('}');
@@ -32,6 +32,7 @@ module.exports = {
32
32
  DebuggerStatement,
33
33
  Program(path, {print}) {
34
34
  path.get('body').forEach(print);
35
+ print.newline();
35
36
  },
36
37
  SwitchStatement,
37
38
  ...TryStatements,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
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",