@putout/printer 2.45.0 → 2.47.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,14 @@
1
+ 2023.07.05, v2.47.0
2
+
3
+ feature:
4
+ - dc0ba73 @putout/printer: Program: improve support of inner comments
5
+
6
+ 2023.07.04, v2.46.0
7
+
8
+ feature:
9
+ - c131fac @putout/printer: Directives
10
+ - 70baffb @putout/printer: add support of directives
11
+
1
12
  2023.07.04, v2.45.0
2
13
 
3
14
  feature:
@@ -3,9 +3,9 @@
3
3
  const {
4
4
  hasTrailingComment,
5
5
  isLast,
6
- } = require('./is');
6
+ } = require('../is');
7
7
 
8
- const {markBefore} = require('./mark');
8
+ const {markBefore} = require('../mark');
9
9
  const {isVariableDeclarator} = require('@babel/types');
10
10
 
11
11
  module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics) => {
@@ -99,6 +99,13 @@ module.exports.parseComments = (path, {write}, semantics) => {
99
99
  write('//');
100
100
  write(value);
101
101
  write.newline();
102
+ continue;
103
+ }
104
+
105
+ if (type === 'CommentBlock') {
106
+ write('/*');
107
+ write(value);
108
+ write('*/');
102
109
  }
103
110
  }
104
111
  };
@@ -24,6 +24,7 @@ module.exports.FunctionDeclaration = {
24
24
  });
25
25
 
26
26
  print.space();
27
+
27
28
  print('__body');
28
29
  },
29
30
  afterSatisfy: () => [isNext, isNextParent],
@@ -11,7 +11,7 @@ const {
11
11
  exists,
12
12
  } = require('../../is');
13
13
 
14
- const {parseComments} = require('../../comments');
14
+ const {parseComments} = require('../../comments/comments');
15
15
  const {isSpreadElement} = require('@babel/types');
16
16
 
17
17
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
@@ -21,6 +21,15 @@ module.exports = {
21
21
 
22
22
  write(raw || extra?.raw || value);
23
23
  },
24
+ Directive(path, {print}) {
25
+ print('__value');
26
+ },
27
+ DirectiveLiteral(path, {write}) {
28
+ write.indent();
29
+ write(path.node.raw);
30
+ write(';');
31
+ write.newline();
32
+ },
24
33
  BooleanLiteral(path, {write}) {
25
34
  write(path.node.value);
26
35
  },
@@ -13,44 +13,54 @@ const {
13
13
  } = require('@babel/types');
14
14
 
15
15
  const {markAfter} = require('../../mark');
16
- const {parseComments} = require('../../comments');
16
+ const {parseComments} = require('../../comments/comments');
17
17
  const {insideIfWithNoBody} = require('./inside-if-with-no-body');
18
18
 
19
- const isFirstStatement = (path) => path.get('body.0')?.isStatement();
19
+ const isFirstStatement = (path) => path.node.body[0];
20
+ const isFirstDirective = (path) => path.node.directives?.[0];
20
21
  const isMethodOrArrow = (path) => isArrowFunctionExpression(path) || isObjectMethod(path);
21
22
 
23
+ const getDirectives = (path) => !path.node.directives ? [] : path.get('directives');
24
+
25
+ module.exports._getDirectives = getDirectives;
26
+
22
27
  module.exports.BlockStatement = {
23
- print(path, {indent, maybe, print, write}, semantics) {
28
+ print(path, {indent, maybe, write, traverse}, semantics) {
24
29
  const body = path.get('body');
30
+ const directives = getDirectives(path);
25
31
 
26
32
  if (path.parentPath.isBlockStatement())
27
33
  indent();
28
34
 
29
35
  indent.inc();
30
- print('{');
36
+ write('{');
31
37
 
32
- if (isFirstStatement(path))
33
- print.newline();
38
+ if (isFirstStatement(path) || isFirstDirective(path))
39
+ write.newline();
40
+
41
+ for (const directive of directives) {
42
+ traverse(directive);
43
+ }
34
44
 
35
45
  for (const element of body) {
36
- print(element);
46
+ traverse(element);
37
47
  }
38
48
 
39
49
  parseComments(path, {write}, semantics);
40
50
 
41
51
  indent.dec();
42
52
  maybe.indent(body.length);
43
- print('}');
53
+ write('}');
44
54
 
45
55
  if (path.parentPath.isObjectMethod()) {
46
- print(',');
56
+ write(',');
47
57
  }
48
58
  },
49
59
  afterIf(path) {
50
60
  return shouldAddNewlineAfter(path);
51
61
  },
52
- after(path, {print}) {
53
- print.newline();
62
+ after(path, {write}) {
63
+ write.newline();
54
64
  markAfter(path.parentPath);
55
65
  },
56
66
  };
@@ -38,6 +38,7 @@ const shouldBreakline = satisfy([
38
38
  module.exports.ExpressionStatement = {
39
39
  print(path, {indent, print, maybe, store}) {
40
40
  indent();
41
+
41
42
  print('__expression');
42
43
  print(';');
43
44
 
@@ -19,6 +19,7 @@ const {ForInStatement} = require('./for-in-statement');
19
19
  const {ExportDefaultDeclaration} = require('./export-declaration/export-default-declaration');
20
20
  const {BreakStatement} = require('./break-statement');
21
21
  const {DoWhileStatement} = require('./do-while-statement');
22
+ const {Program} = require('./program');
22
23
 
23
24
  const {
24
25
  ExportNamespaceSpecifier,
@@ -48,15 +49,7 @@ module.exports = {
48
49
  print.space();
49
50
  print('__body');
50
51
  },
51
- Program(path, {print}) {
52
- print('__interpreter');
53
-
54
- path
55
- .get('body')
56
- .forEach(print);
57
-
58
- print.newline();
59
- },
52
+ Program,
60
53
  EmptyStatement(path, {write}) {
61
54
  write(';');
62
55
  },
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const {parseComments} = require('../comments/comments');
4
+ module.exports.Program = (path, {print, write}, semantics) => {
5
+ print('__interpreter');
6
+ parseComments(path, {write}, semantics);
7
+
8
+ path
9
+ .get('body')
10
+ .forEach(print);
11
+
12
+ print.newline();
13
+ };
14
+
@@ -13,7 +13,7 @@ const {isExportDeclaration} = require('@babel/types');
13
13
  const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
14
14
 
15
15
  const {isConcatenation} = require('../../expressions/binary-expression/concatanate');
16
- const {parseLeadingComments} = require('../../comments');
16
+ const {parseLeadingComments} = require('../../comments/comments');
17
17
 
18
18
  const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
19
19
  const isInsideBlock = (path) => /^(Program|BlockStatement)$/.test(path.parentPath.type);
@@ -27,7 +27,7 @@ const {
27
27
  const {
28
28
  parseLeadingComments,
29
29
  parseTrailingComments,
30
- } = require('./comments');
30
+ } = require('./comments/comments');
31
31
 
32
32
  const {parseOverrides} = require('./overrides');
33
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.45.0",
3
+ "version": "2.47.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",
@@ -50,6 +50,7 @@
50
50
  "@babel/plugin-codemod-object-assign-to-object-spread": "^7.10.4",
51
51
  "@putout/plugin-minify": "^1.8.0",
52
52
  "@putout/plugin-printer": "^1.0.0",
53
+ "@putout/plugin-promises": "^10.0.0",
53
54
  "@putout/plugin-react-hook-form": "^3.4.1",
54
55
  "@putout/plugin-react-hooks": "^5.0.0",
55
56
  "@putout/test": "^6.0.1",