Skip to content

Commit

Permalink
feat(ts/analyzer): Detect more non-optional delete operands (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Oct 29, 2022
1 parent 77e9e7e commit 27ad052
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
10 changes: 9 additions & 1 deletion crates/stc_ts_file_analyzer/src/analyzer/expr/unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,15 @@ impl Analyzer<'_, '_> {
..
}) => Err(Error::CannotDeletePrivateProperty { span }),

RExpr::Member(..) => return Ok(()),
RExpr::Member(me) => {
if self.rule().strict_null_checks {
let ty = self.type_of_member_expr(me, TypeOfMode::RValue)?;
if !self.can_be_undefined(span, &ty)? {
return Err(Error::DeleteOperandMustBeOptional { span });
}
}
return Ok(());
}

RExpr::Await(..) => Err(Error::InvalidDeleteOperand { span }),

Expand Down
1 change: 1 addition & 0 deletions crates/stc_ts_type_checker/tests/conformance.pass.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ controlFlow/controlFlowBinaryAndExpression.ts
controlFlow/controlFlowBindingPatternOrder.ts
controlFlow/controlFlowCommaOperator.ts
controlFlow/controlFlowConditionalExpression.ts
controlFlow/controlFlowDeleteOperator.ts
controlFlow/controlFlowDestructuringDeclaration.ts
controlFlow/controlFlowDoWhileStatement.ts
controlFlow/controlFlowElementAccess.ts
Expand Down
6 changes: 3 additions & 3 deletions crates/stc_ts_type_checker/tests/tsc-stats.rust-debug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Stats {
required_error: 4159,
matched_error: 5536,
extra_error: 1024,
required_error: 4158,
matched_error: 5537,
extra_error: 1015,
}

0 comments on commit 27ad052

Please sign in to comment.