@putout/printer 1.55.0 → 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,8 @@
1
+ 2023.04.19, v1.56.0
2
+
3
+ feature:
4
+ - aaf4886 @putout/printer: add support of JSXFragment
5
+
1
6
  2023.04.18, v1.55.0
2
7
 
3
8
  fix:
@@ -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
  };
@@ -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 ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.55.0",
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",