File tree Expand file tree Collapse file tree 5 files changed +39
-6
lines changed Expand file tree Collapse file tree 5 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -600,7 +600,9 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
600
600
JERRY_ASSERT (context_p -> token .type == LEXER_KEYW_FUNCTION );
601
601
602
602
#if JERRY_ESNEXT
603
- if (JERRY_UNLIKELY (parser_statement_flags [context_p -> stack_top_uint8 ] & PARSER_STATM_SINGLE_STATM ))
603
+ bool is_single_statement = (parser_statement_flags [context_p -> stack_top_uint8 ] & PARSER_STATM_SINGLE_STATM ) != 0 ;
604
+
605
+ if (JERRY_UNLIKELY (is_single_statement ))
604
606
{
605
607
if (context_p -> status_flags & PARSER_IS_STRICT )
606
608
{
@@ -667,6 +669,10 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
667
669
668
670
if (lexer_consume_generator (context_p ))
669
671
{
672
+ if (is_single_statement )
673
+ {
674
+ parser_raise_error (context_p , PARSER_ERR_GENERATOR_IN_SINGLE_STATEMENT_POS );
675
+ }
670
676
is_generator_function = true;
671
677
}
672
678
#endif /* JERRY_ESNEXT */
Original file line number Diff line number Diff line change @@ -1243,6 +1243,10 @@ parser_error_to_string (parser_error_t error) /**< error code */
1243
1243
{
1244
1244
return "Lexical declaration cannot appear in a single-statement context" ;
1245
1245
}
1246
+ case PARSER_ERR_GENERATOR_IN_SINGLE_STATEMENT_POS :
1247
+ {
1248
+ return "Generator function cannot appear in a single-statement context" ;
1249
+ }
1246
1250
case PARSER_ERR_LABELLED_FUNC_NOT_IN_BLOCK :
1247
1251
{
1248
1252
return "Labelled functions are only allowed inside blocks" ;
Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ typedef enum
141
141
#if JERRY_ESNEXT
142
142
PARSER_ERR_VARIABLE_REDECLARED , /**< a variable redeclared */
143
143
PARSER_ERR_LEXICAL_SINGLE_STATEMENT , /**< lexical declaration in single statement context */
144
+ PARSER_ERR_GENERATOR_IN_SINGLE_STATEMENT_POS , /**< generator func not allowed in single statement position */
144
145
PARSER_ERR_LABELLED_FUNC_NOT_IN_BLOCK , /**< labelled functions are only allowed inside blocks */
145
146
PARSER_ERR_LEXICAL_LET_BINDING , /**< let binding cannot be declared in let/const */
146
147
PARSER_ERR_MISSING_ASSIGN_AFTER_CONST , /**< an assignment is required after a const declaration */
Original file line number Diff line number Diff line change
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
+
16
+
17
+ function parse ( txt ) {
18
+ try {
19
+ eval ( txt )
20
+ assert ( false )
21
+ } catch ( e ) {
22
+ assert ( e instanceof SyntaxError )
23
+ }
24
+ }
25
+
26
+ parse ( "if (true) function* g() { }" )
27
+ parse ( "if (false) ; else function* g() { }" )
Original file line number Diff line number Diff line change 365
365
<test id="language/statements/if/cptn-no-else-false.js"><reason></reason></test>
366
366
<test id="language/statements/if/cptn-no-else-true-abrupt-empty.js"><reason></reason></test>
367
367
<test id="language/statements/if/cptn-no-else-true-nrml.js"><reason></reason></test>
368
- <test id="language/statements/if/if-gen-else-gen.js"><reason></reason></test>
369
- <test id="language/statements/if/if-gen-else-stmt.js"><reason></reason></test>
370
- <test id="language/statements/if/if-gen-no-else.js"><reason></reason></test>
371
- <test id="language/statements/if/if-stmt-else-gen.js"><reason></reason></test>
372
368
<test id="language/statements/if/let-block-with-newline.js"><reason></reason></test>
373
369
<test id="language/statements/if/let-identifier-with-newline.js"><reason></reason></test>
374
- <test id="language/statements/labeled/decl-gen.js"><reason></reason></test>
375
370
<test id="language/statements/labeled/let-block-with-newline.js"><reason></reason></test>
376
371
<test id="language/statements/labeled/let-identifier-with-newline.js"><reason></reason></test>
377
372
<test id="language/statements/let/syntax/let-newline-yield-in-generator-function.js"><reason></reason></test>
You can’t perform that action at this time.
0 commit comments