@putout/printer 1.70.0 → 1.70.2

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,13 @@
1
+ 2023.04.25, v1.70.2
2
+
3
+ fix:
4
+ - 42813b5 @putout/printer: ExportDeclaration: newline
5
+
6
+ 2023.04.25, v1.70.1
7
+
8
+ feature:
9
+ - 1cdcf93 @putout/printer: add support of ImportNamespaceSpecifier
10
+
1
11
  2023.04.25, v1.70.0
2
12
 
3
13
  feature:
@@ -1,5 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ const {isNewlineBetweenStatements} = require('../is');
4
+ const {
5
+ markAfter,
6
+ isMarkedAfter,
7
+ } = require('../mark');
8
+
9
+ const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
10
+
3
11
  module.exports.ExportSpecifier = (path, {print}) => {
4
12
  const {
5
13
  local,
@@ -19,37 +27,49 @@ module.exports.ExportNamespaceSpecifier = (path, {print}) => {
19
27
  print('__exported');
20
28
  };
21
29
 
22
- module.exports.ExportNamedDeclaration = (path, {print, traverse, write, indent}) => {
23
- const {exportKind} = path.node;
24
- const specifiers = path.get('specifiers');
25
-
26
- write('export ');
27
-
28
- if (exportKind === 'type' && specifiers.length) {
29
- print('type');
30
- print(specifiers[0]);
31
- print(' from ');
32
- print('__source');
33
- print(';');
30
+ module.exports.ExportNamedDeclaration = {
31
+ print(path, {print, traverse, write, indent}) {
32
+ const {exportKind} = path.node;
33
+ const specifiers = path.get('specifiers');
34
34
 
35
- return;
36
- }
37
-
38
- if (specifiers.length) {
39
- write('{');
40
- indent.inc();
41
- write.newline();
35
+ write('export ');
42
36
 
43
- for (const spec of specifiers) {
44
- indent();
45
- traverse(spec);
46
- write(',');
37
+ if (exportKind === 'type' && specifiers.length) {
38
+ print('type');
39
+ print(specifiers[0]);
40
+ print(' from ');
41
+ print('__source');
42
+ print(';');
43
+
44
+ return;
45
+ }
46
+
47
+ if (specifiers.length) {
48
+ write('{');
49
+ indent.inc();
47
50
  write.newline();
51
+
52
+ for (const spec of specifiers) {
53
+ indent();
54
+ traverse(spec);
55
+ write(',');
56
+ write.newline();
57
+ }
58
+
59
+ indent.dec();
60
+ write('}');
48
61
  }
49
62
 
50
- indent.dec();
51
- write('}');
52
- }
53
-
54
- print('__declaration');
63
+ print('__declaration');
64
+ },
65
+ afterIf(path) {
66
+ if (isDeclarationNewline(path))
67
+ return false;
68
+
69
+ return isNewlineBetweenStatements(path);
70
+ },
71
+ after(path, {print}) {
72
+ print.newline();
73
+ markAfter(path);
74
+ },
55
75
  };
@@ -17,6 +17,11 @@ module.exports.ImportDeclaration = {
17
17
  continue;
18
18
  }
19
19
 
20
+ if (spec.isImportNamespaceSpecifier()) {
21
+ print('* as ');
22
+ print(spec.get('local'));
23
+ }
24
+
20
25
  if (spec.isImportSpecifier()) {
21
26
  maybe.print(index, ', ');
22
27
  maybe.print(!wasSpecifier, '{');
@@ -9,7 +9,7 @@ const {ReturnStatement} = require('./return-statement');
9
9
  const TryStatements = require('./try-statements');
10
10
  const {DebuggerStatement} = require('./debugger-statement');
11
11
  const {ForStatement} = require('./for-statement');
12
- const importDeclarations = require('./import-declarations');
12
+ const importDeclarations = require('./import-declaration');
13
13
  const exportDeclarations = require('./export-declarations');
14
14
  const {WhileStatement} = require('./while-statement');
15
15
  const {SwitchStatement} = require('./switch-statement');
@@ -6,10 +6,7 @@ const {
6
6
  isNewlineBetweenStatements,
7
7
  } = require('../is');
8
8
 
9
- const {
10
- hasPrevNewline,
11
- markAfter,
12
- } = require('../mark');
9
+ const {hasPrevNewline} = require('../mark');
13
10
 
14
11
  const {isExportDeclaration} = require('@babel/types');
15
12
 
@@ -52,7 +49,7 @@ module.exports.VariableDeclaration = {
52
49
  const wasNewline = store();
53
50
  maybe.print.linebreak(wasNewline);
54
51
  maybe.print.newline(!wasNewline);
55
- markAfter(path);
52
+ maybe.markAfter(wasNewline, path);
56
53
  },
57
54
  };
58
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.70.0",
3
+ "version": "1.70.2",
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 fro 🐊Putout",