Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

feat(ts/analyzer): delete operand must be optional #142

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}