@putout/printer 1.55.0 → 1.57.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,13 @@
1
+ 2023.04.19, v1.57.0
2
+
3
+ feature:
4
+ - 8f4ddc4 @putout/printer: add support of JSXMemberExpression
5
+
6
+ 2023.04.19, v1.56.0
7
+
8
+ feature:
9
+ - aaf4886 @putout/printer: add support of JSXFragment
10
+
1
11
  2023.04.18, v1.55.0
2
12
 
3
13
  fix:
@@ -51,6 +51,7 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
51
51
 
52
52
  print(')');
53
53
  }
54
+
54
55
  module.exports.OptionalCallExpression = CallExpression;
55
56
  module.exports.CallExpression = CallExpression;
56
57
 
@@ -3,16 +3,17 @@
3
3
  module.exports.ClassExpression = classVisitor;
4
4
  module.exports.ClassDeclaration = classVisitor;
5
5
 
6
- module.exports.ClassDeclaration = (path, {print, indent}) => {
6
+ module.exports.ClassDeclaration = (path, {print, indent, maybe}) => {
7
7
  indent();
8
8
 
9
9
  classVisitor(path, {
10
10
  print,
11
11
  indent,
12
+ maybe,
12
13
  });
13
14
  };
14
15
 
15
- function classVisitor(path, {print, indent}) {
16
+ function classVisitor(path, {print, indent, maybe}) {
16
17
  print('class ');
17
18
  print('__id');
18
19
  print('__typeParameters');
@@ -25,6 +26,7 @@ function classVisitor(path, {print, indent}) {
25
26
  }
26
27
 
27
28
  if (node.superClass) {
29
+ maybe.print.space(path.node.id);
28
30
  print('extends ');
29
31
  print('__superClass');
30
32
  }
@@ -1,15 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const {hasPrevNewline} = require('../../mark');
4
- const isFirst = (path) => !path.getPrevSibling().node;
3
+ const {markAfter} = require('../../mark');
4
+ const {isNext} = require('../../is');
5
5
 
6
6
  module.exports.FunctionDeclaration = {
7
- beforeIf(path) {
8
- return !isFirst(path) && !hasPrevNewline(path) && !path.parentPath.isExportDeclaration();
9
- },
10
- before(path, {write}) {
11
- write('\n');
12
- },
13
7
  print(path, {print, maybe}) {
14
8
  const {async} = path.node;
15
9
 
@@ -32,4 +26,11 @@ module.exports.FunctionDeclaration = {
32
26
  print(') ');
33
27
  print('__body');
34
28
  },
29
+ afterSatisfy: () => [
30
+ isNext,
31
+ ],
32
+ after(path, {write}) {
33
+ write.newline();
34
+ markAfter(path);
35
+ },
35
36
  };
@@ -62,6 +62,7 @@ function shouldAddNewline(path) {
62
62
 
63
63
  return path.parentPath.parentPath.isSpreadElement();
64
64
  }
65
+
65
66
  module.exports.ObjectProperty = (path, {print, maybe}) => {
66
67
  const {
67
68
  shorthand,
@@ -30,6 +30,7 @@ function printUnary(path, name, {print}) {
30
30
  print(`${name} `);
31
31
  print('__argument');
32
32
  }
33
+
33
34
  const isWord = (a) => /delete|typeof/.test(a);
34
35
 
35
36
  function unaryExpression(path, {maybe, traverse}) {
@@ -45,6 +45,7 @@ function isCoupleLines(path) {
45
45
 
46
46
  return end > start;
47
47
  }
48
+
48
49
  module.exports.exists = (a) => a.node;
49
50
  module.exports.isStringAndIdentifier = ([a, b]) => isStringLiteral(a) && isIdentifier(b);
50
51
 
@@ -4,8 +4,10 @@ const {JSXElement} = require('./jsx-element');
4
4
  const {JSXAttribute} = require('./jsx-attribute');
5
5
  const {isCoupleLines} = require('../is');
6
6
  const {JSXOpeningElement} = require('./jsx-opening-element');
7
+ const fragments = require('./jsx-fragment');
7
8
 
8
9
  module.exports = {
10
+ ...fragments,
9
11
  JSXElement,
10
12
  JSXAttribute,
11
13
  JSXOpeningElement,
@@ -20,6 +22,11 @@ module.exports = {
20
22
  JSXText(path, {write}) {
21
23
  write(path.node.value);
22
24
  },
25
+ JSXMemberExpression(path, {print}) {
26
+ print('__object');
27
+ print('.');
28
+ print('__property');
29
+ },
23
30
  JSXSpreadAttribute(path, {print, maybe}) {
24
31
  const isNewline = isCoupleLines(path.parentPath);
25
32
  maybe.indent.inc(isNewline);
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ module.exports.JSXFragment = {
4
+ condition,
5
+ before(path, {write, indent}) {
6
+ write('(');
7
+ indent.inc();
8
+ write.breakline();
9
+ },
10
+ print(path, {print, traverse}) {
11
+ print('__openingFragment');
12
+ path.get('children').map(traverse);
13
+ print('__closingFragment');
14
+ },
15
+ after(path, {write, indent}) {
16
+ indent.dec();
17
+ write.breakline();
18
+ write(')');
19
+ },
20
+ };
21
+
22
+ module.exports.JSXOpeningFragment = (path, {write}) => {
23
+ write('<>');
24
+ };
25
+
26
+ module.exports.JSXClosingFragment = (path, {write}) => {
27
+ write('</>');
28
+ };
29
+
30
+ function condition(path) {
31
+ if (path.parentPath.isReturnStatement())
32
+ return true;
33
+
34
+ return path.parentPath.isVariableDeclarator();
35
+ }
@@ -14,11 +14,13 @@ function markBefore(path) {
14
14
  function markAfter(path) {
15
15
  path[WATER_MARK_AFTER] = true;
16
16
  }
17
+
17
18
  module.exports.isMarkedAfter = isMarkedAfter;
18
19
 
19
20
  function isMarkedAfter(path) {
20
21
  return path[WATER_MARK_AFTER];
21
22
  }
23
+
22
24
  module.exports.hasPrevNewline = (path) => {
23
25
  return isMarkedAfter(path.getPrevSibling());
24
26
  };
@@ -1,11 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- isNewlineBetweenStatements,
5
- isNext,
6
- } = require('../is');
7
-
8
- const {isMarkedAfter} = require('../mark');
3
+ const {isNext} = require('../is');
9
4
 
10
5
  const notClass = (path) => {
11
6
  if (!isNext(path))
@@ -15,17 +10,6 @@ const notClass = (path) => {
15
10
  };
16
11
 
17
12
  module.exports.ExportDefaultDeclaration = {
18
- beforeIf(path) {
19
- const prev = path.getPrevSibling();
20
-
21
- if (isMarkedAfter(prev))
22
- return false;
23
-
24
- return isNewlineBetweenStatements(prev);
25
- },
26
- before(path, {print}) {
27
- print.newline();
28
- },
29
13
  print(path, {print, traverse, maybe}) {
30
14
  const declaration = path.get('declaration');
31
15
  print('export default ');
@@ -89,6 +89,7 @@ function isNextCoupleLines(path) {
89
89
 
90
90
  return isCoupleLines(next);
91
91
  }
92
+
92
93
  const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
93
94
 
94
95
  function shouldAddNewlineBefore(path) {
@@ -115,6 +116,7 @@ function shouldAddNewlineBefore(path) {
115
116
  function isFirst(path) {
116
117
  return path.node === path.parentPath.node.body?.[0];
117
118
  }
119
+
118
120
  const isNextAssign = (path) => {
119
121
  const nextPath = path.getNextSibling();
120
122
 
@@ -52,6 +52,7 @@ function initFormat(format) {
52
52
  indent: ' ',
53
53
  };
54
54
  }
55
+
55
56
  const createAddToken = (tokens) => {
56
57
  const log = createLog();
57
58
 
@@ -237,6 +238,7 @@ function printIndent(i, indent) {
237
238
 
238
239
  return result;
239
240
  }
241
+
240
242
  const createPrint = (path, {traverse, write}) => (maybeLine) => {
241
243
  if (maybeLine === path)
242
244
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.55.0",
3
+ "version": "1.57.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",