File tree Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -5777,7 +5777,7 @@ namespace ts {
5777
5777
getIndexInfoOfType(objectType, IndexKind.String) ||
5778
5778
undefined;
5779
5779
if (indexInfo) {
5780
- if (accessExpression && isAssignmentTarget(accessExpression) && indexInfo.isReadonly ) {
5780
+ if (accessExpression && indexInfo.isReadonly && ( isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression)) ) {
5781
5781
error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType));
5782
5782
return unknownType;
5783
5783
}
@@ -13550,9 +13550,16 @@ namespace ts {
13550
13550
13551
13551
function checkDeleteExpression(node: DeleteExpression): Type {
13552
13552
checkExpression(node.expression);
13553
- checkReferenceExpression(node.expression,
13554
- Diagnostics.The_operand_of_a_delete_operator_must_be_a_property_reference,
13555
- Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
13553
+ const expr = skipParentheses(node.expression);
13554
+ if (expr.kind !== SyntaxKind.PropertyAccessExpression && expr.kind !== SyntaxKind.ElementAccessExpression) {
13555
+ error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_a_property_reference);
13556
+ return booleanType;
13557
+ }
13558
+ const links = getNodeLinks(expr);
13559
+ const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol);
13560
+ if (symbol && isReadonlySymbol(symbol)) {
13561
+ error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
13562
+ }
13556
13563
return booleanType;
13557
13564
}
13558
13565
Original file line number Diff line number Diff line change @@ -2651,7 +2651,6 @@ namespace ts {
2651
2651
resolvedType ?: Type ; // Cached type of type node
2652
2652
resolvedSignature ?: Signature ; // Cached signature of signature node or call expression
2653
2653
resolvedSymbol ?: Symbol ; // Cached name resolution result
2654
- resolvedIndexInfo ?: IndexInfo ; // Cached indexing info resolution result
2655
2654
enumMemberValue ?: number ; // Constant value of enum member
2656
2655
isVisible ?: boolean ; // Is this node visible
2657
2656
hasReportedStatementInAmbientContext ?: boolean ; // Cache boolean if we report statements in ambient context
Original file line number Diff line number Diff line change 1
- /// <reference path="sys.ts" />
1
+ /// <reference path="sys.ts" />
2
2
3
3
/* @internal */
4
4
namespace ts {
@@ -1666,6 +1666,18 @@ namespace ts {
1666
1666
return getAssignmentTargetKind ( node ) !== AssignmentKind . None ;
1667
1667
}
1668
1668
1669
+ // a node is delete target iff. it is PropertyAccessExpression/ElementAccessExpression with parentheses skipped
1670
+ export function isDeleteTarget ( node : Node ) : boolean {
1671
+ if ( node . kind !== SyntaxKind . PropertyAccessExpression && node . kind !== SyntaxKind . ElementAccessExpression ) {
1672
+ return false ;
1673
+ }
1674
+ node = node . parent ;
1675
+ while ( node && node . kind === SyntaxKind . ParenthesizedExpression ) {
1676
+ node = node . parent ;
1677
+ }
1678
+ return node && node . kind === SyntaxKind . DeleteExpression ;
1679
+ }
1680
+
1669
1681
export function isNodeDescendantOf ( node : Node , ancestor : Node ) : boolean {
1670
1682
while ( node ) {
1671
1683
if ( node === ancestor ) return true ;
You can’t perform that action at this time.
0 commit comments