Skip to content

Commit 32962f0

Browse files
authored
Fix class/function parsing in single-statement blocks (#3179)
This patch fixes #3151 and fixes #3174. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 07c7eb8 commit 32962f0

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
23382338
case LEXER_KEYW_CLASS:
23392339
{
23402340
parser_parse_class (context_p, true);
2341-
continue;
2341+
goto consume_last_statement;
23422342
}
23432343
#endif /* ENABLED (JERRY_ES2015_CLASS) */
23442344

@@ -2359,7 +2359,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
23592359
case LEXER_KEYW_FUNCTION:
23602360
{
23612361
parser_parse_function_statement (context_p);
2362-
continue;
2362+
goto consume_last_statement;
23632363
}
23642364

23652365
case LEXER_KEYW_IF:
@@ -2665,6 +2665,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
26652665
parser_raise_error (context_p, PARSER_ERR_SEMICOLON_EXPECTED);
26662666
}
26672667

2668+
consume_last_statement:
26682669
while (true)
26692670
{
26702671
switch (context_p->stack_top_uint8)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
do class $ { } while (0);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
if ($)
16+
function $ ( ) { };
17+
else if ( b ) c
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
do function $ ( ) { } while (0);

0 commit comments

Comments
 (0)