@putout/printer 8.4.0 → 8.6.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
+ 2024.02.19, v8.6.0
2
+
3
+ feature:
4
+ - c2c749e @putout/printer: export: maybePlugin
5
+
6
+ 2024.02.15, v8.5.0
7
+
8
+ feature:
9
+ - 0270569 @putout/printer: ArrayExpression: couple elements including nesting
10
+
1
11
  2024.02.15, v8.4.0
2
12
 
3
13
  feature:
package/lib/printer.js CHANGED
@@ -4,6 +4,9 @@ const {tokenize} = require('./tokenize/tokenize');
4
4
  const {printTokens} = require('./print-tokens');
5
5
  const {maybeJSON} = require('./json');
6
6
 
7
+ const {maybePlugin} = require('./tokenize/maybe/index');
8
+ const visitors = require('./tokenize/visitors');
9
+
7
10
  module.exports.print = (ast, overrides = {}) => {
8
11
  const options = maybeJSON(ast, overrides);
9
12
  const tokens = tokenize(ast, options);
@@ -11,4 +14,5 @@ module.exports.print = (ast, overrides = {}) => {
11
14
  return printTokens(tokens);
12
15
  };
13
16
 
14
- module.exports.visitors = require('./tokenize/visitors');
17
+ module.exports.visitors = visitors;
18
+ module.exports.maybePlugin = maybePlugin;
@@ -27,6 +27,8 @@ const {
27
27
  } = types;
28
28
 
29
29
  const isNextString = (path) => isStringLiteral(path.getNextSibling());
30
+ const isPrevString = (path) => isStringLiteral(path.getPrevSibling());
31
+ const isAroundStrings = (path) => isNextString(path) || isPrevString(path);
30
32
  const isNextObject = (a) => a.getNextSibling().isObjectExpression();
31
33
  const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
32
34
  const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
@@ -52,7 +54,7 @@ module.exports.ArrayExpression = {
52
54
  before(path, {print}) {
53
55
  print.breakline();
54
56
  },
55
- print(path, {print, maybe, indent}, semantics) {
57
+ print(path, {print, maybe}, semantics) {
56
58
  const {
57
59
  maxElementsInOneLine,
58
60
  trailingComma,
@@ -100,9 +102,12 @@ module.exports.ArrayExpression = {
100
102
  const parentElements = path.parentPath.get('elements');
101
103
 
102
104
  if (isInsideArray(path) && isStringAndArray(parentElements)) {
103
- maybe.indent.dec(!isNextString(path));
105
+ const parentCountTwo = parentElements.length === 2;
106
+ const isHideIdent = !isAroundStrings(path) || parentCountTwo;
107
+
108
+ maybe.indent.dec(isHideIdent);
104
109
  maybe.indent(elements.length && isNewLine);
105
- maybe.indent.inc(!isNextString(path));
110
+ maybe.indent.inc(isHideIdent);
106
111
  } else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
107
112
  maybe.indent(elements.length && isNewLine);
108
113
  }
@@ -130,4 +135,3 @@ module.exports.ArrayExpression = {
130
135
  indent.inc();
131
136
  },
132
137
  };
133
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.4.0",
3
+ "version": "8.6.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",