Skip to content

Commit 42f04d7

Browse files
gkzAndyPengc12
authored andcommitted
Support Flow as expressions in ESLint rules (facebook#27590)
Support Flow `as` expressions in ESLint rules, e.g. `<expr> as <type>`. This is the same syntax as TypeScript as expressions. I just looked for any place referencing `TSAsExpression` (the TS node) or `TypeCastExpression` (the previous Flow syntax) and added a case for `AsExpression` as well.
1 parent 5549802 commit 42f04d7

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export default {
177177
if (init == null) {
178178
return false;
179179
}
180-
while (init.type === 'TSAsExpression') {
180+
while (init.type === 'TSAsExpression' || init.type === 'AsExpression') {
181181
init = init.expression;
182182
}
183183
// Detect primitive constants
@@ -1525,7 +1525,7 @@ function getConstructionExpressionType(node) {
15251525
}
15261526
return null;
15271527
case 'TypeCastExpression':
1528-
return getConstructionExpressionType(node.expression);
1528+
case 'AsExpression':
15291529
case 'TSAsExpression':
15301530
return getConstructionExpressionType(node.expression);
15311531
}

scripts/eslint-rules/safe-string-coercion.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,11 @@ function checkBinaryExpression(context, node) {
291291
(isEmptyLiteral(node.left) || isEmptyLiteral(node.right))
292292
) {
293293
let valueToTest = isEmptyLiteral(node.left) ? node.right : node.left;
294-
if (valueToTest.type === 'TypeCastExpression' && valueToTest.expression) {
294+
if (
295+
(valueToTest.type === 'TypeCastExpression' ||
296+
valueToTest.type === 'AsExpression') &&
297+
valueToTest.expression
298+
) {
295299
valueToTest = valueToTest.expression;
296300
}
297301

0 commit comments

Comments
 (0)