@putout/printer 1.61.1 → 1.63.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.21, v1.63.0
2
+
3
+ feature:
4
+ - cceed23 @putout/printer: improve support of AssignmentPattern inside of ObjectProperty
5
+
6
+ 2023.04.20, v1.62.0
7
+
8
+ feature:
9
+ - 7cebd86 @putout/printer: improve support of JSXText
10
+
1
11
  2023.04.20, v1.61.1
2
12
 
3
13
  feature:
@@ -9,6 +9,9 @@ module.exports.AssignmentPattern = (path, {print, maybe}) => {
9
9
  };
10
10
 
11
11
  function shouldPrint(path) {
12
+ if (path.parentPath.isObjectProperty() && !path.parentPath.node.shorthand)
13
+ return true;
14
+
12
15
  if (isArg(path))
13
16
  return true;
14
17
 
@@ -30,9 +30,7 @@ module.exports.ObjectPattern = (path, {indent, print, maybe}) => {
30
30
  if (!shorthand) {
31
31
  print(': ');
32
32
  print(valuePath);
33
- }
34
-
35
- if (isAssign)
33
+ } else if (isAssign)
36
34
  print(valuePath);
37
35
 
38
36
  if (is) {
@@ -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.1",
3
+ "version": "1.63.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",