eslint-plugin-putout 14.6.0 → 14.7.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.
@@ -10,10 +10,6 @@ const {
10
10
  parse,
11
11
  } = require('putout');
12
12
 
13
- const traverse = require('@babel/traverse').default;
14
-
15
- const v8 = require('v8');
16
-
17
13
  const parseOptions = require('putout/parse-options');
18
14
  const {parseError} = require('./parse-error');
19
15
 
@@ -23,9 +19,6 @@ const getContextOptions = ({options}) => {
23
19
  return allContextOptions;
24
20
  };
25
21
 
26
- const copyAST = (a) => v8.deserialize(v8.serialize(a));
27
- const returns = (a) => () => a;
28
-
29
22
  const EMPTY_VISITORS = {};
30
23
 
31
24
  module.exports = {
@@ -54,20 +47,20 @@ module.exports = {
54
47
  const {text} = source;
55
48
  const node = source.ast;
56
49
 
57
- const ast = parse(text, {
58
- parser: createParser(node),
50
+ const [errorParser, ast] = tryCatch(parse, text, {
51
+ isTS: true,
59
52
  });
60
53
 
61
- // remove parent nodes that was ignored before converting to babel
62
- removeParent(ast);
63
-
64
- const [error, places = []] = tryCatch(findPlaces, ast, text, resultOptions);
65
-
66
- if (error)
54
+ if (errorParser) {
67
55
  context.report({
68
- message: `${parseError(error)} (putout)`,
56
+ message: `${parseError(errorParser)} (putout)`,
69
57
  node,
70
58
  });
59
+
60
+ return EMPTY_VISITORS;
61
+ }
62
+
63
+ const places = findPlaces(ast, text, resultOptions);
71
64
 
72
65
  for (const {rule, message, position} of places) {
73
66
  context.report({
@@ -105,34 +98,3 @@ const fix = ({ast, text, node, source, resultOptions}) => (fixer) => {
105
98
  return fixer.replaceTextRange([0, last], code);
106
99
  };
107
100
 
108
- // 1. We cannot modify ESLint AST
109
- // 2. Parent nodes makes Recast go crazy, so they should be removed
110
- // 3. Recast creates original nodes with copies of each nodes
111
- // 4. Parser does nothing but returns original AST before estree to babel
112
- // 5. All this stuff made to gain performance benefit of avoiding a duble parsing: ESLint, and then Babel
113
- // 6. Always can be removed and switched to direct parsing by Putout, when benefits outweight supporting all of this magic
114
- const createParser = (node) => {
115
- const ast = copyAST(node);
116
- removeParent(ast);
117
-
118
- const parser = {
119
- parse: returns(ast),
120
- };
121
-
122
- return parser;
123
- };
124
-
125
- // ESLint adds parent to each node
126
- // it makes recase go crazy
127
- // so we better drop them out
128
- //
129
- // https://github.com/eslint/eslint/blob/v8.4.0/lib/linter/linter.js#L964
130
- function removeParent(ast) {
131
- traverse(ast, {
132
- noScope: true,
133
- enter(path) {
134
- delete path.node.parent;
135
- },
136
- });
137
- }
138
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-putout",
3
- "version": "14.6.0",
3
+ "version": "14.7.0",
4
4
  "type": "commonjs",
5
5
  "description": "eslint plugin for putout",
6
6
  "release": false,