@putout/printer 1.6.5 → 1.6.7

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.03.21, v1.6.7
2
+
3
+ feature:
4
+ - 6f75079 @putout/printer: add support of BreakStatement
5
+
6
+ 2023.03.21, v1.6.6
7
+
8
+ feature:
9
+ - 4af2bdb @putout/printer: add support of ImportDeclaration, ExportDeclaration
10
+
1
11
  2023.03.21, v1.6.5
2
12
 
3
13
  feature:
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {isMarkedPrevAfter} = require('../mark');
4
- const isFirst = (path) => path.node === path.parentPath.node.body[0];
4
+ const isFirst = (path) => !path.getPrevSibling().node;
5
5
 
6
6
  module.exports.FunctionExpression = (path, {print, maybe}) => {
7
7
  const {node} = path;
@@ -72,7 +72,7 @@ module.exports.ObjectMethod = (path, {print}) => {
72
72
  module.exports.FunctionDeclaration = (path, {print, maybe}) => {
73
73
  const {async} = path.node;
74
74
 
75
- if (!isFirst(path) && !isMarkedPrevAfter(path))
75
+ if (!isFirst(path) && !isMarkedPrevAfter(path) && !path.parentPath.isExportDeclaration())
76
76
  print('\n');
77
77
 
78
78
  maybe.print(async, 'async ');
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports.ExportNamedDeclaration = (path, {print}) => {
4
+ print('export ');
5
+ print('__declaration');
6
+ };
7
+
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ const {entries} = Object;
4
+
5
+ module.exports.ImportDeclaration = (path, {print, maybe}) => {
6
+ const specifiers = path.get('specifiers');
7
+ print('import ');
8
+
9
+ for (const [index, spec] of entries(specifiers)) {
10
+ if (spec.isImportDefaultSpecifier()) {
11
+ print(spec.get('local'));
12
+ continue;
13
+ }
14
+
15
+ if (spec.isImportSpecifier()) {
16
+ maybe.print(index, ', ');
17
+ print('{');
18
+ print(spec.get('imported'));
19
+ print('}');
20
+ continue;
21
+ }
22
+ }
23
+
24
+ print(' ');
25
+ print('from');
26
+ print(' ');
27
+ print('__source');
28
+ print(';');
29
+ print.newline();
30
+ };
31
+
@@ -9,8 +9,12 @@ 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');
13
+ const exportDeclarations = require('./export-declarations');
12
14
 
13
15
  module.exports = {
16
+ ...importDeclarations,
17
+ ...exportDeclarations,
14
18
  BlockStatement,
15
19
  ExpressionStatement,
16
20
  VariableDeclaration,
@@ -23,9 +27,15 @@ module.exports = {
23
27
  path.get('body').forEach(traverse);
24
28
  },
25
29
  ...TryStatements,
26
- ContinueStatement(path, {write, indent}) {
30
+ BreakStatement(path, {print, indent}) {
27
31
  indent();
28
- write('continue;\n');
32
+ print('break;');
33
+ print.newline();
34
+ },
35
+ ContinueStatement(path, {indent, print}) {
36
+ indent();
37
+ print('continue;');
38
+ print.newline();
29
39
  },
30
40
  };
31
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
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",