@putout/plugin-for-of 12.7.0 → 12.7.2
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.
|
@@ -5,7 +5,11 @@ const {
|
|
|
5
5
|
isObjectProperty,
|
|
6
6
|
} = types;
|
|
7
7
|
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
remove,
|
|
10
|
+
createTypeChecker,
|
|
11
|
+
} = operator;
|
|
12
|
+
|
|
9
13
|
const getValue = ({value}) => value;
|
|
10
14
|
|
|
11
15
|
export const report = (path) => {
|
|
@@ -29,9 +33,24 @@ function matchForOf(vars, path) {
|
|
|
29
33
|
const idPath = path.get('left.declarations.0.id');
|
|
30
34
|
const elements = getElements(idPath);
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
if (isAllReferenced(idPath, elements))
|
|
37
|
+
return false;
|
|
38
|
+
|
|
39
|
+
return isSupportedForOf(idPath, {
|
|
40
|
+
variables: getVariables(path),
|
|
41
|
+
});
|
|
33
42
|
}
|
|
34
43
|
|
|
44
|
+
const hasOneProperty = ({node}) => node.properties.length === 1;
|
|
45
|
+
const isFullyUnreferenced = ({node}, {variables}) => variables.length === node.properties.length;
|
|
46
|
+
|
|
47
|
+
const isSupportedForOf = createTypeChecker([
|
|
48
|
+
['+: -> !ObjectPattern'],
|
|
49
|
+
['+', hasOneProperty],
|
|
50
|
+
['-', isFullyUnreferenced],
|
|
51
|
+
['+: -> ObjectPattern'],
|
|
52
|
+
]);
|
|
53
|
+
|
|
35
54
|
function replaceForOf(vars, path) {
|
|
36
55
|
const variables = getVariables(path);
|
|
37
56
|
|
|
@@ -20,8 +20,7 @@ const hasAssignment = ({node}) => node.properties.some(isAssignment);
|
|
|
20
20
|
|
|
21
21
|
const isSupportedBinding = createTypeChecker([
|
|
22
22
|
['-: references', '!=', 1],
|
|
23
|
-
['
|
|
24
|
-
['+: -> +'],
|
|
23
|
+
['+: referencePaths.0.parentPath -> VariableDeclarator'],
|
|
25
24
|
]);
|
|
26
25
|
|
|
27
26
|
const isSupportedId = createTypeChecker([
|
package/package.json
CHANGED