Merge pull request #589 from Qantas94Heavy/fix-private-fields
Add delete check and fix nested class parsing for private fields
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");
|
||||
|
||||
@@ -684,7 +684,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
// class bodies are implicitly strict
|
||||
const oldStrict = this.state.strict;
|
||||
this.state.strict = true;
|
||||
this.state.inClass = true;
|
||||
this.state.classLevel++;
|
||||
|
||||
const state = { hadConstructor: false };
|
||||
let decorators = [];
|
||||
@@ -731,7 +731,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
node.body = this.finishNode(classBody, "ClassBody");
|
||||
|
||||
this.state.inClass = false;
|
||||
this.state.classLevel--;
|
||||
this.state.strict = oldStrict;
|
||||
}
|
||||
|
||||
|
||||
@@ -444,7 +444,7 @@ export default class Tokenizer extends LocationParser {
|
||||
switch (code) {
|
||||
|
||||
case 35: // '#'
|
||||
if (this.hasPlugin("classPrivateProperties") && this.state.inClass) {
|
||||
if (this.hasPlugin("classPrivateProperties") && this.state.classLevel > 0) {
|
||||
++this.state.pos; return this.finishToken(tt.hash);
|
||||
} else {
|
||||
this.raise(this.state.pos, `Unexpected character '${codePointToString(code)}'`);
|
||||
|
||||
@@ -24,11 +24,12 @@ export default class State {
|
||||
this.inAsync =
|
||||
this.inPropertyName =
|
||||
this.inType =
|
||||
this.inClass =
|
||||
this.inClassProperty =
|
||||
this.noAnonFunctionType =
|
||||
false;
|
||||
|
||||
this.classLevel = 0;
|
||||
|
||||
this.labels = [];
|
||||
|
||||
this.decorators = [];
|
||||
@@ -84,7 +85,9 @@ export default class State {
|
||||
noAnonFunctionType: boolean;
|
||||
inPropertyName: boolean;
|
||||
inClassProperty: boolean;
|
||||
inClass: boolean;
|
||||
|
||||
// Check whether we are in a (nested) class or not.
|
||||
classLevel: number;
|
||||
|
||||
// Labels in scope.
|
||||
labels: Array<{ kind: ?("loop" | "switch"), statementStart?: number }>;
|
||||
|
||||
Reference in New Issue
Block a user