mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Fix identifier handling inside export statements (#2843)
Fixes #2842 Co-authored-by: Marko Fabo <mfabo@inf.u-szeged.hu> JerryScript-DCO-1.0-Signed-off-by: Marko Fabo mfabo@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
parent
097e1862d2
commit
1cdb3c6c56
@ -2289,6 +2289,7 @@ lexer_expect_identifier (parser_context_t *context_p, /**< context */
|
||||
lexer_construct_literal_object (context_p,
|
||||
(lexer_lit_location_t *) &lexer_default_literal,
|
||||
lexer_default_literal.type);
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_DEFAULT_CLASS_OR_FUNC);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -571,9 +571,10 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_VAR;
|
||||
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
if (JERRY_CONTEXT (module_top_context_p) != NULL && context_p->module_current_node_p != NULL)
|
||||
if (context_p->status_flags & PARSER_MODULE_STORE_IDENT)
|
||||
{
|
||||
context_p->module_identifier_lit_p = context_p->lit_object.literal_p;
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_STORE_IDENT);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
@ -1276,12 +1277,12 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
&context_p->token.lit_location,
|
||||
context_p->token.lit_location.type);
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
if (context_p->status_flags & PARSER_MODULE_DEFAULT_EXPR
|
||||
if (context_p->status_flags & PARSER_MODULE_STORE_IDENT
|
||||
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
||||
{
|
||||
context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_VAR;
|
||||
context_p->module_identifier_lit_p = context_p->lit_object.literal_p;
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_DEFAULT_EXPR);
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_STORE_IDENT);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ typedef enum
|
||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
PARSER_MODULE_DEFAULT_CLASS_OR_FUNC = (1u << 25), /**< parsing a function or class default export */
|
||||
PARSER_MODULE_DEFAULT_EXPR = (1u << 26), /**< parsing a default export expression */
|
||||
PARSER_MODULE_STORE_IDENT = (1u << 26), /**< store identifier of the current export statement */
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
} parser_general_flags_t;
|
||||
|
||||
|
||||
@ -327,9 +327,10 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */
|
||||
context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_VAR;
|
||||
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
if (JERRY_CONTEXT (module_top_context_p) != NULL && context_p->module_current_node_p != NULL)
|
||||
if (context_p->status_flags & PARSER_MODULE_STORE_IDENT)
|
||||
{
|
||||
context_p->module_identifier_lit_p = context_p->lit_object.literal_p;
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_STORE_IDENT);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
@ -399,9 +400,10 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
|
||||
name_p = context_p->lit_object.literal_p;
|
||||
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
if (JERRY_CONTEXT (module_top_context_p) != NULL && context_p->module_current_node_p != NULL)
|
||||
if (context_p->status_flags & PARSER_MODULE_STORE_IDENT)
|
||||
{
|
||||
context_p->module_identifier_lit_p = context_p->lit_object.literal_p;
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_STORE_IDENT);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
@ -1815,6 +1817,8 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
lexer_range_t range;
|
||||
parser_save_range (context_p, &range, context_p->source_end_p);
|
||||
|
||||
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
if (context_p->token.type == LEXER_KEYW_CLASS)
|
||||
{
|
||||
@ -1829,7 +1833,6 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
else
|
||||
{
|
||||
/* Assignment expression */
|
||||
context_p->status_flags |= PARSER_MODULE_DEFAULT_EXPR;
|
||||
parser_set_range (context_p, &range);
|
||||
|
||||
/* 15.2.3.5 Use the synthetic name '*default*' as the identifier. */
|
||||
@ -1866,7 +1869,6 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
name_p);
|
||||
ecma_deref_ecma_string (name_p);
|
||||
ecma_deref_ecma_string (export_name_p);
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_DEFAULT_CLASS_OR_FUNC | PARSER_MODULE_DEFAULT_EXPR);
|
||||
break;
|
||||
}
|
||||
case LEXER_MULTIPLY:
|
||||
@ -1884,6 +1886,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
case LEXER_KEYW_VAR:
|
||||
{
|
||||
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
||||
parser_parse_var_statement (context_p);
|
||||
ecma_string_t *name_p = ecma_new_ecma_string_from_utf8 (context_p->module_identifier_lit_p->u.char_p,
|
||||
context_p->module_identifier_lit_p->prop.length);
|
||||
@ -1902,6 +1905,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
case LEXER_KEYW_CLASS:
|
||||
{
|
||||
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
||||
parser_parse_class (context_p, true);
|
||||
ecma_string_t *name_p = ecma_new_ecma_string_from_utf8 (context_p->module_identifier_lit_p->u.char_p,
|
||||
context_p->module_identifier_lit_p->prop.length);
|
||||
@ -1920,6 +1924,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
case LEXER_KEYW_FUNCTION:
|
||||
{
|
||||
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
||||
parser_parse_function_statement (context_p);
|
||||
ecma_string_t *name_p = ecma_new_ecma_string_from_utf8 (context_p->module_identifier_lit_p->u.char_p,
|
||||
context_p->module_identifier_lit_p->prop.length);
|
||||
@ -1955,6 +1960,7 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
}
|
||||
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_DEFAULT_CLASS_OR_FUNC | PARSER_MODULE_STORE_IDENT);
|
||||
parser_module_add_export_node_to_context (context_p);
|
||||
context_p->module_current_node_p = NULL;
|
||||
} /* parser_parse_export_statement */
|
||||
|
||||
16
tests/jerry/es2015/regression-test-issue-2842.js
Normal file
16
tests/jerry/es2015/regression-test-issue-2842.js
Normal file
@ -0,0 +1,16 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export function $ () { var $, b }
|
||||
16
tests/jerry/fail/module-031.js
Normal file
16
tests/jerry/fail/module-031.js
Normal file
@ -0,0 +1,16 @@
|
||||
/* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export default function () { function () {} }
|
||||
Loading…
x
Reference in New Issue
Block a user