@putout/printer 1.61.0 → 1.62.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.20, v1.62.0
2
+
3
+ feature:
4
+ - 7cebd86 @putout/printer: improve support of JSXText
5
+
6
+ 2023.04.20, v1.61.1
7
+
8
+ feature:
9
+ - 69575cb @putout/printer: newlines
10
+
1
11
  2023.04.20, v1.61.0
2
12
 
3
13
  feature:
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {isNext} = require('../is');
4
+ const {markAfter} = require('../mark');
4
5
 
5
6
  module.exports.ClassExpression = classVisitor;
6
7
  module.exports.ClassDeclaration = classVisitor;
@@ -16,6 +17,8 @@ module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => {
16
17
 
17
18
  if (!path.parentPath.isExportDeclaration() && isNext(path)) {
18
19
  write.newline();
20
+ write.newline();
21
+ markAfter(path);
19
22
  }
20
23
  };
21
24
 
@@ -2,20 +2,8 @@
2
2
 
3
3
  const {markAfter} = require('../../mark');
4
4
  const {isNext} = require('../../is');
5
- const isFirst = (path) => !path.getPrevSibling().node;
6
5
 
7
6
  module.exports.FunctionDeclaration = {
8
- beforeIf(path) {
9
- if (isFirst(path))
10
- return false;
11
-
12
- const prev = path.getPrevSibling();
13
-
14
- return prev.isClassDeclaration();
15
- },
16
- before(path, {write}) {
17
- write.newline();
18
- },
19
7
  print(path, {print, maybe}) {
20
8
  const {async} = path.node;
21
9
 
@@ -5,12 +5,14 @@ const {JSXAttribute} = require('./jsx-attribute');
5
5
  const {isCoupleLines} = require('../is');
6
6
  const {JSXOpeningElement} = require('./jsx-opening-element');
7
7
  const fragments = require('./jsx-fragment');
8
+ const {JSXText} = require('./jsx-text');
8
9
 
9
10
  module.exports = {
10
11
  ...fragments,
11
12
  JSXElement,
12
13
  JSXAttribute,
13
14
  JSXOpeningElement,
15
+ JSXText,
14
16
  JSXExpressionContainer(path, {print}) {
15
17
  print('{');
16
18
  print('__expression');
@@ -19,10 +21,6 @@ module.exports = {
19
21
  JSXIdentifier(path, {write}) {
20
22
  write(path.node.name);
21
23
  },
22
- JSXText(path, {write}) {
23
- const {value} = path.node;
24
- write(value);
25
- },
26
24
  JSXMemberExpression(path, {print}) {
27
25
  print('__object');
28
26
  print('.');
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const {isNext} = require('../is');
4
+
5
+ module.exports.JSXText = (path, {write, indent}) => {
6
+ const {value} = path.node;
7
+ const isSpacesOnly = /^\s+$/.test(value);
8
+ const hasNext = isNext(path);
9
+
10
+ if (isSpacesOnly && hasNext) {
11
+ indent.inc();
12
+ write.newline();
13
+ write.indent();
14
+ indent.dec();
15
+
16
+ return;
17
+ }
18
+
19
+ if (isSpacesOnly) {
20
+ write.newline();
21
+ write.indent();
22
+
23
+ return;
24
+ }
25
+
26
+ write(value);
27
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.61.0",
3
+ "version": "1.62.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",