Skip to content

Commit

Permalink
fix(parser): super call should be allowed in private method
Browse files Browse the repository at this point in the history
Also fixed the error message for invalid super call.

closes #203
  • Loading branch information
3cp committed Mar 18, 2022
1 parent 4b24c73 commit 6de707a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/parser.ts
Expand Up @@ -3742,7 +3742,7 @@ export function parseSuperExpression(
case Token.LeftParen: {
// The super property has to be within a class constructor
if ((context & Context.SuperCall) < 1) report(parser, Errors.SuperNoConstructor);
if (context & Context.InClass) report(parser, Errors.UnexpectedPrivateField);
if (context & Context.InClass) report(parser, Errors.InvalidSuperProperty);
parser.assignable = AssignmentKind.CannotAssign;
break;
}
Expand All @@ -3751,7 +3751,7 @@ export function parseSuperExpression(
// new super() is never allowed.
// super() is only allowed in derived constructor
if ((context & Context.SuperProperty) < 1) report(parser, Errors.InvalidSuperProperty);
if (context & Context.InClass) report(parser, Errors.UnexpectedPrivateField);
if (context & Context.InClass) report(parser, Errors.InvalidSuperProperty);
parser.assignable = AssignmentKind.Assignable;
break;
}
Expand Down Expand Up @@ -8299,11 +8299,9 @@ function parseClassElementList(
nextToken(parser, context); // skip: '*'
} else if (context & Context.OptionsNext && parser.token === Token.PrivateField) {
kind |= PropertyKind.PrivateField;
key = parsePrivateIdentifier(parser, context, tokenPos, linePos, colPos);
context = context | Context.InClass;
key = parsePrivateIdentifier(parser, context | Context.InClass, tokenPos, linePos, colPos);
} else if (context & Context.OptionsNext && (parser.token & Token.IsClassField) === Token.IsClassField) {
kind |= PropertyKind.ClassField;
context = context | Context.InClass;
} else if (token === Token.EscapedFutureReserved) {
key = parseIdentifier(parser, context, 0);
if (parser.token !== Token.LeftParen)
Expand Down
4 changes: 3 additions & 1 deletion test/parser/next/private_methods.ts
Expand Up @@ -192,7 +192,9 @@ describe('Next - Private methods', () => {
'foo() { this.#m, (() => this)().#m }',
'foo() { this.#m, (() => this)().#m }',
'foo() { this.#m, (() => this)().#m }',
'method() { super.#x(); }'
'method() { super.#x(); }',
'#method() { super.x(); }',
'#method() { super.#x(); }'
]) {
it(`class C { ${arg} }`, () => {
t.doesNotThrow(() => {
Expand Down

0 comments on commit 6de707a

Please sign in to comment.