@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
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 =
|
|
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
|
|
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
|
-
|
|
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(
|
|
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