mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 00:20:04 +01:00
Support Flow as expressions in ESLint rules (#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.
This commit is contained in:
parent
3eaa0c3871
commit
6bfc0e032a
|
|
@ -177,7 +177,7 @@ export default {
|
|||
if (init == null) {
|
||||
return false;
|
||||
}
|
||||
while (init.type === 'TSAsExpression') {
|
||||
while (init.type === 'TSAsExpression' || init.type === 'AsExpression') {
|
||||
init = init.expression;
|
||||
}
|
||||
// Detect primitive constants
|
||||
|
|
@ -1525,7 +1525,7 @@ function getConstructionExpressionType(node) {
|
|||
}
|
||||
return null;
|
||||
case 'TypeCastExpression':
|
||||
return getConstructionExpressionType(node.expression);
|
||||
case 'AsExpression':
|
||||
case 'TSAsExpression':
|
||||
return getConstructionExpressionType(node.expression);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,7 +291,11 @@ function checkBinaryExpression(context, node) {
|
|||
(isEmptyLiteral(node.left) || isEmptyLiteral(node.right))
|
||||
) {
|
||||
let valueToTest = isEmptyLiteral(node.left) ? node.right : node.left;
|
||||
if (valueToTest.type === 'TypeCastExpression' && valueToTest.expression) {
|
||||
if (
|
||||
(valueToTest.type === 'TypeCastExpression' ||
|
||||
valueToTest.type === 'AsExpression') &&
|
||||
valueToTest.expression
|
||||
) {
|
||||
valueToTest = valueToTest.expression;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user