Skip to content

Commit a42f239

Browse files
rerobikazherczeg
authored andcommitted
Fix super keyword parsing for arrow functions. (#2664)
This patch fixes #2657. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 858c3e6 commit a42f239

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
14121412
{
14131413
if ((lexer_check_next_character (context_p, LIT_CHAR_DOT)
14141414
|| lexer_check_next_character (context_p, LIT_CHAR_LEFT_SQUARE))
1415-
&& context_p->status_flags & (PARSER_CLASS_HAS_SUPER | PARSER_IS_ARROW_FUNCTION))
1415+
&& context_p->status_flags & (PARSER_CLASS_HAS_SUPER))
14161416
{
14171417
if (!LEXER_IS_BINARY_LVALUE_TOKEN (context_p->stack_top_uint8))
14181418
{
@@ -1437,9 +1437,8 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
14371437
}
14381438

14391439
if (lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN)
1440-
&& (context_p->status_flags & PARSER_CLASS_HAS_SUPER)
1441-
&& !(context_p->status_flags & PARSER_CLASS_IMPLICIT_SUPER)
1442-
&& (context_p->status_flags & (PARSER_IS_ARROW_FUNCTION | PARSER_CLASS_CONSTRUCTOR)))
1440+
&& ((context_p->status_flags & PARSER_CLASS_CONSTRUCTOR_SUPER) == PARSER_CLASS_CONSTRUCTOR_SUPER)
1441+
&& !(context_p->status_flags & PARSER_CLASS_IMPLICIT_SUPER))
14431442
{
14441443
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_CONSTRUCTOR_SUPER);
14451444
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)