11//! [ECMAScript Module Record](https://tc39.es/ecma262/#sec-abstract-module-records)
2- #![ allow( missing_docs) ] // fixme
3-
4- use std:: fmt;
52
63use oxc_allocator:: { Allocator , Vec } ;
74use oxc_span:: { Atom , Span } ;
@@ -15,6 +12,7 @@ use rustc_hash::FxHashMap;
1512/// See
1613/// * <https://tc39.es/ecma262/#table-additional-fields-of-source-text-module-records>
1714/// * <https://tc39.es/ecma262/#cyclic-module-record>
15+ #[ derive( Debug ) ]
1816pub struct ModuleRecord < ' a > {
1917 /// This module has no import / export statements
2018 pub not_esm : bool ,
@@ -74,6 +72,7 @@ pub struct ModuleRecord<'a> {
7472}
7573
7674impl < ' a > ModuleRecord < ' a > {
75+ /// Constructor
7776 pub fn new ( allocator : & ' a Allocator ) -> Self {
7877 Self {
7978 not_esm : true ,
@@ -91,30 +90,18 @@ impl<'a> ModuleRecord<'a> {
9190 }
9291}
9392
94- impl fmt:: Debug for ModuleRecord < ' _ > {
95- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
96- f. debug_struct ( "ModuleRecord" )
97- . field ( "not_esm" , & self . not_esm )
98- . field ( "import_entries" , & self . import_entries )
99- . field ( "local_export_entries" , & self . local_export_entries )
100- . field ( "indirect_export_entries" , & self . indirect_export_entries )
101- . field ( "star_export_entries" , & self . star_export_entries )
102- . field ( "exported_bindings" , & self . exported_bindings )
103- . field ( "exported_bindings_duplicated" , & self . exported_bindings_duplicated )
104- . field ( "exported_bindings_from_star_export" , & self . exported_bindings_from_star_export )
105- . field ( "export_default" , & self . export_default )
106- . field ( "export_default_duplicated" , & self . export_default_duplicated )
107- . finish ( )
108- }
109- }
110-
93+ /// Name and Span
11194#[ derive( Debug , Clone , PartialEq , Eq ) ]
11295pub struct NameSpan < ' a > {
96+ /// Name
11397 pub name : Atom < ' a > ,
98+
99+ /// Span
114100 pub span : Span ,
115101}
116102
117103impl < ' a > NameSpan < ' a > {
104+ /// Constructor
118105 pub fn new ( name : Atom < ' a > , span : Span ) -> Self {
119106 Self { name, span }
120107 }
@@ -193,16 +180,21 @@ pub struct ImportEntry<'a> {
193180/// `ImportName` For `ImportEntry`
194181#[ derive( Debug , Clone , PartialEq , Eq ) ]
195182pub enum ImportImportName < ' a > {
183+ /// Name
196184 Name ( NameSpan < ' a > ) ,
185+ /// Namespace Object
197186 NamespaceObject ,
187+ /// Default
198188 Default ( Span ) ,
199189}
200190
201191impl ImportImportName < ' _ > {
192+ /// Is `default`
202193 pub fn is_default ( & self ) -> bool {
203194 matches ! ( self , Self :: Default ( _) )
204195 }
205196
197+ /// Is namespace
206198 pub fn is_namespace_object ( & self ) -> bool {
207199 matches ! ( self , Self :: NamespaceObject )
208200 }
@@ -253,6 +245,7 @@ pub struct ExportEntry<'a> {
253245/// `ImportName` for `ExportEntry`
254246#[ derive( Debug , Default , Clone , PartialEq , Eq ) ]
255247pub enum ExportImportName < ' a > {
248+ /// Name
256249 Name ( NameSpan < ' a > ) ,
257250 /// all is used for export * as ns from "mod" declarations.
258251 All ,
@@ -263,11 +256,14 @@ pub enum ExportImportName<'a> {
263256 Null ,
264257}
265258
259+ /// Export Import Name
266260impl ExportImportName < ' _ > {
261+ /// Is all
267262 pub fn is_all ( & self ) -> bool {
268263 matches ! ( self , Self :: All )
269264 }
270265
266+ /// Is all but default
271267 pub fn is_all_but_default ( & self ) -> bool {
272268 matches ! ( self , Self :: AllButDefault )
273269 }
@@ -276,8 +272,11 @@ impl ExportImportName<'_> {
276272/// `ExportName` for `ExportEntry`
277273#[ derive( Debug , Default , Clone , PartialEq , Eq ) ]
278274pub enum ExportExportName < ' a > {
275+ /// Name
279276 Name ( NameSpan < ' a > ) ,
277+ /// Default
280278 Default ( Span ) ,
279+ /// Null
281280 #[ default]
282281 Null ,
283282}
@@ -306,9 +305,11 @@ impl ExportExportName<'_> {
306305/// `LocalName` for `ExportEntry`
307306#[ derive( Debug , Default , Clone , PartialEq , Eq ) ]
308307pub enum ExportLocalName < ' a > {
308+ /// Name
309309 Name ( NameSpan < ' a > ) ,
310310 /// `export default name_span`
311311 Default ( NameSpan < ' a > ) ,
312+ /// Null
312313 #[ default]
313314 Null ,
314315}
@@ -333,22 +334,11 @@ impl<'a> ExportLocalName<'a> {
333334 }
334335}
335336
337+ /// RequestedModule
336338#[ derive( Debug , Clone , Copy ) ]
337339pub struct RequestedModule {
338- span : Span ,
339- is_type : bool ,
340- /// is_import is true if the module is requested by an import statement.
341- is_import : bool ,
342- }
343-
344- impl RequestedModule {
345- pub fn new ( span : Span , is_type : bool , is_import : bool ) -> Self {
346- Self { span, is_type, is_import }
347- }
348-
349- pub fn span ( & self ) -> Span {
350- self . span
351- }
340+ /// Span
341+ pub span : Span ,
352342
353343 /// `true` if a `type` modifier was used in the import statement.
354344 ///
@@ -358,13 +348,16 @@ impl RequestedModule {
358348 /// import { type bar } from "bar"; // false, `type` is on specifier
359349 /// import { baz } from "baz"; // false, no `type` modifier
360350 /// ```
361- pub fn is_type ( & self ) -> bool {
362- self . is_type
363- }
351+ pub is_type : bool ,
364352
365353 /// `true` if the module is requested by an import statement.
366- pub fn is_import ( & self ) -> bool {
367- self . is_import
354+ pub is_import : bool ,
355+ }
356+
357+ impl RequestedModule {
358+ /// Constructor
359+ pub fn new ( span : Span , is_type : bool , is_import : bool ) -> Self {
360+ Self { span, is_type, is_import }
368361 }
369362}
370363
0 commit comments