@@ -101,6 +101,9 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
101
101
case LEXER_KEYW_FUNCTION :
102
102
{
103
103
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) */
104
107
105
108
#if ENABLED (JERRY_ESNEXT )
106
109
if (scanner_context_p -> async_source_p != NULL )
@@ -121,8 +124,30 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
121
124
if (context_p -> token .type == LEXER_LITERAL
122
125
&& context_p -> token .lit_location .type == LEXER_IDENT_LITERAL )
123
126
{
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) */
124
139
lexer_next_token (context_p );
125
140
}
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) */
126
151
127
152
parser_stack_push_uint8 (context_p , SCAN_STACK_FUNCTION_EXPRESSION );
128
153
scanner_context_p -> mode = SCAN_MODE_FUNCTION_ARGUMENTS ;
@@ -179,7 +204,8 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
179
204
scanner_scan_simple_arrow (context_p , scanner_context_p , source_p );
180
205
return SCAN_KEEP_TOKEN ;
181
206
}
182
- else if (JERRY_UNLIKELY (lexer_token_is_async (context_p )))
207
+
208
+ if (JERRY_UNLIKELY (lexer_token_is_async (context_p )))
183
209
{
184
210
scanner_context_p -> async_source_p = source_p ;
185
211
scanner_check_async_function (context_p , scanner_context_p );
@@ -189,6 +215,17 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
189
215
190
216
if (context_p -> token .lit_location .type == LEXER_IDENT_LITERAL )
191
217
{
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
+
192
229
scanner_add_reference (context_p , scanner_context_p );
193
230
}
194
231
/* FALLTHRU */
@@ -1804,84 +1841,9 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
1804
1841
if (context_p -> token .type == LEXER_KEYW_DEFAULT )
1805
1842
{
1806
1843
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 );
1874
1845
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 ;
1885
1847
}
1886
1848
1887
1849
scanner_context_p -> mode = SCAN_MODE_STATEMENT_END ;
@@ -2152,6 +2114,16 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
2152
2114
2153
2115
scanner_pop_literal_pool (context_p , scanner_context_p );
2154
2116
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) */
2155
2127
return SCAN_NEXT_TOKEN ;
2156
2128
}
2157
2129
case SCAN_STACK_FUNCTION_PROPERTY :
@@ -2306,6 +2278,17 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
2306
2278
continue ;
2307
2279
}
2308
2280
#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) */
2309
2292
default :
2310
2293
{
2311
2294
JERRY_ASSERT (context_p -> stack_top_uint8 == SCAN_STACK_TRY_STATEMENT
@@ -2617,6 +2600,16 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
2617
2600
2618
2601
scanner_context .mode = SCAN_MODE_POST_PRIMARY_EXPRESSION ;
2619
2602
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) */
2620
2613
break ;
2621
2614
}
2622
2615
0 commit comments