@putout/printer 1.51.0 → 1.52.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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = (plugin) => {
|
|
4
|
+
if (!plugin.afterSatisfy && !plugin.beforeSatisfy)
|
|
5
|
+
return plugin;
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
afterIf: createIf(plugin.afterSatisfy),
|
|
9
|
+
beforeIf: createIf(plugin.beforeSatisfy),
|
|
10
|
+
...plugin,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const createIf = (getConditions) => (path) => {
|
|
15
|
+
const conditions = getConditions?.() || [];
|
|
16
|
+
|
|
17
|
+
for (const condition of conditions) {
|
|
18
|
+
if (condition(path))
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return false;
|
|
23
|
+
};
|
package/lib/tokenize/maybe.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const rendy = require('rendy');
|
|
4
|
+
const maybeSatisfy = require('./maybe/satisfy');
|
|
4
5
|
|
|
5
6
|
const {
|
|
6
7
|
isProgram,
|
|
@@ -22,9 +23,7 @@ module.exports.maybeThrow = (a, path, b) => {
|
|
|
22
23
|
}));
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
const maybeProgram = (ast) => isProgram(ast) ? ast : Program([
|
|
26
|
-
ExpressionStatement(ast),
|
|
27
|
-
]);
|
|
26
|
+
const maybeProgram = (ast) => isProgram(ast) ? ast : Program([ExpressionStatement(ast)]);
|
|
28
27
|
|
|
29
28
|
module.exports.maybeFile = (ast) => isFile(ast) ? ast : File(maybeProgram(ast));
|
|
30
29
|
|
|
@@ -44,7 +43,7 @@ function objectPlugin(plugin, path, printer) {
|
|
|
44
43
|
beforeIf = condition,
|
|
45
44
|
after = split,
|
|
46
45
|
afterIf = condition,
|
|
47
|
-
} = plugin;
|
|
46
|
+
} = maybeSatisfy(plugin);
|
|
48
47
|
|
|
49
48
|
if (beforeIf?.(path, printer)) {
|
|
50
49
|
before(path, printer);
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
isNext,
|
|
5
|
-
isParentProgram,
|
|
6
5
|
isLast,
|
|
7
6
|
isParentBlock,
|
|
8
7
|
isParentLast,
|
|
@@ -21,9 +20,12 @@ module.exports.ExpressionStatement = {
|
|
|
21
20
|
store(true);
|
|
22
21
|
}
|
|
23
22
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
afterSatisfy: () => [
|
|
24
|
+
isParentOrNotLastORParentLast,
|
|
25
|
+
isParentBlock,
|
|
26
|
+
isNext,
|
|
27
|
+
isNextUp,
|
|
28
|
+
],
|
|
27
29
|
after(path, {print, maybe, store}) {
|
|
28
30
|
print.newline();
|
|
29
31
|
maybe.markAfter(store(), path);
|
|
@@ -49,16 +51,11 @@ function shouldBreakline(path) {
|
|
|
49
51
|
return false;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return true;
|
|
58
|
-
|
|
59
|
-
if (isNext(path))
|
|
60
|
-
return true;
|
|
61
|
-
|
|
54
|
+
function isParentOrNotLastORParentLast(path) {
|
|
55
|
+
return isParentBlock(path) || !(isLast(path) || isParentLast(path));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isNextUp(path) {
|
|
62
59
|
return path.findParent(isNext);
|
|
63
60
|
}
|
|
64
61
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.52.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",
|