@@ -61,7 +61,7 @@ impl<'a> Default for RewriteOptions<'a> {
6161/// Usually the two things are too distinct to provide a common
6262/// interface however for token lookup and writing back into a writer
6363/// general methods are provided.
64- #[ derive( Debug , Clone ) ]
64+ #[ derive( Debug , Clone , PartialEq ) ]
6565pub enum DecodedMap {
6666 /// Indicates a regular sourcemap
6767 Regular ( SourceMap ) ,
@@ -419,7 +419,7 @@ impl fmt::Display for Token<'_> {
419419}
420420
421421/// Represents a section in a sourcemap index
422- #[ derive( Debug , Clone ) ]
422+ #[ derive( Debug , Clone , PartialEq ) ]
423423pub struct SourceMapSection {
424424 offset : ( u32 , u32 ) ,
425425 url : Option < String > ,
@@ -443,20 +443,21 @@ impl<'a> Iterator for SourceMapSectionIter<'a> {
443443}
444444
445445/// Represents a sourcemap index in memory
446- #[ derive( Debug , Clone ) ]
446+ #[ derive( Debug , Clone , PartialEq ) ]
447447pub struct SourceMapIndex {
448448 file : Option < String > ,
449449 sections : Vec < SourceMapSection > ,
450450 x_facebook_offsets : Option < Vec < Option < u32 > > > ,
451451 x_metro_module_paths : Option < Vec < String > > ,
452+ debug_id : Option < DebugId > ,
452453}
453454
454455/// Represents a sourcemap in memory
455456///
456457/// This is always represents a regular "non-indexed" sourcemap. Particularly
457458/// in case the `from_reader` method is used an index sourcemap will be
458459/// rejected with an error on reading.
459- #[ derive( Clone , Debug ) ]
460+ #[ derive( Clone , Debug , PartialEq ) ]
460461pub struct SourceMap {
461462 pub ( crate ) file : Option < Arc < str > > ,
462463 pub ( crate ) tokens : Vec < RawToken > ,
@@ -1078,6 +1079,7 @@ impl SourceMapIndex {
10781079 sections,
10791080 x_facebook_offsets : None ,
10801081 x_metro_module_paths : None ,
1082+ debug_id : None ,
10811083 }
10821084 }
10831085
@@ -1099,9 +1101,21 @@ impl SourceMapIndex {
10991101 sections,
11001102 x_facebook_offsets,
11011103 x_metro_module_paths,
1104+ debug_id : None ,
11021105 }
11031106 }
11041107
1108+ /// Returns the debug ID.
1109+ pub ( crate ) fn debug_id ( & self ) -> Option < DebugId > {
1110+ self . debug_id
1111+ }
1112+
1113+ /// Adds the given debug id to the sourcemap index.
1114+ pub ( crate ) fn with_debug_id ( mut self , debug_id : Option < DebugId > ) -> Self {
1115+ self . debug_id = debug_id;
1116+ self
1117+ }
1118+
11051119 /// Returns the embedded filename in case there is one.
11061120 pub fn get_file ( & self ) -> Option < & str > {
11071121 self . file . as_ref ( ) . map ( |x| & x[ ..] )
@@ -1306,7 +1320,7 @@ impl SourceMapSection {
13061320
13071321#[ cfg( test) ]
13081322mod tests {
1309- use super :: { RewriteOptions , SourceMap } ;
1323+ use super :: { RewriteOptions , SourceMap , SourceMapIndex } ;
13101324 use debugid:: DebugId ;
13111325
13121326 #[ test]
@@ -1416,6 +1430,25 @@ mod tests {
14161430 assert_eq ! ( sm_new. sources, sm. sources) ;
14171431 }
14181432
1433+ #[ test]
1434+ fn test_sourcemap_index_default_debug_id ( ) {
1435+ let sm = SourceMapIndex :: new ( None , vec ! [ ] ) ;
1436+ assert ! ( sm. debug_id( ) . is_none( ) ) ;
1437+ }
1438+
1439+ #[ test]
1440+ fn test_sourcemap_index_debug_id ( ) {
1441+ const DEBUG_ID : & str = "0123456789abcdef0123456789abcdef" ;
1442+
1443+ let sm = SourceMapIndex :: new ( None , vec ! [ ] )
1444+ . with_debug_id ( Some ( DEBUG_ID . parse ( ) . expect ( "valid debug id" ) ) ) ;
1445+
1446+ assert_eq ! (
1447+ sm. debug_id( ) ,
1448+ Some ( DEBUG_ID . parse( ) . expect( "valid debug id" ) )
1449+ ) ;
1450+ }
1451+
14191452 mod prop {
14201453 //! This module exists to test the following property:
14211454 //!
0 commit comments