Implement namespace exports in modules (#4708)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -474,8 +474,21 @@ ecma_module_resolve_export (ecma_module_t *const module_p, /**< base module */
|
||||
{
|
||||
ecma_module_t *target_module_p = ecma_module_get_from_object (*indirect_export_p->u.module_object_p);
|
||||
|
||||
if (!ecma_module_resolve_set_append (resolve_set_p, target_module_p, export_names_p->local_name_p)
|
||||
&& resolve_result_p->result_type == ECMA_MODULE_RESOLVE_NOT_FOUND)
|
||||
if (ecma_compare_ecma_string_to_magic_id (export_names_p->local_name_p,
|
||||
LIT_MAGIC_STRING_ASTERIX_CHAR))
|
||||
{
|
||||
/* Namespace export. */
|
||||
ecma_value_t namespace = ecma_make_object_value (target_module_p->namespace_object_p);
|
||||
|
||||
JERRY_ASSERT (namespace & ECMA_MODULE_NAMESPACE_RESULT_FLAG);
|
||||
|
||||
if (!ecma_module_resolve_update (resolve_result_p, namespace))
|
||||
{
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else if (!ecma_module_resolve_set_append (resolve_set_p, target_module_p, export_names_p->local_name_p)
|
||||
&& resolve_result_p->result_type == ECMA_MODULE_RESOLVE_NOT_FOUND)
|
||||
{
|
||||
resolve_result_p->result_type = ECMA_MODULE_RESOLVE_CIRCULAR;
|
||||
}
|
||||
|
||||
@@ -2618,13 +2618,47 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||
case LEXER_MULTIPLY:
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
|
||||
ecma_module_node_t **target_node_list_p = &(JERRY_CONTEXT (module_current_p)->star_exports_p);
|
||||
|
||||
if (lexer_token_is_identifier (context_p, "as", 2))
|
||||
{
|
||||
target_node_list_p = &(JERRY_CONTEXT (module_current_p)->indirect_exports_p);
|
||||
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (context_p->token.type != LEXER_LITERAL
|
||||
|| context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED);
|
||||
}
|
||||
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL);
|
||||
|
||||
lexer_literal_t *literal_p = PARSER_GET_LITERAL (context_p->lit_object.index);
|
||||
ecma_string_t *export_name_p = ecma_new_ecma_string_from_utf8 (literal_p->u.char_p,
|
||||
literal_p->prop.length);
|
||||
|
||||
if (parser_module_check_duplicate_export (context_p, export_name_p))
|
||||
{
|
||||
ecma_deref_ecma_string (export_name_p);
|
||||
parser_raise_error (context_p, PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER);
|
||||
}
|
||||
|
||||
ecma_string_t *local_name_p = ecma_get_magic_string (LIT_MAGIC_STRING_ASTERIX_CHAR);
|
||||
parser_module_add_names_to_node (context_p, export_name_p, local_name_p);
|
||||
ecma_deref_ecma_string (export_name_p);
|
||||
|
||||
lexer_next_token (context_p);
|
||||
}
|
||||
|
||||
if (!lexer_token_is_identifier (context_p, "from", 4))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_FROM_EXPECTED);
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
parser_module_handle_module_specifier (context_p, &(JERRY_CONTEXT (module_current_p)->star_exports_p));
|
||||
parser_module_handle_module_specifier (context_p, target_node_list_p);
|
||||
return false;
|
||||
}
|
||||
case LEXER_KEYW_VAR:
|
||||
|
||||
@@ -1851,6 +1851,20 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
if (context_p->token.type == LEXER_MULTIPLY)
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (lexer_token_is_identifier (context_p, "as", 2))
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (context_p->token.type != LEXER_LITERAL
|
||||
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
||||
{
|
||||
scanner_raise_error (context_p);
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
}
|
||||
|
||||
if (!lexer_token_is_identifier (context_p, "from", 4))
|
||||
{
|
||||
scanner_raise_error (context_p);
|
||||
|
||||
Reference in New Issue
Block a user