Rework ES2015 module system and add missing features. (#2792)
Co-authored-by: Dániel Bátyai <dbatyai@inf.u-szeged.hu> JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Daniel Vince vinced@inf.u-szeged.hu
This commit is contained in:
committed by
Robert Fancsik
parent
938e9c7530
commit
37b7645e6a
@@ -24,6 +24,8 @@
|
||||
#include "js-parser-limits.h"
|
||||
#include "js-lexer.h"
|
||||
|
||||
#include "ecma-module.h"
|
||||
|
||||
/** \addtogroup parser Parser
|
||||
* @{
|
||||
*
|
||||
@@ -78,6 +80,10 @@ typedef enum
|
||||
PARSER_CLASS_STATIC_FUNCTION = (1u << 23), /**< this function is a static class method */
|
||||
PARSER_CLASS_SUPER_PROP_REFERENCE = (1u << 24), /**< super property call or assignment */
|
||||
#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 */
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
} parser_general_flags_t;
|
||||
|
||||
/**
|
||||
@@ -296,59 +302,6 @@ typedef struct
|
||||
|
||||
#endif /* JERRY_DEBUGGER */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
/**
|
||||
* String struct for storing the module path.
|
||||
*/
|
||||
typedef struct parser_module_utf8_string
|
||||
{
|
||||
uint8_t *value_p; /**< string value stored as uint8_t */
|
||||
prop_length_t length; /**< length of the string */
|
||||
} parser_module_utf8_string_t;
|
||||
|
||||
/**
|
||||
* Imported or exported names, for example:
|
||||
* import { v as x } from "module";
|
||||
* exported name: v
|
||||
* imported name: x
|
||||
* export x as v;
|
||||
* exported variable: x
|
||||
* exported as: v
|
||||
* Reference: https://www.ecma-international.org/ecma-262/6.0/#table-41
|
||||
*/
|
||||
typedef struct parser_module_names
|
||||
{
|
||||
ecma_string_t *import_name_p; /**< local name of the import - export item */
|
||||
ecma_string_t *local_name_p; /**< import name of the import - export item */
|
||||
|
||||
struct parser_module_names *next_p; /**< next linked list node */
|
||||
} parser_module_names_t;
|
||||
|
||||
/**
|
||||
* Module node to store imports / exports.
|
||||
*/
|
||||
typedef struct parser_module_node
|
||||
{
|
||||
parser_module_names_t *module_names_p; /**< names of the requested imports - exports */
|
||||
uint16_t module_request_count; /**< count of the requested imports - exports */
|
||||
|
||||
parser_module_utf8_string_t script_path; /**< path of the requested module*/
|
||||
|
||||
struct parser_module_node *next_p; /**< next linked list node */
|
||||
} parser_module_node_t;
|
||||
|
||||
/**
|
||||
* Module context in the parser context. It is not in the context if modules
|
||||
* are not enabled during the build. It's value is NULL if there is no import /
|
||||
* export in the script, otherwise it contains all the imports and exports.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
parser_module_node_t *imports_p; /**< import item of the current context */
|
||||
parser_module_node_t *exports_p; /**< export item of the current context */
|
||||
} parser_module_context_t;
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
/**
|
||||
* Those members of a context which needs
|
||||
* to be saved when a sub-function is parsed.
|
||||
@@ -396,8 +349,8 @@ typedef struct
|
||||
parser_stack_iterator_t last_statement; /**< last statement position */
|
||||
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
parser_module_context_t *module_context_p; /**< shared module context inside the parser */
|
||||
parser_module_node_t *module_current_node_p; /**< import / export node that is being processed */
|
||||
ecma_module_node_t *module_current_node_p; /**< import / export node that is being processed */
|
||||
lexer_literal_t *module_identifier_lit_p; /**< the literal for the identifier of the current element */
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
/* Lexer members. */
|
||||
@@ -614,27 +567,23 @@ void parser_free_jumps (parser_stack_iterator_t iterator);
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern const lexer_lit_location_t lexer_default_literal;
|
||||
void parser_module_add_export_node_to_context (parser_context_t *context_p);
|
||||
void parser_module_add_import_node_to_context (parser_context_t *context_p);
|
||||
void parser_module_check_request_place (parser_context_t *context_p);
|
||||
void parser_module_context_cleanup (parser_context_t *context_p);
|
||||
void parser_module_context_init (parser_context_t *context_p);
|
||||
void parser_module_free_saved_names (parser_module_node_t *module_node_p);
|
||||
void parser_module_handle_from_clause (parser_context_t *context_p);
|
||||
void parser_module_handle_module_specifier (parser_context_t *context_p);
|
||||
void parser_module_handle_requests (parser_context_t *context_p);
|
||||
void parser_module_partial_cleanup_on_error (parser_module_node_t *module_node_p);
|
||||
void parser_module_parse_export_item_list (parser_context_t *context_p);
|
||||
void parser_module_parse_import_item_list (parser_context_t *context_p);
|
||||
|
||||
parser_module_node_t *parser_module_create_module_node (parser_context_t *context_p,
|
||||
parser_module_node_t *template_node_p);
|
||||
parser_module_node_t *parser_module_get_export_node (parser_context_t *context_p);
|
||||
|
||||
void parser_module_add_item_to_node (parser_context_t *context_p,
|
||||
parser_module_node_t *module_node_p,
|
||||
lexer_literal_t *import_name_p,
|
||||
lexer_literal_t *local_name_p,
|
||||
bool is_import_item);
|
||||
void parser_module_parse_export_clause (parser_context_t *context_p);
|
||||
void parser_module_parse_import_clause (parser_context_t *context_p);
|
||||
void parser_module_set_default (parser_context_t *context_p);
|
||||
ecma_module_node_t *parser_module_create_module_node (parser_context_t *context_p,
|
||||
ecma_module_node_t *template_node_p);
|
||||
bool parser_module_check_duplicate_import (parser_context_t *context_p, ecma_string_t *local_name_p);
|
||||
bool parser_module_check_duplicate_export (parser_context_t *context_p, ecma_string_t *export_name_p);
|
||||
void parser_module_add_names_to_node (parser_context_t *context_p,
|
||||
ecma_string_t *imex_name_p,
|
||||
ecma_string_t *local_name_p);
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user