eslint-plugin-putout 12.4.0 → 12.5.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/lib/putout/index.js +25 -12
- package/package.json +1 -1
package/lib/putout/index.js
CHANGED
|
@@ -6,12 +6,10 @@ const {
|
|
|
6
6
|
transform,
|
|
7
7
|
print,
|
|
8
8
|
parse,
|
|
9
|
-
|
|
9
|
+
traverse,
|
|
10
10
|
} = require('putout');
|
|
11
11
|
|
|
12
12
|
const v8 = require('v8');
|
|
13
|
-
const toBabel = require('estree-to-babel');
|
|
14
|
-
const tryCatch = require('try-catch');
|
|
15
13
|
|
|
16
14
|
const parseOptions = require('putout/parse-options');
|
|
17
15
|
|
|
@@ -22,6 +20,7 @@ const getContextOptions = ({options}) => {
|
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
const copyAST = (a) => v8.deserialize(v8.serialize(a));
|
|
23
|
+
const returns = (a) => () => a;
|
|
25
24
|
|
|
26
25
|
module.exports = {
|
|
27
26
|
meta: {
|
|
@@ -51,9 +50,7 @@ module.exports = {
|
|
|
51
50
|
const {text} = source;
|
|
52
51
|
|
|
53
52
|
const ast = parse(text, {
|
|
54
|
-
parser:
|
|
55
|
-
parse: () => toBabel(copyAST(node)),
|
|
56
|
-
},
|
|
53
|
+
parser: createParser(node),
|
|
57
54
|
});
|
|
58
55
|
|
|
59
56
|
const places = findPlaces(ast, text, resultOptions);
|
|
@@ -88,17 +85,33 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
|
|
|
88
85
|
transform(ast, text, resultOptions);
|
|
89
86
|
|
|
90
87
|
const [, last] = lastToken.range;
|
|
91
|
-
const code =
|
|
88
|
+
const code = print(ast);
|
|
92
89
|
|
|
93
90
|
return fixer.replaceTextRange([0, last], code);
|
|
94
91
|
};
|
|
95
92
|
|
|
96
|
-
|
|
97
|
-
const
|
|
93
|
+
const createParser = (node) => {
|
|
94
|
+
const ast = copyAST(node);
|
|
95
|
+
removeParent(ast);
|
|
98
96
|
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
const parser = {
|
|
98
|
+
parse: returns(ast),
|
|
99
|
+
};
|
|
101
100
|
|
|
102
|
-
return
|
|
101
|
+
return parser;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// ESLint adds parent to each node
|
|
105
|
+
// it makes recase go crazy
|
|
106
|
+
// so we better drop them
|
|
107
|
+
//
|
|
108
|
+
// https://github.com/eslint/eslint/blob/v8.4.0/lib/linter/linter.js#L964
|
|
109
|
+
function removeParent(ast) {
|
|
110
|
+
traverse(ast, {
|
|
111
|
+
noScope: true,
|
|
112
|
+
enter(path) {
|
|
113
|
+
delete path.node.parent;
|
|
114
|
+
},
|
|
115
|
+
});
|
|
103
116
|
}
|
|
104
117
|
|