mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
migrate checkDelete to new property checking
This commit is contained in:
+11
-4
@@ -5777,7 +5777,7 @@ namespace ts {
|
||||
getIndexInfoOfType(objectType, IndexKind.String) ||
|
||||
undefined;
|
||||
if (indexInfo) {
|
||||
if (accessExpression && isAssignmentTarget(accessExpression) && indexInfo.isReadonly) {
|
||||
if (accessExpression && indexInfo.isReadonly && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) {
|
||||
error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType));
|
||||
return unknownType;
|
||||
}
|
||||
@@ -13550,9 +13550,16 @@ namespace ts {
|
||||
|
||||
function checkDeleteExpression(node: DeleteExpression): Type {
|
||||
checkExpression(node.expression);
|
||||
checkReferenceExpression(node.expression,
|
||||
Diagnostics.The_operand_of_a_delete_operator_must_be_a_property_reference,
|
||||
Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
|
||||
const expr = skipParentheses(node.expression);
|
||||
if (expr.kind !== SyntaxKind.PropertyAccessExpression && expr.kind !== SyntaxKind.ElementAccessExpression) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_a_property_reference);
|
||||
return booleanType;
|
||||
}
|
||||
const links = getNodeLinks(expr);
|
||||
const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol);
|
||||
if (symbol && isReadonlySymbol(symbol)) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
|
||||
}
|
||||
return booleanType;
|
||||
}
|
||||
|
||||
|
||||
@@ -2651,7 +2651,6 @@ namespace ts {
|
||||
resolvedType?: Type; // Cached type of type node
|
||||
resolvedSignature?: Signature; // Cached signature of signature node or call expression
|
||||
resolvedSymbol?: Symbol; // Cached name resolution result
|
||||
resolvedIndexInfo?: IndexInfo; // Cached indexing info resolution result
|
||||
enumMemberValue?: number; // Constant value of enum member
|
||||
isVisible?: boolean; // Is this node visible
|
||||
hasReportedStatementInAmbientContext?: boolean; // Cache boolean if we report statements in ambient context
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/// <reference path="sys.ts" />
|
||||
/// <reference path="sys.ts" />
|
||||
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
@@ -1666,6 +1666,18 @@ namespace ts {
|
||||
return getAssignmentTargetKind(node) !== AssignmentKind.None;
|
||||
}
|
||||
|
||||
// a node is delete target iff. it is PropertyAccessExpression/ElementAccessExpression with parentheses skipped
|
||||
export function isDeleteTarget(node: Node): boolean {
|
||||
if (node.kind !== SyntaxKind.PropertyAccessExpression && node.kind !== SyntaxKind.ElementAccessExpression) {
|
||||
return false;
|
||||
}
|
||||
node = node.parent;
|
||||
while (node && node.kind === SyntaxKind.ParenthesizedExpression) {
|
||||
node = node.parent;
|
||||
}
|
||||
return node && node.kind === SyntaxKind.DeleteExpression;
|
||||
}
|
||||
|
||||
export function isNodeDescendantOf(node: Node, ancestor: Node): boolean {
|
||||
while (node) {
|
||||
if (node === ancestor) return true;
|
||||
|
||||
Reference in New Issue
Block a user