@@ -101,6 +101,9 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
101101 case LEXER_KEYW_FUNCTION :
102102 {
103103 uint16_t status_flags = SCANNER_LITERAL_POOL_FUNCTION ;
104+ #if ENABLED (JERRY_MODULE_SYSTEM )
105+ bool is_export_default = stack_top == SCAN_STACK_EXPORT_DEFAULT ;
106+ #endif /* ENABLED (JERRY_MODULE_SYSTEM) */
104107
105108#if ENABLED (JERRY_ESNEXT )
106109 if (scanner_context_p -> async_source_p != NULL )
@@ -121,8 +124,30 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
121124 if (context_p -> token .type == LEXER_LITERAL
122125 && context_p -> token .lit_location .type == LEXER_IDENT_LITERAL )
123126 {
127+ #if ENABLED (JERRY_MODULE_SYSTEM )
128+ if (is_export_default )
129+ {
130+ lexer_lit_location_t * location_p ;
131+ location_p = scanner_add_custom_literal (context_p ,
132+ scanner_context_p -> active_literal_pool_p -> prev_p ,
133+ & context_p -> token .lit_location );
134+
135+ scanner_detect_invalid_let (context_p , location_p );
136+ location_p -> type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET ;
137+ }
138+ #endif /* ENABLED (JERRY_MODULE_SYSTEM) */
124139 lexer_next_token (context_p );
125140 }
141+ #if ENABLED (JERRY_MODULE_SYSTEM )
142+ else if (is_export_default )
143+ {
144+ lexer_lit_location_t * location_p ;
145+ location_p = scanner_add_custom_literal (context_p ,
146+ scanner_context_p -> active_literal_pool_p -> prev_p ,
147+ & lexer_default_literal );
148+ location_p -> type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET ;
149+ }
150+ #endif /* ENABLED (JERRY_MODULE_SYSTEM) */
126151
127152 parser_stack_push_uint8 (context_p , SCAN_STACK_FUNCTION_EXPRESSION );
128153 scanner_context_p -> mode = SCAN_MODE_FUNCTION_ARGUMENTS ;
@@ -179,7 +204,8 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
179204 scanner_scan_simple_arrow (context_p , scanner_context_p , source_p );
180205 return SCAN_KEEP_TOKEN ;
181206 }
182- else if (JERRY_UNLIKELY (lexer_token_is_async (context_p )))
207+
208+ if (JERRY_UNLIKELY (lexer_token_is_async (context_p )))
183209 {
184210 scanner_context_p -> async_source_p = source_p ;
185211 scanner_check_async_function (context_p , scanner_context_p );
@@ -189,6 +215,17 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
189215
190216 if (context_p -> token .lit_location .type == LEXER_IDENT_LITERAL )
191217 {
218+ #if ENABLED (JERRY_MODULE_SYSTEM )
219+ if (stack_top == SCAN_STACK_EXPORT_DEFAULT )
220+ {
221+ lexer_lit_location_t * location_p = scanner_add_literal (context_p , scanner_context_p );
222+ location_p -> type |= (SCANNER_LITERAL_IS_USED | SCANNER_LITERAL_IS_VAR );
223+ scanner_detect_eval_call (context_p , scanner_context_p );
224+ scanner_context_p -> mode = SCAN_MODE_POST_PRIMARY_EXPRESSION ;
225+ break ;
226+ }
227+ #endif /* ENABLED (JERRY_MODULE_SYSTEM) */
228+
192229 scanner_add_reference (context_p , scanner_context_p );
193230 }
194231 /* FALLTHRU */
@@ -1804,84 +1841,9 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
18041841 if (context_p -> token .type == LEXER_KEYW_DEFAULT )
18051842 {
18061843 lexer_next_token (context_p );
1807-
1808- if (context_p -> token .type == LEXER_KEYW_FUNCTION )
1809- {
1810- lexer_next_token (context_p );
1811- if (context_p -> token .type == LEXER_LITERAL
1812- && context_p -> token .lit_location .type == LEXER_IDENT_LITERAL )
1813- {
1814- lexer_lit_location_t * location_p = scanner_add_literal (context_p , scanner_context_p );
1815-
1816- if (location_p -> type & SCANNER_LITERAL_IS_LOCAL
1817- && !(location_p -> type & SCANNER_LITERAL_IS_FUNC ))
1818- {
1819- scanner_raise_redeclaration_error (context_p );
1820- }
1821- location_p -> type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET ;
1822-
1823- lexer_next_token (context_p );
1824- }
1825- else
1826- {
1827- lexer_lit_location_t * location_p ;
1828- location_p = scanner_add_custom_literal (context_p ,
1829- scanner_context_p -> active_literal_pool_p ,
1830- & lexer_default_literal );
1831- location_p -> type |= SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET ;
1832- }
1833-
1834- scanner_push_literal_pool (context_p , scanner_context_p , SCANNER_LITERAL_POOL_FUNCTION );
1835-
1836- parser_stack_push_uint8 (context_p , SCAN_STACK_FUNCTION_STATEMENT );
1837- scanner_context_p -> mode = SCAN_MODE_FUNCTION_ARGUMENTS ;
1838- return SCAN_KEEP_TOKEN ;
1839- }
1840-
1841- if (context_p -> token .type == LEXER_KEYW_CLASS )
1842- {
1843- lexer_lit_location_t * literal_p ;
1844- literal_p = scanner_push_class_declaration (context_p , scanner_context_p , SCAN_STACK_CLASS_STATEMENT );
1845-
1846- if (literal_p != NULL )
1847- {
1848- scanner_detect_invalid_let (context_p , literal_p );
1849-
1850- if (literal_p -> type & SCANNER_LITERAL_IS_USED )
1851- {
1852- literal_p -> type |= SCANNER_LITERAL_EARLY_CREATE ;
1853- }
1854-
1855- literal_p -> type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG ;
1856- return SCAN_NEXT_TOKEN ;
1857- }
1858-
1859- literal_p = scanner_add_custom_literal (context_p ,
1860- scanner_context_p -> active_literal_pool_p ,
1861- & lexer_default_literal );
1862-
1863- literal_p -> type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG ;
1864- scanner_context_p -> active_literal_pool_p -> status_flags |= SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME ;
1865- return SCAN_KEEP_TOKEN ;
1866- }
1867-
1868- /* Assignment expression. */
1869- lexer_lit_location_t * location_p ;
1870- location_p = scanner_add_custom_literal (context_p ,
1871- scanner_context_p -> active_literal_pool_p ,
1872- & lexer_default_literal );
1873- location_p -> type |= SCANNER_LITERAL_IS_VAR ;
1844+ parser_stack_push_uint8 (context_p , SCAN_STACK_EXPORT_DEFAULT );
18741845 scanner_context_p -> mode = SCAN_MODE_PRIMARY_EXPRESSION ;
1875-
1876- if (context_p -> token .type != LEXER_LITERAL || context_p -> token .lit_location .type != LEXER_IDENT_LITERAL )
1877- {
1878- return SCAN_KEEP_TOKEN ;
1879- }
1880-
1881- location_p = scanner_add_literal (context_p , scanner_context_p );
1882- location_p -> type |= SCANNER_LITERAL_IS_VAR ;
1883- scanner_context_p -> mode = SCAN_MODE_POST_PRIMARY_EXPRESSION ;
1884- return SCAN_NEXT_TOKEN ;
1846+ return SCAN_KEEP_TOKEN ;
18851847 }
18861848
18871849 scanner_context_p -> mode = SCAN_MODE_STATEMENT_END ;
@@ -2152,6 +2114,16 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
21522114
21532115 scanner_pop_literal_pool (context_p , scanner_context_p );
21542116 parser_stack_pop_uint8 (context_p );
2117+
2118+ #if ENABLED (JERRY_MODULE_SYSTEM )
2119+ if (context_p -> stack_top_uint8 == SCAN_STACK_EXPORT_DEFAULT )
2120+ {
2121+ terminator_found = true;
2122+ parser_stack_pop_uint8 (context_p );
2123+ lexer_next_token (context_p );
2124+ continue ;
2125+ }
2126+ #endif /* ENABLED (JERRY_MODULE_SYSTEM) */
21552127 return SCAN_NEXT_TOKEN ;
21562128 }
21572129 case SCAN_STACK_FUNCTION_PROPERTY :
@@ -2306,6 +2278,17 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
23062278 continue ;
23072279 }
23082280#endif /* ENABLED (JERRY_ESNEXT) */
2281+ #if ENABLED (JERRY_MODULE_SYSTEM )
2282+ case SCAN_STACK_EXPORT_DEFAULT :
2283+ {
2284+ parser_stack_pop_uint8 (context_p );
2285+ lexer_lit_location_t * location_p = scanner_add_custom_literal (context_p ,
2286+ scanner_context_p -> active_literal_pool_p ,
2287+ & lexer_default_literal );
2288+ location_p -> type |= SCANNER_LITERAL_IS_VAR ;
2289+ continue ;
2290+ }
2291+ #endif /* ENABLED (JERRY_MODULE_SYSTEM) */
23092292 default :
23102293 {
23112294 JERRY_ASSERT (context_p -> stack_top_uint8 == SCAN_STACK_TRY_STATEMENT
@@ -2617,6 +2600,16 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
26172600
26182601 scanner_context .mode = SCAN_MODE_POST_PRIMARY_EXPRESSION ;
26192602 parser_stack_pop_uint8 (context_p );
2603+
2604+ #if ENABLED (JERRY_MODULE_SYSTEM )
2605+ if (context_p -> stack_top_uint8 == SCAN_STACK_EXPORT_DEFAULT )
2606+ {
2607+ /* The token is kept to disallow consuming a semicolon after it. */
2608+ parser_stack_change_last_uint8 (context_p , SCAN_STACK_CLASS_STATEMENT );
2609+ scanner_context .mode = SCAN_MODE_STATEMENT_END ;
2610+ continue ;
2611+ }
2612+ #endif /* ENABLED (JERRY_MODULE_SYSTEM) */
26202613 break ;
26212614 }
26222615
0 commit comments