Rework export default parsing (#4505)
- Remove SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME workaround - Add async and generator function support - Fix auto semicolon insertion after export statement - fixes #4150. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -2535,8 +2535,11 @@ parser_parse_import_statement (parser_context_t *context_p) /**< parser context
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse export statement.
|
* Parse export statement.
|
||||||
|
*
|
||||||
|
* @return true - if function of class statement was found
|
||||||
|
* false - otherwise
|
||||||
*/
|
*/
|
||||||
static void
|
static bool
|
||||||
parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_EXPORT);
|
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_EXPORT);
|
||||||
@@ -2545,6 +2548,8 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
|||||||
|
|
||||||
context_p->module_current_node_p = parser_module_create_module_node (context_p);
|
context_p->module_current_node_p = parser_module_create_module_node (context_p);
|
||||||
|
|
||||||
|
bool consume_last_statement = false;
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
switch (context_p->token.type)
|
switch (context_p->token.type)
|
||||||
{
|
{
|
||||||
@@ -2556,15 +2561,26 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
|||||||
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
|
if (context_p->token.type == LEXER_LITERAL
|
||||||
|
&& lexer_token_is_async (context_p)
|
||||||
|
&& context_p->next_scanner_info_p->source_p == context_p->source_p
|
||||||
|
&& context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION)
|
||||||
|
{
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
}
|
||||||
|
|
||||||
if (context_p->token.type == LEXER_KEYW_CLASS)
|
if (context_p->token.type == LEXER_KEYW_CLASS)
|
||||||
{
|
{
|
||||||
context_p->status_flags |= PARSER_MODULE_DEFAULT_CLASS_OR_FUNC;
|
context_p->status_flags |= PARSER_MODULE_DEFAULT_CLASS_OR_FUNC;
|
||||||
parser_parse_class (context_p, true);
|
parser_parse_class (context_p, true);
|
||||||
|
consume_last_statement = true;
|
||||||
}
|
}
|
||||||
else if (context_p->token.type == LEXER_KEYW_FUNCTION)
|
else if (context_p->token.type == LEXER_KEYW_FUNCTION)
|
||||||
{
|
{
|
||||||
context_p->status_flags |= PARSER_MODULE_DEFAULT_CLASS_OR_FUNC;
|
context_p->status_flags |= PARSER_MODULE_DEFAULT_CLASS_OR_FUNC;
|
||||||
parser_parse_function_statement (context_p);
|
parser_parse_function_statement (context_p);
|
||||||
|
consume_last_statement = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2627,12 +2643,14 @@ parser_parse_export_statement (parser_context_t *context_p) /**< context */
|
|||||||
{
|
{
|
||||||
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
||||||
parser_parse_class (context_p, true);
|
parser_parse_class (context_p, true);
|
||||||
|
consume_last_statement = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LEXER_KEYW_FUNCTION:
|
case LEXER_KEYW_FUNCTION:
|
||||||
{
|
{
|
||||||
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
context_p->status_flags |= PARSER_MODULE_STORE_IDENT;
|
||||||
parser_parse_function_statement (context_p);
|
parser_parse_function_statement (context_p);
|
||||||
|
consume_last_statement = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LEXER_LEFT_BRACE:
|
case LEXER_LEFT_BRACE:
|
||||||
@@ -2656,6 +2674,8 @@ 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);
|
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_DEFAULT_CLASS_OR_FUNC | PARSER_MODULE_STORE_IDENT);
|
||||||
parser_module_finalize_export_node (context_p);
|
parser_module_finalize_export_node (context_p);
|
||||||
context_p->module_current_node_p = NULL;
|
context_p->module_current_node_p = NULL;
|
||||||
|
|
||||||
|
return consume_last_statement;
|
||||||
} /* parser_parse_export_statement */
|
} /* parser_parse_export_statement */
|
||||||
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
|
|
||||||
@@ -2948,7 +2968,10 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
|
|||||||
|
|
||||||
case LEXER_KEYW_EXPORT:
|
case LEXER_KEYW_EXPORT:
|
||||||
{
|
{
|
||||||
parser_parse_export_statement (context_p);
|
if (parser_parse_export_statement (context_p))
|
||||||
|
{
|
||||||
|
goto consume_last_statement;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
|
|||||||
@@ -119,6 +119,9 @@ typedef enum
|
|||||||
SCAN_STACK_FOR_START_PATTERN, /**< possible assignment pattern for "for" iterator */
|
SCAN_STACK_FOR_START_PATTERN, /**< possible assignment pattern for "for" iterator */
|
||||||
SCAN_STACK_USE_ASYNC, /**< an "async" identifier is used */
|
SCAN_STACK_USE_ASYNC, /**< an "async" identifier is used */
|
||||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
SCAN_STACK_EXPORT_DEFAULT, /**< scan primary expression after export default */
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
} scan_stack_modes_t;
|
} scan_stack_modes_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,11 +340,6 @@ typedef enum
|
|||||||
#define SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS(status_flags) \
|
#define SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS(status_flags) \
|
||||||
(!((status_flags) & (SCANNER_LITERAL_POOL_CLASS_NAME | SCANNER_LITERAL_POOL_CLASS_FIELD)))
|
(!((status_flags) & (SCANNER_LITERAL_POOL_CLASS_NAME | SCANNER_LITERAL_POOL_CLASS_FIELD)))
|
||||||
|
|
||||||
/**
|
|
||||||
* The class name is the *default* class name
|
|
||||||
*/
|
|
||||||
#define SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE
|
|
||||||
|
|
||||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -640,19 +640,6 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
|||||||
|
|
||||||
parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator);
|
parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator);
|
||||||
|
|
||||||
#if ENABLED (JERRY_ESNEXT)
|
|
||||||
if (JERRY_UNLIKELY (status_flags & SCANNER_LITERAL_POOL_CLASS_NAME))
|
|
||||||
{
|
|
||||||
literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator);
|
|
||||||
|
|
||||||
if ((literal_p != NULL || (status_flags & SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME))
|
|
||||||
&& no_declarations < PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK)
|
|
||||||
{
|
|
||||||
no_declarations++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
|
||||||
|
|
||||||
uint8_t arguments_stream_type = SCANNER_STREAM_TYPE_ARGUMENTS;
|
uint8_t arguments_stream_type = SCANNER_STREAM_TYPE_ARGUMENTS;
|
||||||
const uint8_t *prev_source_p = literal_pool_p->source_p - 1;
|
const uint8_t *prev_source_p = literal_pool_p->source_p - 1;
|
||||||
lexer_lit_location_t *last_argument_p = NULL;
|
lexer_lit_location_t *last_argument_p = NULL;
|
||||||
@@ -1702,15 +1689,40 @@ scanner_push_class_declaration (parser_context_t *context_p, /**< context */
|
|||||||
const uint8_t *source_p = context_p->source_p;
|
const uint8_t *source_p = context_p->source_p;
|
||||||
lexer_lit_location_t *literal_p = NULL;
|
lexer_lit_location_t *literal_p = NULL;
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
bool is_export_default = context_p->stack_top_uint8 == SCAN_STACK_EXPORT_DEFAULT;
|
||||||
|
JERRY_ASSERT (!is_export_default || stack_mode == SCAN_STACK_CLASS_EXPRESSION);
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
|
|
||||||
parser_stack_push_uint8 (context_p, stack_mode);
|
parser_stack_push_uint8 (context_p, stack_mode);
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
bool class_has_name = (context_p->token.type == LEXER_LITERAL
|
bool class_has_name = (context_p->token.type == LEXER_LITERAL
|
||||||
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
|
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
|
||||||
|
|
||||||
if (stack_mode == SCAN_STACK_CLASS_STATEMENT && class_has_name)
|
if (class_has_name)
|
||||||
|
{
|
||||||
|
if (stack_mode == SCAN_STACK_CLASS_STATEMENT)
|
||||||
{
|
{
|
||||||
literal_p = scanner_add_literal (context_p, scanner_context_p);
|
literal_p = scanner_add_literal (context_p, scanner_context_p);
|
||||||
|
scanner_context_p->active_literal_pool_p->no_declarations++;
|
||||||
|
}
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
else if (is_export_default)
|
||||||
|
{
|
||||||
|
literal_p = scanner_add_literal (context_p, scanner_context_p);
|
||||||
|
scanner_context_p->active_literal_pool_p->no_declarations++;
|
||||||
|
|
||||||
|
scanner_detect_invalid_let (context_p, literal_p);
|
||||||
|
|
||||||
|
if (literal_p->type & SCANNER_LITERAL_IS_USED)
|
||||||
|
{
|
||||||
|
literal_p->type |= SCANNER_LITERAL_EARLY_CREATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner_literal_pool_t *literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
|
scanner_literal_pool_t *literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
|
||||||
@@ -1718,7 +1730,20 @@ scanner_push_class_declaration (parser_context_t *context_p, /**< context */
|
|||||||
if (class_has_name)
|
if (class_has_name)
|
||||||
{
|
{
|
||||||
scanner_add_literal (context_p, scanner_context_p);
|
scanner_add_literal (context_p, scanner_context_p);
|
||||||
|
scanner_context_p->active_literal_pool_p->no_declarations++;
|
||||||
}
|
}
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
else if (is_export_default)
|
||||||
|
{
|
||||||
|
lexer_lit_location_t *name_literal_p;
|
||||||
|
name_literal_p = scanner_add_custom_literal (context_p,
|
||||||
|
scanner_context_p->active_literal_pool_p->prev_p,
|
||||||
|
&lexer_default_literal);
|
||||||
|
|
||||||
|
name_literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG;
|
||||||
|
scanner_context_p->active_literal_pool_p->no_declarations++;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
|
|
||||||
literal_pool_p->source_p = source_p;
|
literal_pool_p->source_p = source_p;
|
||||||
literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CLASS_NAME;
|
literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CLASS_NAME;
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
|||||||
case LEXER_KEYW_FUNCTION:
|
case LEXER_KEYW_FUNCTION:
|
||||||
{
|
{
|
||||||
uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION;
|
uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION;
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
bool is_export_default = stack_top == SCAN_STACK_EXPORT_DEFAULT;
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
|
|
||||||
#if ENABLED (JERRY_ESNEXT)
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
if (scanner_context_p->async_source_p != NULL)
|
if (scanner_context_p->async_source_p != NULL)
|
||||||
@@ -121,8 +124,30 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
|||||||
if (context_p->token.type == LEXER_LITERAL
|
if (context_p->token.type == LEXER_LITERAL
|
||||||
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
||||||
{
|
{
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
if (is_export_default)
|
||||||
|
{
|
||||||
|
lexer_lit_location_t *location_p;
|
||||||
|
location_p = scanner_add_custom_literal (context_p,
|
||||||
|
scanner_context_p->active_literal_pool_p->prev_p,
|
||||||
|
&context_p->token.lit_location);
|
||||||
|
|
||||||
|
scanner_detect_invalid_let (context_p, location_p);
|
||||||
|
location_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
}
|
}
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
else if (is_export_default)
|
||||||
|
{
|
||||||
|
lexer_lit_location_t *location_p;
|
||||||
|
location_p = scanner_add_custom_literal (context_p,
|
||||||
|
scanner_context_p->active_literal_pool_p->prev_p,
|
||||||
|
&lexer_default_literal);
|
||||||
|
location_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
|
|
||||||
parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_EXPRESSION);
|
parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_EXPRESSION);
|
||||||
scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS;
|
scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS;
|
||||||
@@ -179,7 +204,8 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
|||||||
scanner_scan_simple_arrow (context_p, scanner_context_p, source_p);
|
scanner_scan_simple_arrow (context_p, scanner_context_p, source_p);
|
||||||
return SCAN_KEEP_TOKEN;
|
return SCAN_KEEP_TOKEN;
|
||||||
}
|
}
|
||||||
else if (JERRY_UNLIKELY (lexer_token_is_async (context_p)))
|
|
||||||
|
if (JERRY_UNLIKELY (lexer_token_is_async (context_p)))
|
||||||
{
|
{
|
||||||
scanner_context_p->async_source_p = source_p;
|
scanner_context_p->async_source_p = source_p;
|
||||||
scanner_check_async_function (context_p, scanner_context_p);
|
scanner_check_async_function (context_p, scanner_context_p);
|
||||||
@@ -189,6 +215,17 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
|||||||
|
|
||||||
if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
if (context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
||||||
{
|
{
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
if (stack_top == SCAN_STACK_EXPORT_DEFAULT)
|
||||||
|
{
|
||||||
|
lexer_lit_location_t *location_p = scanner_add_literal (context_p, scanner_context_p);
|
||||||
|
location_p->type |= (SCANNER_LITERAL_IS_USED | SCANNER_LITERAL_IS_VAR);
|
||||||
|
scanner_detect_eval_call (context_p, scanner_context_p);
|
||||||
|
scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
|
|
||||||
scanner_add_reference (context_p, scanner_context_p);
|
scanner_add_reference (context_p, scanner_context_p);
|
||||||
}
|
}
|
||||||
/* FALLTHRU */
|
/* FALLTHRU */
|
||||||
@@ -1804,86 +1841,11 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
|||||||
if (context_p->token.type == LEXER_KEYW_DEFAULT)
|
if (context_p->token.type == LEXER_KEYW_DEFAULT)
|
||||||
{
|
{
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
parser_stack_push_uint8 (context_p, SCAN_STACK_EXPORT_DEFAULT);
|
||||||
if (context_p->token.type == LEXER_KEYW_FUNCTION)
|
|
||||||
{
|
|
||||||
lexer_next_token (context_p);
|
|
||||||
if (context_p->token.type == LEXER_LITERAL
|
|
||||||
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
|
|
||||||
{
|
|
||||||
lexer_lit_location_t *location_p = scanner_add_literal (context_p, scanner_context_p);
|
|
||||||
|
|
||||||
if (location_p->type & SCANNER_LITERAL_IS_LOCAL
|
|
||||||
&& !(location_p->type & SCANNER_LITERAL_IS_FUNC))
|
|
||||||
{
|
|
||||||
scanner_raise_redeclaration_error (context_p);
|
|
||||||
}
|
|
||||||
location_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET;
|
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lexer_lit_location_t *location_p;
|
|
||||||
location_p = scanner_add_custom_literal (context_p,
|
|
||||||
scanner_context_p->active_literal_pool_p,
|
|
||||||
&lexer_default_literal);
|
|
||||||
location_p->type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET;
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_FUNCTION);
|
|
||||||
|
|
||||||
parser_stack_push_uint8 (context_p, SCAN_STACK_FUNCTION_STATEMENT);
|
|
||||||
scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS;
|
|
||||||
return SCAN_KEEP_TOKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context_p->token.type == LEXER_KEYW_CLASS)
|
|
||||||
{
|
|
||||||
lexer_lit_location_t *literal_p;
|
|
||||||
literal_p = scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT);
|
|
||||||
|
|
||||||
if (literal_p != NULL)
|
|
||||||
{
|
|
||||||
scanner_detect_invalid_let (context_p, literal_p);
|
|
||||||
|
|
||||||
if (literal_p->type & SCANNER_LITERAL_IS_USED)
|
|
||||||
{
|
|
||||||
literal_p->type |= SCANNER_LITERAL_EARLY_CREATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG;
|
|
||||||
return SCAN_NEXT_TOKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
literal_p = scanner_add_custom_literal (context_p,
|
|
||||||
scanner_context_p->active_literal_pool_p,
|
|
||||||
&lexer_default_literal);
|
|
||||||
|
|
||||||
literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG;
|
|
||||||
scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME;
|
|
||||||
return SCAN_KEEP_TOKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Assignment expression. */
|
|
||||||
lexer_lit_location_t *location_p;
|
|
||||||
location_p = scanner_add_custom_literal (context_p,
|
|
||||||
scanner_context_p->active_literal_pool_p,
|
|
||||||
&lexer_default_literal);
|
|
||||||
location_p->type |= SCANNER_LITERAL_IS_VAR;
|
|
||||||
scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION;
|
scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION;
|
||||||
|
|
||||||
if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
|
|
||||||
{
|
|
||||||
return SCAN_KEEP_TOKEN;
|
return SCAN_KEEP_TOKEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
location_p = scanner_add_literal (context_p, scanner_context_p);
|
|
||||||
location_p->type |= SCANNER_LITERAL_IS_VAR;
|
|
||||||
scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
|
||||||
return SCAN_NEXT_TOKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner_context_p->mode = SCAN_MODE_STATEMENT_END;
|
scanner_context_p->mode = SCAN_MODE_STATEMENT_END;
|
||||||
|
|
||||||
if (context_p->token.type == LEXER_MULTIPLY)
|
if (context_p->token.type == LEXER_MULTIPLY)
|
||||||
@@ -2152,6 +2114,16 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
|
|||||||
|
|
||||||
scanner_pop_literal_pool (context_p, scanner_context_p);
|
scanner_pop_literal_pool (context_p, scanner_context_p);
|
||||||
parser_stack_pop_uint8 (context_p);
|
parser_stack_pop_uint8 (context_p);
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
if (context_p->stack_top_uint8 == SCAN_STACK_EXPORT_DEFAULT)
|
||||||
|
{
|
||||||
|
terminator_found = true;
|
||||||
|
parser_stack_pop_uint8 (context_p);
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
return SCAN_NEXT_TOKEN;
|
return SCAN_NEXT_TOKEN;
|
||||||
}
|
}
|
||||||
case SCAN_STACK_FUNCTION_PROPERTY:
|
case SCAN_STACK_FUNCTION_PROPERTY:
|
||||||
@@ -2306,6 +2278,17 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
case SCAN_STACK_EXPORT_DEFAULT:
|
||||||
|
{
|
||||||
|
parser_stack_pop_uint8 (context_p);
|
||||||
|
lexer_lit_location_t *location_p = scanner_add_custom_literal (context_p,
|
||||||
|
scanner_context_p->active_literal_pool_p,
|
||||||
|
&lexer_default_literal);
|
||||||
|
location_p->type |= SCANNER_LITERAL_IS_VAR;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_TRY_STATEMENT
|
JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_TRY_STATEMENT
|
||||||
@@ -2617,6 +2600,16 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
|||||||
|
|
||||||
scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
||||||
parser_stack_pop_uint8 (context_p);
|
parser_stack_pop_uint8 (context_p);
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_MODULE_SYSTEM)
|
||||||
|
if (context_p->stack_top_uint8 == SCAN_STACK_EXPORT_DEFAULT)
|
||||||
|
{
|
||||||
|
/* The token is kept to disallow consuming a semicolon after it. */
|
||||||
|
parser_stack_change_last_uint8 (context_p, SCAN_STACK_CLASS_STATEMENT);
|
||||||
|
scanner_context.mode = SCAN_MODE_STATEMENT_END;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ export {};
|
|||||||
export {a as aa,};
|
export {a as aa,};
|
||||||
export {b as bb, c as cc};
|
export {b as bb, c as cc};
|
||||||
export {d};
|
export {d};
|
||||||
export var x = 42;
|
export var x = 40;
|
||||||
export function f(a) {return a;};
|
export function f(a) {return a;} x++; /* test auto semicolon insertion */
|
||||||
export class Dog {
|
export class Dog {
|
||||||
constructor (name) {
|
constructor (name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -27,7 +27,7 @@ export class Dog {
|
|||||||
speak() {
|
speak() {
|
||||||
return this.name + " barks."
|
return this.name + " barks."
|
||||||
}
|
}
|
||||||
};
|
} x++; /* test auto semicolon insertion */
|
||||||
export default "default";
|
export default "default";
|
||||||
|
|
||||||
var a = "a";
|
var a = "a";
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
let counter = 0.1;
|
||||||
|
export default function* g() { return "foo1"; } counter++; /* test auto semicolon insertion */
|
||||||
|
export {counter};
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
let counter = 1.1;
|
||||||
|
export default async function* g() { return "foo2"; } counter++; /* test auto semicolon insertion */
|
||||||
|
export {counter};
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
let counter = 2.1;
|
||||||
|
export default async function g() { return "foo3"; } counter++; /* test auto semicolon insertion */
|
||||||
|
export {counter};
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
var async = "foo4";
|
||||||
|
|
||||||
|
export default async;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// 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 _ => "foo5";
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// 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 async _ => "foo6";
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// 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 async (a, b) => a + b;
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
let counter = 7.1;
|
||||||
|
export default class A { static x = "foo8" } counter++; /* test auto semicolon insertion */
|
||||||
|
export {counter};
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
let counter = 8.1;
|
||||||
|
export default class { static x = "foo9" } counter++; /* test auto semicolon insertion */
|
||||||
|
export {counter};
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
import foo1, { counter as bar1 } from "./module-export-default-1.mjs"
|
||||||
|
import foo2, { counter as bar2 } from "./module-export-default-2.mjs"
|
||||||
|
import foo3, { counter as bar3 } from "./module-export-default-3.mjs"
|
||||||
|
import foo4 from "./module-export-default-4.mjs"
|
||||||
|
import foo5 from "./module-export-default-5.mjs"
|
||||||
|
import foo6 from "./module-export-default-6.mjs"
|
||||||
|
import foo7 from "./module-export-default-7.mjs"
|
||||||
|
import foo8, { counter as bar8 } from "./module-export-default-8.mjs"
|
||||||
|
import foo9, { counter as bar9 } from "./module-export-default-9.mjs"
|
||||||
|
|
||||||
|
let async_queue_expected = ["foo2", "foo3", "foo6", "foo7"];
|
||||||
|
let async_queue = [];
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
assert(foo1().next().value === "foo1");
|
||||||
|
assert(bar1 === 1.1);
|
||||||
|
})();
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
async_queue.push((await foo2().next()).value);
|
||||||
|
assert(bar2 === 2.1);
|
||||||
|
})();
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
async_queue.push(await foo3());
|
||||||
|
assert(bar3 === 3.1);
|
||||||
|
})();
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
assert(foo4 === "foo4");
|
||||||
|
})();
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
assert(foo5() === "foo5");
|
||||||
|
})();
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
async_queue.push(await foo6());
|
||||||
|
})();
|
||||||
|
|
||||||
|
(async function() {
|
||||||
|
async_queue.push(await foo7("foo", "7"));
|
||||||
|
})();
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
assert(foo8.x === "foo8");
|
||||||
|
assert(bar8 === 8.1);
|
||||||
|
})();
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
assert(foo9.x === "foo9");
|
||||||
|
assert(bar9 === 9.1);
|
||||||
|
})();
|
||||||
|
|
||||||
|
Array.prototype.assertArrayEqual = function(expected) {
|
||||||
|
assert(this.length === expected.length);
|
||||||
|
print(this);
|
||||||
|
print(expected);
|
||||||
|
|
||||||
|
for (var i = 0; i < this.length; i++) {
|
||||||
|
assert(this[i] === expected[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let global = new Function('return this;')();
|
||||||
|
|
||||||
|
global.__checkAsync = function() {
|
||||||
|
async_queue.assertArrayEqual(async_queue_expected);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// 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 () => 1, 5;
|
||||||
@@ -389,11 +389,8 @@
|
|||||||
<test id="language/identifiers/start-unicode-9.0.0-escaped.js"><reason></reason></test>
|
<test id="language/identifiers/start-unicode-9.0.0-escaped.js"><reason></reason></test>
|
||||||
<test id="language/identifiers/start-unicode-9.0.0.js"><reason></reason></test>
|
<test id="language/identifiers/start-unicode-9.0.0.js"><reason></reason></test>
|
||||||
<test id="language/literals/string/legacy-octal-escape-sequence-prologue-strict.js"><reason></reason></test>
|
<test id="language/literals/string/legacy-octal-escape-sequence-prologue-strict.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>
|
|
||||||
<test id="language/module-code/eval-export-dflt-cls-anon.js"><reason></reason></test>
|
<test id="language/module-code/eval-export-dflt-cls-anon.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-export-dflt-cls-name-meth.js"><reason></reason></test>
|
<test id="language/module-code/eval-export-dflt-cls-name-meth.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-export-dflt-cls-named-semi.js"><reason></reason></test>
|
|
||||||
<test id="language/module-code/eval-export-dflt-cls-named.js"><reason></reason></test>
|
<test id="language/module-code/eval-export-dflt-cls-named.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-export-dflt-expr-cls-anon.js"><reason></reason></test>
|
<test id="language/module-code/eval-export-dflt-expr-cls-anon.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-export-dflt-expr-cls-name-meth.js"><reason></reason></test>
|
<test id="language/module-code/eval-export-dflt-expr-cls-name-meth.js"><reason></reason></test>
|
||||||
@@ -404,12 +401,6 @@
|
|||||||
<test id="language/module-code/eval-export-dflt-expr-gen-anon.js"><reason></reason></test>
|
<test id="language/module-code/eval-export-dflt-expr-gen-anon.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-export-dflt-expr-gen-named.js"><reason></reason></test>
|
<test id="language/module-code/eval-export-dflt-expr-gen-named.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-export-dflt-expr-in.js"><reason></reason></test>
|
<test id="language/module-code/eval-export-dflt-expr-in.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-export-dflt-fun-anon-semi.js"><reason></reason></test>
|
|
||||||
<test id="language/module-code/eval-export-dflt-fun-named-semi.js"><reason></reason></test>
|
|
||||||
<test id="language/module-code/eval-export-dflt-gen-anon-semi.js"><reason></reason></test>
|
|
||||||
<test id="language/module-code/eval-export-dflt-gen-named-semi.js"><reason></reason></test>
|
|
||||||
<test id="language/module-code/eval-export-fun-semi.js"><reason></reason></test>
|
|
||||||
<test id="language/module-code/eval-export-gen-semi.js"><reason></reason></test>
|
|
||||||
<test id="language/module-code/eval-gtbndng-indirect-trlng-comma.js"><reason></reason></test>
|
<test id="language/module-code/eval-gtbndng-indirect-trlng-comma.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-gtbndng-indirect-update-as.js"><reason></reason></test>
|
<test id="language/module-code/eval-gtbndng-indirect-update-as.js"><reason></reason></test>
|
||||||
<test id="language/module-code/eval-gtbndng-indirect-update-dflt.js"><reason></reason></test>
|
<test id="language/module-code/eval-gtbndng-indirect-update-dflt.js"><reason></reason></test>
|
||||||
|
|||||||
Reference in New Issue
Block a user