@putout/printer 1.54.5 → 1.56.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,16 @@
1
+ 2023.04.19, v1.56.0
2
+
3
+ feature:
4
+ - aaf4886 @putout/printer: add support of JSXFragment
5
+
6
+ 2023.04.18, v1.55.0
7
+
8
+ fix:
9
+ - 85dbbd1 @putout/printer: get back satisfy
10
+
11
+ feature:
12
+ - c540dcb @putout/printer: ForOfStatement: add support of Statement inside of body
13
+
1
14
  2023.04.18, v1.54.5
2
15
 
3
16
  feature:
@@ -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
  };
@@ -79,5 +79,8 @@ module.exports.isNewlineBetweenStatements = (path) => {
79
79
 
80
80
  module.exports.satisfy = (conditions) => (path) => {
81
81
  for (const condition of conditions)
82
- return false;
82
+ if (condition(path))
83
+ return true;
84
+
85
+ return false;
83
86
  };
@@ -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,
@@ -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
+ }
@@ -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 ');
@@ -31,21 +31,19 @@ module.exports.ForOfStatement = {
31
31
 
32
32
  const bodyPath = path.get('body');
33
33
 
34
- if (bodyPath.isExpressionStatement()) {
35
- indent.inc();
36
- print.newline();
37
- traverse(bodyPath);
38
- maybe.markAfter(isMarkedAfter(bodyPath), path);
39
- indent.dec();
40
- maybe.print.newline(isNext(path));
41
-
42
- return;
43
- }
44
-
45
34
  if (bodyPath.isBlockStatement()) {
46
35
  print(' ');
47
36
  print('__body');
37
+
38
+ return;
48
39
  }
40
+
41
+ indent.inc();
42
+ print.newline();
43
+ traverse(bodyPath);
44
+ indent.dec();
45
+
46
+ maybe.markAfter(isMarkedAfter(bodyPath), path);
49
47
  },
50
48
  afterIf: isNext,
51
49
  after(path, {print}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.54.5",
3
+ "version": "1.56.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",