Throw on attempt to delete a private field
Given that private fields can only be used within classes, any code using them must be in a strict mode context. As private fields cannot be deleted, throw an early SyntaxError.
This commit is contained in:
@@ -252,8 +252,16 @@ export default class ExpressionParser extends LValParser {
|
||||
|
||||
if (update) {
|
||||
this.checkLVal(node.argument, undefined, undefined, "prefix operation");
|
||||
} else if (this.state.strict && node.operator === "delete" && node.argument.type === "Identifier") {
|
||||
this.raise(node.start, "Deleting local variable in strict mode");
|
||||
} else if (this.state.strict && node.operator === "delete") {
|
||||
const arg = node.argument;
|
||||
|
||||
if (arg.type === "Identifier") {
|
||||
this.raise(node.start, "Deleting local variable in strict mode");
|
||||
} else if (this.hasPlugin("classPrivateProperties")) {
|
||||
if (arg.type === "PrivateName" || (arg.type === "MemberExpression" && arg.property.type === "PrivateName")) {
|
||||
this.raise(node.start, "Deleting a private field is not allowed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
|
||||
|
||||
Reference in New Issue
Block a user