Skip to content

Commit e94fd6e

Browse files
committed
Fix super keyword parsing for arrow functions.
This patch fixes #2657. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 0c20f8e commit e94fd6e

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

jerry-core/parser/js/js-parser-expr.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,6 @@ parser_parse_class (parser_context_t *context_p, /**< context */
560560
{
561561
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_CLASS);
562562

563-
context_p->status_flags &= (uint32_t) ~PARSER_CLASS_HAS_SUPER;
564-
565563
uint16_t class_ident_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS;
566564

567565
if (is_statement)
@@ -1407,7 +1405,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
14071405
{
14081406
if ((lexer_check_next_character (context_p, LIT_CHAR_DOT)
14091407
|| lexer_check_next_character (context_p, LIT_CHAR_LEFT_SQUARE))
1410-
&& context_p->status_flags & (PARSER_CLASS_HAS_SUPER | PARSER_IS_ARROW_FUNCTION))
1408+
&& context_p->status_flags & (PARSER_CLASS_HAS_SUPER))
14111409
{
14121410
if (!LEXER_IS_BINARY_LVALUE_TOKEN (context_p->stack_top_uint8))
14131411
{
@@ -1426,8 +1424,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
14261424
}
14271425

14281426
if (lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)
1429-
&& (context_p->status_flags & PARSER_CLASS_HAS_SUPER)
1430-
&& (context_p->status_flags & (PARSER_IS_ARROW_FUNCTION | PARSER_CLASS_CONSTRUCTOR)))
1427+
&& ((context_p->status_flags & PARSER_CLASS_CONSTRUCTOR_SUPER) == PARSER_CLASS_CONSTRUCTOR_SUPER))
14311428
{
14321429
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_SUPER);
14331430
break;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
try {
16+
eval ("var Mixin1 = (superclass) => class extends super.lass {};");
17+
assert (false);
18+
} catch (e) {
19+
assert (e instanceof SyntaxError);
20+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var mustBeCalled = false;
16+
17+
class C1 {
18+
f () {
19+
mustBeCalled = true;
20+
return function () {};
21+
}
22+
}
23+
24+
class C2 extends C1 {
25+
f () {
26+
return class extends super.f() {}
27+
}
28+
}
29+
30+
var c = new C2;
31+
c.f ();
32+
33+
assert (mustBeCalled);

0 commit comments

Comments
 (0)