@putout/printer 2.44.0 → 2.46.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.04, v2.46.0
2
+
3
+ feature:
4
+ - c131fac @putout/printer: Directives
5
+ - 70baffb @putout/printer: add support of directives
6
+
7
+ 2023.07.04, v2.45.0
8
+
9
+ feature:
10
+ - d30c1cd @putout/printer: ObjectExpression: spread
11
+
1
12
  2023.07.03, v2.44.0
2
13
 
3
14
  feature:
@@ -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],
@@ -12,6 +12,7 @@ const {
12
12
  } = require('../../is');
13
13
 
14
14
  const {parseComments} = require('../../comments');
15
+ const {isSpreadElement} = require('@babel/types');
15
16
 
16
17
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
17
18
  const isLogical = (path) => path.get('argument').isLogicalExpression();
@@ -101,6 +102,13 @@ function shouldAddNewline(path) {
101
102
  const ONE_LINE = true;
102
103
  const MANY_LINES = false;
103
104
 
105
+ const isSpreadFirst = (path) => {
106
+ const {properties} = path.node;
107
+ const {length} = properties;
108
+
109
+ return length > 1 && isSpreadElement(properties[0]);
110
+ };
111
+
104
112
  module.exports.isOneLine = isOneLine;
105
113
  function isOneLine(path) {
106
114
  const {length} = path.get('properties');
@@ -120,6 +128,9 @@ function isOneLine(path) {
120
128
  if (isCoupleLines(path))
121
129
  return MANY_LINES;
122
130
 
131
+ if (isSpreadFirst(path))
132
+ return MANY_LINES;
133
+
123
134
  return !isValue(path);
124
135
  }
125
136
 
@@ -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
  },
@@ -62,3 +71,4 @@ module.exports = {
62
71
  write('super');
63
72
  },
64
73
  };
74
+
@@ -16,41 +16,51 @@ const {markAfter} = require('../../mark');
16
16
  const {parseComments} = require('../../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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.44.0",
3
+ "version": "2.46.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",
@@ -47,8 +47,10 @@
47
47
  "generate"
48
48
  ],
49
49
  "devDependencies": {
50
+ "@babel/plugin-codemod-object-assign-to-object-spread": "^7.10.4",
50
51
  "@putout/plugin-minify": "^1.8.0",
51
52
  "@putout/plugin-printer": "^1.0.0",
53
+ "@putout/plugin-promises": "^10.0.0",
52
54
  "@putout/plugin-react-hook-form": "^3.4.1",
53
55
  "@putout/plugin-react-hooks": "^5.0.0",
54
56
  "@putout/test": "^6.0.1",