Skip to content

Commit 6a386a2

Browse files
authored
Merge pull request #210 from meriyah/fix-private-super
fix(parser): super call should be allowed in private method
2 parents 4b24c73 + 6de707a commit 6a386a2

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/parser.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,7 +3742,7 @@ export function parseSuperExpression(
37423742
case Token.LeftParen: {
37433743
// The super property has to be within a class constructor
37443744
if ((context & Context.SuperCall) < 1) report(parser, Errors.SuperNoConstructor);
3745-
if (context & Context.InClass) report(parser, Errors.UnexpectedPrivateField);
3745+
if (context & Context.InClass) report(parser, Errors.InvalidSuperProperty);
37463746
parser.assignable = AssignmentKind.CannotAssign;
37473747
break;
37483748
}
@@ -3751,7 +3751,7 @@ export function parseSuperExpression(
37513751
// new super() is never allowed.
37523752
// super() is only allowed in derived constructor
37533753
if ((context & Context.SuperProperty) < 1) report(parser, Errors.InvalidSuperProperty);
3754-
if (context & Context.InClass) report(parser, Errors.UnexpectedPrivateField);
3754+
if (context & Context.InClass) report(parser, Errors.InvalidSuperProperty);
37553755
parser.assignable = AssignmentKind.Assignable;
37563756
break;
37573757
}
@@ -8299,11 +8299,9 @@ function parseClassElementList(
82998299
nextToken(parser, context); // skip: '*'
83008300
} else if (context & Context.OptionsNext && parser.token === Token.PrivateField) {
83018301
kind |= PropertyKind.PrivateField;
8302-
key = parsePrivateIdentifier(parser, context, tokenPos, linePos, colPos);
8303-
context = context | Context.InClass;
8302+
key = parsePrivateIdentifier(parser, context | Context.InClass, tokenPos, linePos, colPos);
83048303
} else if (context & Context.OptionsNext && (parser.token & Token.IsClassField) === Token.IsClassField) {
83058304
kind |= PropertyKind.ClassField;
8306-
context = context | Context.InClass;
83078305
} else if (token === Token.EscapedFutureReserved) {
83088306
key = parseIdentifier(parser, context, 0);
83098307
if (parser.token !== Token.LeftParen)

test/parser/next/private_methods.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ describe('Next - Private methods', () => {
192192
'foo() { this.#m, (() => this)().#m }',
193193
'foo() { this.#m, (() => this)().#m }',
194194
'foo() { this.#m, (() => this)().#m }',
195-
'method() { super.#x(); }'
195+
'method() { super.#x(); }',
196+
'#method() { super.x(); }',
197+
'#method() { super.#x(); }'
196198
]) {
197199
it(`class C { ${arg} }`, () => {
198200
t.doesNotThrow(() => {

0 commit comments

Comments
 (0)