@putout/printer 1.8.1 → 1.8.3

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.03.26, v1.8.3
2
+
3
+ feature:
4
+ - fec7aee @putout/printer: improve support of ObjectExpression inside LogicalExpression inside SpreadElement property of ObjectExpression
5
+
6
+ 2023.03.26, v1.8.2
7
+
8
+ feature:
9
+ - 5d25d59 @putout/printer: add support of ConditionalExpression
10
+
1
11
  2023.03.26, v1.8.1
2
12
 
3
13
  feature:
@@ -3,24 +3,7 @@
3
3
  module.exports.cook = (tokens) => {
4
4
  const cookedTokens = [];
5
5
 
6
- for (const [i, {
7
- value,
8
- }] of tokens.entries()) {
9
- /*
10
- if (type !== TYPES.TOKEN)
11
- console.log(type);
12
-
13
- if (type === TYPES.NEWLINE && next?.type === TYPES.LINEBREAK) {
14
- console.log('[skipped]');
15
- continue;
16
- }
17
-
18
- if (type === TYPES.LINEBREAK && next?.type === TYPES.LINEBREAK) {
19
- console.log('[skipped]');
20
- continue;
21
- }
22
- */
23
-
6
+ for (const [i, {value}] of tokens.entries()) {
24
7
  cookedTokens.push(value);
25
8
  }
26
9
 
@@ -25,6 +25,10 @@ function CallExpression(path, {indent, print, maybe}) {
25
25
  }
26
26
 
27
27
  print('__callee');
28
+
29
+ if (path.node.optional)
30
+ print('?.');
31
+
28
32
  print('(');
29
33
 
30
34
  const args = path.get('arguments');
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ module.exports.ConditionalExpression = (path, {print}) => {
4
+ print('__test');
5
+ print.space();
6
+ print('?');
7
+ print.space();
8
+ print('__consequent');
9
+ print.space();
10
+ print(':');
11
+ print.space();
12
+ print('__alternate');
13
+ };
14
+
@@ -24,6 +24,7 @@ const {
24
24
  BinaryExpression,
25
25
  LogicalExpression,
26
26
  } = require('./binary-expression');
27
+ const {ConditionalExpression} = require('./conditional-expression');
27
28
 
28
29
  module.exports = {
29
30
  ...functions,
@@ -36,6 +37,7 @@ module.exports = {
36
37
  BinaryExpression,
37
38
  CallExpression,
38
39
  ClassDeclaration,
40
+ ConditionalExpression,
39
41
  NewExpression,
40
42
  LogicalExpression,
41
43
  OptionalCallExpression,
@@ -2,6 +2,7 @@
2
2
 
3
3
  const {isCoupleLines} = require('../is');
4
4
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
5
+ const isLogical = (path) => path.get('argument').isLogicalExpression();
5
6
  const isForOf = (path) => {
6
7
  if (path.parentPath.isForOfStatement())
7
8
  return true;
@@ -24,7 +25,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
24
25
 
25
26
  for (const property of properties) {
26
27
  if (property.isSpreadElement()) {
27
- maybe.indent(length > 1);
28
+ maybe.indent(length > 1 || isLogical(property));
28
29
  print(property);
29
30
 
30
31
  if (length > 1) {
@@ -60,6 +61,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
60
61
 
61
62
  maybe.indent(manyLines);
62
63
  print('}');
64
+ maybe.print.newline(path.parentPath.isLogicalExpression());
63
65
  maybe.print(parens, ')');
64
66
  };
65
67
  function isOneLine(path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
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",