@putout/printer 8.30.0 → 8.31.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,9 @@
1
+ 2024.05.03, v8.31.0
2
+
3
+ feature:
4
+ - 5fd0053 @putout/printer: ArrayExpression: is-object-after-simple: simplify
5
+ - 22dae11 @putout/printer: ArrayExpression: is-object-after-simple
6
+
1
7
  2024.05.02, v8.30.0
2
8
 
3
9
  feature:
@@ -7,6 +7,7 @@ const {
7
7
  isIdentifierAndIdentifier,
8
8
  isStringAndArray,
9
9
  isSimpleAndEmptyObject,
10
+ isNextObject,
10
11
  } = require('../../is');
11
12
 
12
13
  const {
@@ -21,46 +22,18 @@ const {
21
22
  isArrayIndented,
22
23
  } = require('./indent');
23
24
 
25
+ const {isObjectAfterSimple} = require('./is-object-after-simple');
26
+
24
27
  const {
25
28
  isObjectExpression,
26
29
  isSpreadElement,
27
30
  isStringLiteral,
28
31
  isIdentifier,
29
- isArrayExpression,
30
- isCallExpression,
31
32
  } = types;
32
33
 
33
34
  const isNextString = (path) => isStringLiteral(path.getNextSibling());
34
35
  const isPrevString = (path) => isStringLiteral(path.getPrevSibling());
35
36
  const isAroundStrings = (path) => isNextString(path) || isPrevString(path);
36
- const isNextObject = (a) => a.getNextSibling().isObjectExpression();
37
- const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
38
- const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
39
- const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
40
-
41
- const isObjectAfterArray = (a) => {
42
- if (!isArrayExpression(a))
43
- return false;
44
-
45
- return isNextObject(a);
46
- };
47
-
48
- const isObjectAfterCall = (a) => {
49
- if (!isCallExpression(a))
50
- return false;
51
-
52
- return isNextObject(a);
53
- };
54
-
55
- const isObjectAfterSimple = (a) => {
56
- if (isObjectAfterArray(a))
57
- return true;
58
-
59
- if (isObjectAfterCall(a))
60
- return true;
61
-
62
- return isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
63
- };
64
37
 
65
38
  const isSpreadBeforeObject = (a) => {
66
39
  if (!a.isObjectExpression())
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const {isNextObject, isPrevObject} = require('../../is');
4
+
5
+ const SIMPLE_TYPES = [
6
+ 'ArrayExpression',
7
+ 'ObjectExpression',
8
+ 'SpreadElement',
9
+ 'CallExpression',
10
+ 'Identifier',
11
+ ];
12
+
13
+ module.exports.isObjectAfterSimple = (a) => {
14
+ const {type} = a;
15
+
16
+ if (!isNextObject(a) || isPrevObject(a))
17
+ return false;
18
+
19
+ return SIMPLE_TYPES.includes(type);
20
+ };
21
+
@@ -34,6 +34,9 @@ const isPrev = (path) => {
34
34
  const isNextParent = (path) => isNext(path.parentPath);
35
35
  const isLast = (path) => isParentProgram(path) && !isNext(path);
36
36
 
37
+ module.exports.isNextObject = (a) => a.getNextSibling().isObjectExpression();
38
+ module.exports.isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
39
+
37
40
  module.exports.isFirst = (path) => path.node === path.parentPath.node.body?.[0];
38
41
  module.exports.isPrevBody = (path) => path.getPrevSibling().isBlockStatement();
39
42
  module.exports.isNext = isNext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.30.0",
3
+ "version": "8.31.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",