@putout/printer 1.2.0 → 1.3.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.
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ module.exports.RestElement = (path, {write, traverse}) => {
4
+ write('...');
5
+ traverse(path.get('argument'));
6
+ };
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ module.exports.SpreadElement = (path, {write, traverse}) => {
4
+ write('...');
5
+ traverse(path.get('argument'));
6
+ };
@@ -13,6 +13,8 @@ const {AssignmentExpression} = require('./assignment-expression');
13
13
  const {ArrayExpression} = require('./array-expression');
14
14
  const {ArrayPattern} = require('./array-pattern');
15
15
  const {AssignmentPattern} = require('./assignment-pattern');
16
+ const {RestElement} = require('./RestElement');
17
+ const {SpreadElement} = require('./SpreadElement');
16
18
 
17
19
  module.exports = {
18
20
  ...functions,
@@ -27,6 +29,8 @@ module.exports = {
27
29
  NewExpression,
28
30
  ObjectExpression,
29
31
  ObjectPattern,
32
+ RestElement,
33
+ SpreadElement,
30
34
  BinaryExpression(path, {traverse, write}) {
31
35
  traverse(path.get('left'));
32
36
  write(` ${path.node.operator} `);
@@ -1,7 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
4
- const isForOf = (path) => path.parentPath?.parentPath?.isForOfStatement();
4
+ const isForOf = (path) => {
5
+ if (path.parentPath.isForOfStatement())
6
+ return true;
7
+
8
+ if (path.parentPath?.parentPath?.isForOfStatement())
9
+ return true;
10
+
11
+ return false;
12
+ };
5
13
 
6
14
  module.exports.ObjectExpression = (path, {traverse, write, maybeWrite, maybeIndent, incIndent, decIndent}) => {
7
15
  incIndent();
@@ -17,6 +25,11 @@ module.exports.ObjectExpression = (path, {traverse, write, maybeWrite, maybeInde
17
25
  maybeWrite(!isOneLine, '\n');
18
26
 
19
27
  for (const property of properties) {
28
+ if (property.isSpreadElement()) {
29
+ traverse(property);
30
+ continue;
31
+ }
32
+
20
33
  const {shorthand, computed} = property.node;
21
34
 
22
35
  maybeIndent(!isOneLine);
@@ -2,7 +2,6 @@
2
2
 
3
3
  const {entries} = Object;
4
4
  const isForOf = (path) => path.parentPath?.parentPath?.parentPath?.isForOfStatement();
5
- const isAssign = (path) => path.isAssignmentPattern();
6
5
 
7
6
  module.exports.ObjectPattern = (path, {traverse, maybeIndent, write, maybeWrite, incIndent, decIndent}) => {
8
7
  incIndent();
@@ -16,6 +15,11 @@ module.exports.ObjectPattern = (path, {traverse, maybeIndent, write, maybeWrite,
16
15
  maybeWrite(is, '\n');
17
16
 
18
17
  for (const [i, property] of entries(properties)) {
18
+ if (property.isRestElement()) {
19
+ traverse(property);
20
+ continue;
21
+ }
22
+
19
23
  const valuePath = property.get('value');
20
24
  const keyPath = property.get('key');
21
25
  const {shorthand} = property.node;
@@ -28,7 +32,7 @@ module.exports.ObjectPattern = (path, {traverse, maybeIndent, write, maybeWrite,
28
32
  traverse(valuePath);
29
33
  }
30
34
 
31
- if (isAssign(valuePath))
35
+ if (valuePath.isAssignmentPattern())
32
36
  traverse(valuePath);
33
37
 
34
38
  if (is) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.2.0",
3
+ "version": "1.3.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",