flatlint 1.20.0 → 1.21.1
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 +10 -0
- package/lib/compare/collect-args.js +10 -10
- package/lib/compare/collect-array.js +15 -7
- package/lib/compare/collect-expression.js +8 -7
- package/lib/compare/compare.js +7 -3
- package/lib/runner/replacer.js +9 -11
- package/lib/types/types.js +7 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
closeRoundBrace,
|
|
3
|
+
closeSquareBrace,
|
|
4
|
+
NOT_OK,
|
|
5
|
+
OK,
|
|
5
6
|
} from '#types';
|
|
6
7
|
import {equal} from './equal.js';
|
|
7
8
|
|
|
8
|
-
export const collectArgs = ({currentTokenIndex, tokens, nextTemplateToken =
|
|
9
|
+
export const collectArgs = ({currentTokenIndex, tokens, nextTemplateToken = closeRoundBrace}) => {
|
|
9
10
|
const n = tokens.length;
|
|
10
|
-
const brace = Punctuator(']');
|
|
11
11
|
let index = currentTokenIndex;
|
|
12
12
|
|
|
13
|
-
if (equal(tokens[index
|
|
14
|
-
return [
|
|
13
|
+
if (equal(tokens[index], closeRoundBrace))
|
|
14
|
+
return [NOT_OK];
|
|
15
15
|
|
|
16
16
|
for (; index < n; index++) {
|
|
17
17
|
const token = tokens[index];
|
|
18
18
|
|
|
19
|
-
if (equal(token,
|
|
19
|
+
if (equal(token, closeRoundBrace))
|
|
20
20
|
break;
|
|
21
21
|
|
|
22
22
|
if (equal(token, nextTemplateToken))
|
|
23
23
|
break;
|
|
24
24
|
|
|
25
|
-
if (equal(token,
|
|
25
|
+
if (equal(token, closeSquareBrace))
|
|
26
26
|
break;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
return [
|
|
30
|
-
|
|
30
|
+
OK,
|
|
31
31
|
--index,
|
|
32
32
|
];
|
|
33
33
|
};
|
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
closeRoundBrace,
|
|
3
|
+
closeSquareBrace,
|
|
4
|
+
semicolon,
|
|
5
|
+
OK,
|
|
6
|
+
NOT_OK,
|
|
4
7
|
} from '#types';
|
|
5
8
|
import {equal} from './equal.js';
|
|
6
9
|
|
|
7
|
-
export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken =
|
|
10
|
+
export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = semicolon}) => {
|
|
8
11
|
const n = tokens.length;
|
|
9
|
-
const brace = Punctuator(']');
|
|
10
12
|
let index = currentTokenIndex;
|
|
11
13
|
|
|
14
|
+
if (equal(tokens[index], closeSquareBrace))
|
|
15
|
+
return [NOT_OK];
|
|
16
|
+
|
|
12
17
|
for (; index < n; index++) {
|
|
13
18
|
const token = tokens[index];
|
|
14
19
|
|
|
15
|
-
if (equal(token,
|
|
20
|
+
if (equal(token, closeRoundBrace))
|
|
16
21
|
break;
|
|
17
22
|
|
|
18
23
|
if (equal(token, nextTemplateToken))
|
|
19
24
|
break;
|
|
20
25
|
|
|
21
|
-
if (equal(token,
|
|
26
|
+
if (equal(token, closeSquareBrace))
|
|
22
27
|
break;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
return
|
|
30
|
+
return [
|
|
31
|
+
OK,
|
|
32
|
+
--index,
|
|
33
|
+
];
|
|
26
34
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
closeRoundBrace,
|
|
3
|
+
openRoundBrace,
|
|
4
|
+
semicolon,
|
|
5
|
+
} from '#types';
|
|
2
6
|
import {equal} from './equal.js';
|
|
3
7
|
|
|
4
|
-
export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken =
|
|
8
|
+
export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken = semicolon}) => {
|
|
5
9
|
const n = tokens.length;
|
|
6
|
-
const closeBrace = Punctuator(')');
|
|
7
|
-
const openBrace = Punctuator('(');
|
|
8
|
-
const semicolon = Punctuator(';');
|
|
9
10
|
let index = currentTokenIndex;
|
|
10
11
|
|
|
11
12
|
for (; index < n; index++) {
|
|
@@ -17,10 +18,10 @@ export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken
|
|
|
17
18
|
if (equal(token, nextTemplateToken))
|
|
18
19
|
break;
|
|
19
20
|
|
|
20
|
-
if (equal(token,
|
|
21
|
+
if (equal(token, openRoundBrace))
|
|
21
22
|
break;
|
|
22
23
|
|
|
23
|
-
if (equal(token,
|
|
24
|
+
if (equal(token, closeRoundBrace))
|
|
24
25
|
break;
|
|
25
26
|
}
|
|
26
27
|
|
package/lib/compare/compare.js
CHANGED
|
@@ -64,15 +64,19 @@ export const compare = (source, template) => {
|
|
|
64
64
|
delta = indexOfExpressionEnd - currentTokenIndex;
|
|
65
65
|
index = indexOfExpressionEnd - templateIndex;
|
|
66
66
|
} else if (isTemplateArrayToken(templateToken)) {
|
|
67
|
-
const indexOfArrayEnd = collectArray({
|
|
67
|
+
const [ok, indexOfArrayEnd] = collectArray({
|
|
68
68
|
currentTokenIndex,
|
|
69
69
|
tokens,
|
|
70
70
|
templateToken,
|
|
71
71
|
nextTemplateToken: templateTokens[templateIndex + 1],
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
if (!ok) {
|
|
75
|
+
++skip;
|
|
76
|
+
} else {
|
|
77
|
+
delta = indexOfArrayEnd - currentTokenIndex;
|
|
78
|
+
index = indexOfArrayEnd - templateIndex;
|
|
79
|
+
}
|
|
76
80
|
} else if (!compareAll(currentToken, templateToken)) {
|
|
77
81
|
isEqual = false;
|
|
78
82
|
break;
|
package/lib/runner/replacer.js
CHANGED
|
@@ -113,29 +113,27 @@ function getValues(tokens, waysFrom) {
|
|
|
113
113
|
|
|
114
114
|
for (const [name, index] of entries(waysFrom)) {
|
|
115
115
|
let end = index;
|
|
116
|
+
let ok = true;
|
|
116
117
|
|
|
117
|
-
if (isTemplateArray(name))
|
|
118
|
-
end = collectArray({
|
|
118
|
+
if (isTemplateArray(name))
|
|
119
|
+
[ok, end] = collectArray({
|
|
119
120
|
currentTokenIndex: index,
|
|
120
121
|
tokens,
|
|
121
122
|
});
|
|
122
|
-
|
|
123
|
+
else if (isTemplateExpression(name))
|
|
123
124
|
end = collectExpression({
|
|
124
125
|
currentTokenIndex: index,
|
|
125
126
|
tokens,
|
|
126
127
|
});
|
|
127
|
-
|
|
128
|
-
let ok = false;
|
|
129
|
-
|
|
128
|
+
else if (isTemplateArgs(name))
|
|
130
129
|
[ok, end] = collectArgs({
|
|
131
130
|
currentTokenIndex: index,
|
|
132
131
|
tokens,
|
|
133
132
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
133
|
+
|
|
134
|
+
if (!ok) {
|
|
135
|
+
values[name] = [];
|
|
136
|
+
continue;
|
|
139
137
|
}
|
|
140
138
|
|
|
141
139
|
values[name] = tokens.slice(index, end + 1);
|
package/lib/types/types.js
CHANGED
|
@@ -67,5 +67,10 @@ export const isTemplateArrayToken = (a) => isIdentifier(a) && isTemplateArray(a.
|
|
|
67
67
|
export const isTemplateExpressionToken = (a) => isIdentifier(a) && isTemplateExpression(a.value);
|
|
68
68
|
export const isTemplateArgsToken = (a) => isIdentifier(a) && isTemplateArgs(a.value);
|
|
69
69
|
|
|
70
|
-
export const
|
|
71
|
-
export const
|
|
70
|
+
export const openRoundBrace = Punctuator('(');
|
|
71
|
+
export const closeRoundBrace = Punctuator(')');
|
|
72
|
+
export const closeSquareBrace = Punctuator(']');
|
|
73
|
+
export const semicolon = Punctuator(';');
|
|
74
|
+
|
|
75
|
+
export const OK = true;
|
|
76
|
+
export const NOT_OK = false;
|