@@ -218,7 +218,7 @@ impl<'a> ParserImpl<'a> {
218
218
span : Span ,
219
219
) -> Result < Box < ' a , ExportNamedDeclaration < ' a > > > {
220
220
let export_kind = self . parse_import_or_export_kind ( ) ;
221
- let specifiers =
221
+ let mut specifiers =
222
222
self . context ( Context :: empty ( ) , self . ctx , ExportNamedSpecifiers :: parse) ?. elements ;
223
223
let ( source, with_clause) = if self . eat ( Kind :: From ) && self . cur_kind ( ) . is_literal ( ) {
224
224
let source = self . parse_literal_string ( ) ?;
@@ -229,7 +229,7 @@ impl<'a> ParserImpl<'a> {
229
229
230
230
// ExportDeclaration : export NamedExports ;
231
231
if source. is_none ( ) {
232
- for specifier in & specifiers {
232
+ for specifier in specifiers. iter_mut ( ) {
233
233
match & specifier. local {
234
234
// It is a Syntax Error if ReferencedBindings of NamedExports contains any StringLiterals.
235
235
ModuleExportName :: StringLiteral ( literal) => {
@@ -242,18 +242,25 @@ impl<'a> ParserImpl<'a> {
242
242
// For each IdentifierName n in ReferencedBindings of NamedExports:
243
243
// It is a Syntax Error if StringValue of n is a ReservedWord or the StringValue of n
244
244
// is one of "implements", "interface", "let", "package", "private", "protected", "public", or "static".
245
- ModuleExportName :: Identifier ( id ) => {
246
- let match_result = Kind :: match_keyword ( & id . name ) ;
245
+ ModuleExportName :: IdentifierName ( ident ) => {
246
+ let match_result = Kind :: match_keyword ( & ident . name ) ;
247
247
if match_result. is_reserved_keyword ( )
248
248
|| match_result. is_future_reserved_keyword ( )
249
249
{
250
250
self . error ( diagnostics:: export_reserved_word (
251
251
& specifier. local . to_string ( ) ,
252
252
& specifier. exported . to_string ( ) ,
253
- id . span ,
253
+ ident . span ,
254
254
) ) ;
255
255
}
256
+
257
+ // `local` becomes a reference for `export { local }`.
258
+ specifier. local = ModuleExportName :: IdentifierReference (
259
+ self . ast . identifier_reference ( ident. span , ident. name . as_str ( ) ) ,
260
+ ) ;
256
261
}
262
+ // No prior code path should lead to parsing `ModuleExportName` as `IdentifierReference`.
263
+ ModuleExportName :: IdentifierReference ( _) => unreachable ! ( ) ,
257
264
}
258
265
}
259
266
}
@@ -343,7 +350,7 @@ impl<'a> ParserImpl<'a> {
343
350
decl
344
351
}
345
352
} ;
346
- let exported = ModuleExportName :: Identifier ( exported) ;
353
+ let exported = ModuleExportName :: IdentifierName ( exported) ;
347
354
let span = self . end_span ( span) ;
348
355
Ok ( self . ast . export_default_declaration ( span, declaration, exported) )
349
356
}
@@ -400,7 +407,7 @@ impl<'a> ParserImpl<'a> {
400
407
} else {
401
408
let local = self . parse_binding_identifier ( ) ?;
402
409
let imported = IdentifierName { span : local. span , name : local. name . clone ( ) } ;
403
- ( ModuleExportName :: Identifier ( imported) , local)
410
+ ( ModuleExportName :: IdentifierName ( imported) , local)
404
411
} ;
405
412
Ok ( self . ast . alloc ( ImportSpecifier {
406
413
span : self . end_span ( specifier_span) ,
@@ -424,7 +431,7 @@ impl<'a> ParserImpl<'a> {
424
431
} ;
425
432
Ok ( ModuleExportName :: StringLiteral ( literal) )
426
433
}
427
- _ => Ok ( ModuleExportName :: Identifier ( self . parse_identifier_name ( ) ?) ) ,
434
+ _ => Ok ( ModuleExportName :: IdentifierName ( self . parse_identifier_name ( ) ?) ) ,
428
435
}
429
436
}
430
437
0 commit comments