Exporting undeclared variables should throw a SyntaxError (#4276)
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
@@ -828,6 +828,7 @@ uint16_t scanner_decode_map_to (parser_scope_stack_t *stack_item_p);
|
||||
uint16_t scanner_save_literal (parser_context_t *context_p, uint16_t ident_index);
|
||||
bool scanner_literal_is_const_reg (parser_context_t *context_p, uint16_t literal_index);
|
||||
bool scanner_literal_is_created (parser_context_t *context_p, uint16_t literal_index);
|
||||
bool scanner_literal_exists (parser_context_t *context_p, uint16_t literal_index);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
void scanner_scan_all (parser_context_t *context_p, const uint8_t *arg_list_p, const uint8_t *arg_list_end_p,
|
||||
|
||||
@@ -353,6 +353,15 @@ parser_module_create_module_node (parser_context_t *context_p) /**< parser conte
|
||||
void
|
||||
parser_module_parse_export_clause (parser_context_t *context_p) /**< parser context */
|
||||
{
|
||||
bool has_module_specifier = false;
|
||||
|
||||
if (context_p->source_p == context_p->next_scanner_info_p->source_p)
|
||||
{
|
||||
has_module_specifier = true;
|
||||
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_EXPORT_MODULE_SPECIFIER);
|
||||
scanner_release_next (context_p, sizeof (scanner_info_t));
|
||||
}
|
||||
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_LEFT_BRACE);
|
||||
lexer_next_token (context_p);
|
||||
|
||||
@@ -377,6 +386,12 @@ parser_module_parse_export_clause (parser_context_t *context_p) /**< parser cont
|
||||
|
||||
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL);
|
||||
|
||||
if (!has_module_specifier
|
||||
&& !scanner_literal_exists (context_p, context_p->lit_object.index))
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_EXPORT_NOT_DEFINED);
|
||||
}
|
||||
|
||||
uint16_t local_name_index = context_p->lit_object.index;
|
||||
uint16_t export_name_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS;
|
||||
|
||||
|
||||
@@ -1418,6 +1418,10 @@ parser_error_to_string (parser_error_t error) /**< error code */
|
||||
{
|
||||
return "Duplicated imported binding name.";
|
||||
}
|
||||
case PARSER_ERR_EXPORT_NOT_DEFINED:
|
||||
{
|
||||
return "Export not defined in module.";
|
||||
}
|
||||
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||
|
||||
default:
|
||||
|
||||
@@ -179,6 +179,7 @@ typedef enum
|
||||
PARSER_ERR_RIGHT_BRACE_COMMA_EXPECTED, /**< right brace or comma expected */
|
||||
PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER, /**< duplicated export identifier name */
|
||||
PARSER_ERR_DUPLICATED_IMPORT_BINDING, /**< duplicated import binding name */
|
||||
PARSER_ERR_EXPORT_NOT_DEFINED, /**< export is not defined in module */
|
||||
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||
|
||||
PARSER_ERR_NON_STRICT_ARG_DEFINITION /**< non-strict argument definition */
|
||||
|
||||
@@ -1764,7 +1764,8 @@ scanner_cleanup (parser_context_t *context_p) /**< context */
|
||||
|| scanner_info_p->type == SCANNER_TYPE_CLASS_CONSTRUCTOR
|
||||
|| scanner_info_p->type == SCANNER_TYPE_OBJECT_LITERAL_WITH_SUPER
|
||||
|| scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED
|
||||
|| scanner_info_p->type == SCANNER_TYPE_ERR_ASYNC_FUNCTION);
|
||||
|| scanner_info_p->type == SCANNER_TYPE_ERR_ASYNC_FUNCTION
|
||||
|| scanner_info_p->type == SCANNER_TYPE_EXPORT_MODULE_SPECIFIER);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
JERRY_ASSERT (scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
@@ -2713,6 +2714,31 @@ scanner_literal_is_created (parser_context_t *context_p, /**< context */
|
||||
return (scope_stack_p->map_to & PARSER_SCOPE_STACK_IS_LOCAL_CREATED) != 0;
|
||||
} /* scanner_literal_is_created */
|
||||
|
||||
/**
|
||||
* Checks whether the literal exists.
|
||||
*
|
||||
* @return true if the literal exists, false otherwise
|
||||
*/
|
||||
bool
|
||||
scanner_literal_exists (parser_context_t *context_p, /**< context */
|
||||
uint16_t literal_index) /**< literal index */
|
||||
{
|
||||
JERRY_ASSERT (literal_index < PARSER_REGISTER_START);
|
||||
|
||||
parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p + context_p->scope_stack_top;
|
||||
|
||||
while (scope_stack_p-- > context_p->scope_stack_p)
|
||||
{
|
||||
if (scope_stack_p->map_from != PARSER_SCOPE_STACK_FUNC
|
||||
&& scanner_decode_map_to (scope_stack_p) == literal_index)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} /* scanner_literal_exists */
|
||||
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
/**
|
||||
|
||||
@@ -1879,6 +1879,9 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
return SCAN_NEXT_TOKEN;
|
||||
}
|
||||
|
||||
scanner_source_start_t source_start;
|
||||
source_start.source_p = context_p->source_p;
|
||||
|
||||
if (context_p->token.type == LEXER_LEFT_BRACE)
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
@@ -1924,6 +1927,9 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
return SCAN_KEEP_TOKEN;
|
||||
}
|
||||
|
||||
scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t));
|
||||
info_p->type = SCANNER_TYPE_EXPORT_MODULE_SPECIFIER;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (context_p->token.type != LEXER_LITERAL
|
||||
@@ -3737,6 +3743,13 @@ scan_completed:
|
||||
print_location = false;
|
||||
break;
|
||||
}
|
||||
case SCANNER_TYPE_EXPORT_MODULE_SPECIFIER:
|
||||
{
|
||||
JERRY_DEBUG_MSG (" EXPORT_WITH_MODULE_SPECIFIER: source:%d\n",
|
||||
(int) (info_p->source_p - source_start_p));
|
||||
print_location = false;
|
||||
break;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ typedef enum
|
||||
SCANNER_TYPE_ERR_REDECLARED, /**< syntax error: a variable is redeclared */
|
||||
SCANNER_TYPE_ERR_ASYNC_FUNCTION, /**< an invalid async function follows */
|
||||
SCANNER_TYPE_OBJECT_LITERAL_WITH_SUPER, /**< object literal with inner super reference */
|
||||
SCANNER_TYPE_EXPORT_MODULE_SPECIFIER, /**< export with module specifier */
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
} scanner_info_type_t;
|
||||
|
||||
|
||||
@@ -301,7 +301,6 @@
|
||||
<test id="language/expressions/tagged-template/cache-identical-source-new-function.js"><reason></reason></test>
|
||||
<test id="language/line-terminators/S7.3_A2.3.js"><reason>No longer a SyntaxError in ES11</reason></test>
|
||||
<test id="language/line-terminators/S7.3_A2.4.js"><reason>No longer a SyntaxError in ES11</reason></test>
|
||||
<test id="language/module-code/export-unresolvable.js"><reason></reason></test>
|
||||
<test id="language/statements/class/syntax/early-errors/class-body-static-method-get-propname-prototype.js"><reason></reason></test>
|
||||
<test id="language/statements/for-of/iterator-next-reference.js"><reason>ES2018 change: next method must be cached</reason></test>
|
||||
<test id="language/statements/for/S12.6.3_A9.1.js"><reason></reason></test>
|
||||
|
||||
@@ -742,8 +742,6 @@
|
||||
<test id="language/identifiers/start-unicode-9.0.0.js"><reason></reason></test>
|
||||
<test id="language/literals/regexp/unicode-escape-nls-err.js"><reason></reason></test>
|
||||
<test id="language/literals/string/legacy-octal-escape-sequence-prologue-strict.js"><reason></reason></test>
|
||||
<test id="language/module-code/early-export-global.js"><reason></reason></test>
|
||||
<test id="language/module-code/early-export-unresolvable.js"><reason></reason></test>
|
||||
<test id="language/module-code/early-strict-mode.js"><reason></reason></test>
|
||||
<test id="language/module-code/eval-export-cls-semi.js"><reason></reason></test>
|
||||
<test id="language/module-code/eval-export-dflt-cls-anon-semi.js"><reason></reason></test>
|
||||
|
||||
Reference in New Issue
Block a user