Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'super' usage in arrow functions. #30

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions dist/meriyah.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -6266,17 +6266,19 @@
case 67174411: {
if ((context & 524288) === 0)
report(parser, 26);
if (context & 16384)
if (context & 16384 && !(context & 33554432)) {
report(parser, 27);
}
parser.assignable = 2;
break;
}
case 69271571:
case 67108877: {
if ((context & 262144) === 0)
report(parser, 27);
if (context & 16384)
if (context & 16384 && !(context & 33554432)) {
report(parser, 27);
}
parser.assignable = 1;
break;
}
Expand Down Expand Up @@ -6313,6 +6315,11 @@
switch (parser.token) {
case 67108877: {
nextToken(parser, (context | 1073741824 | 8192) ^ 8192);
if (context & 16384 &&
(parser.token & 131) === 131 &&
parser.tokenValue === 'super') {
report(parser, 27);
}
parser.assignable = 1;
const property = parsePropertyOrPrivatePropertyName(parser, context | 65536);
expr = finishNode(parser, context, start, line, column, {
Expand Down Expand Up @@ -8023,7 +8030,7 @@
reportScopeError(scope.scopeError);
}
if (expression) {
body = parseExpression(parser, context, 1, 0, 0, parser.tokenPos, parser.linePos, parser.colPos);
body = parseExpression(parser, context & 16384 ? context | 33554432 : context, 1, 0, 0, parser.tokenPos, parser.linePos, parser.colPos);
}
else {
if (scope)
Expand Down Expand Up @@ -8695,6 +8702,13 @@
const { tokenPos, linePos, colPos } = parser;
if (parser.token === 537079928)
report(parser, 116);
const modifierFlags = (state & 64) === 0
? 31981568
: 14680064;
context =
((context | modifierFlags) ^ modifierFlags) |
((state & 88) << 18) |
100925440;
value = parsePrimaryExpression(parser, context | 16384, 2, 0, 1, 0, 0, 1, tokenPos, linePos, colPos);
if ((parser.token & 1073741824) !== 1073741824 ||
(parser.token & 4194304) === 4194304) {
Expand Down
37 changes: 34 additions & 3 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3916,7 +3916,9 @@ export function parseSuperExpression(
case Token.LeftParen: {
// The super property has to be within a class constructor
if ((context & Context.SuperCall) === 0) report(parser, Errors.SuperNoConstructor);
if (context & Context.InClass) report(parser, Errors.InvalidSuperProperty);
if (context & Context.InClass && !(context & Context.InMethod)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why the optional chaining operator is not used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because here the bitwise AND & is used or am I missing something?

report(parser, Errors.InvalidSuperProperty);
}
parser.assignable = AssignmentKind.CannotAssign;
break;
}
Expand All @@ -3925,7 +3927,9 @@ export function parseSuperExpression(
// new super() is never allowed.
// super() is only allowed in derived constructor
if ((context & Context.SuperProperty) === 0) report(parser, Errors.InvalidSuperProperty);
if (context & Context.InClass) report(parser, Errors.InvalidSuperProperty);
if (context & Context.InClass && !(context & Context.InMethod)) {
report(parser, Errors.InvalidSuperProperty);
}
parser.assignable = AssignmentKind.Assignable;
break;
}
Expand Down Expand Up @@ -4041,6 +4045,14 @@ export function parseMemberOrUpdateExpression(
case Token.Period: {
nextToken(parser, (context | Context.AllowEscapedKeyword | Context.InGlobal) ^ Context.InGlobal);

if (
context & Context.InClass &&
(parser.token & Token.PrivateField) === Token.PrivateField &&
parser.tokenValue === 'super'
) {
report(parser, Errors.InvalidSuperProperty);
}

parser.assignable = AssignmentKind.Assignable;

const property = parsePropertyOrPrivatePropertyName(parser, context | Context.TaggedTemplate);
Expand Down Expand Up @@ -7347,7 +7359,16 @@ export function parseArrowFunctionExpression(

if (expression) {
// Single-expression body
body = parseExpression(parser, context, 1, 0, 0, parser.tokenPos, parser.linePos, parser.colPos);
body = parseExpression(
parser,
context & Context.InClass ? context | Context.InMethod : context,
1,
0,
0,
parser.tokenPos,
parser.linePos,
parser.colPos
);
} else {
if (scope) scope = addChildScope(scope, ScopeKind.FunctionBody);

Expand Down Expand Up @@ -8704,6 +8725,16 @@ export function parsePropertyDefinition(

if (parser.token === Token.Arguments) report(parser, Errors.StrictEvalArguments);

const modifierFlags =
(state & PropertyKind.Constructor) === 0
? 0b0000001111010000000_0000_00000000
: 0b0000000111000000000_0000_00000000;

context =
((context | modifierFlags) ^ modifierFlags) |
((state & 0b0000000000000000000_0000_01011000) << 18) |
0b0000110000001000000_0000_00000000;
ypapouski marked this conversation as resolved.
Show resolved Hide resolved

value = parsePrimaryExpression(
parser,
context | Context.InClass,
Expand Down
Loading
Loading