@@ -354,22 +354,7 @@ impl<'s> PostTransformChecker<'s> {
354354 let symbol_ids = self . get_pair ( scope_ids, |data, scope_id| {
355355 data. scopes . get_bindings ( scope_id) . values ( ) . copied ( ) . collect :: < Vec < _ > > ( )
356356 } ) ;
357-
358- let mut symbol_ids_after_transform = symbol_ids
359- . after_transform
360- . iter ( )
361- . map ( |& symbol_id| self . symbol_ids_map . get ( symbol_id) )
362- . collect :: < Vec < _ > > ( ) ;
363- symbol_ids_after_transform. sort_unstable ( ) ;
364- let mut symbol_ids_rebuilt = symbol_ids
365- . rebuilt
366- . iter ( )
367- . copied ( )
368- . map ( Option :: Some )
369- . collect :: < Vec < _ > > ( ) ;
370- symbol_ids_rebuilt. sort_unstable ( ) ;
371-
372- if symbol_ids_after_transform != symbol_ids_rebuilt {
357+ if self . remap_symbol_ids_sets ( & symbol_ids) . is_mismatch ( ) {
373358 self . errors . push_mismatch (
374359 "Binding symbols mismatch" ,
375360 scope_ids,
@@ -421,19 +406,7 @@ impl<'s> PostTransformChecker<'s> {
421406 // Check children match
422407 let child_ids = self
423408 . get_pair ( scope_ids, |data, scope_id| data. scopes . get_child_ids ( scope_id) . to_vec ( ) ) ;
424- let is_match = child_ids. after_transform . len ( ) == child_ids. rebuilt . len ( ) && {
425- let mut child_ids_after_transform = child_ids
426- . after_transform
427- . iter ( )
428- . map ( |& child_id| self . scope_ids_map . get ( child_id) )
429- . collect :: < Vec < _ > > ( ) ;
430- child_ids_after_transform. sort_unstable ( ) ;
431- let mut child_ids_rebuilt =
432- child_ids. rebuilt . iter ( ) . copied ( ) . map ( Option :: Some ) . collect :: < Vec < _ > > ( ) ;
433- child_ids_rebuilt. sort_unstable ( ) ;
434- child_ids_after_transform == child_ids_rebuilt
435- } ;
436- if !is_match {
409+ if self . remap_scope_ids_sets ( & child_ids) . is_mismatch ( ) {
437410 self . errors . push_mismatch ( "Scope children mismatch" , scope_ids, child_ids) ;
438411 }
439412 }
@@ -542,6 +515,43 @@ impl<'s> PostTransformChecker<'s> {
542515 fn remap_scope_ids ( & self , scope_ids : Pair < ScopeId > ) -> Pair < Option < ScopeId > > {
543516 Pair :: new ( self . scope_ids_map . get ( scope_ids. after_transform ) , Some ( scope_ids. rebuilt ) )
544517 }
518+
519+ /// Remap pair of arrays of `ScopeId`s.
520+ /// Map `after_transform` IDs to `rebuilt` IDs.
521+ /// Sort both sets.
522+ fn remap_scope_ids_sets ( & self , scope_ids : & Pair < Vec < ScopeId > > ) -> Pair < Vec < Option < ScopeId > > > {
523+ let mut after_transform = scope_ids
524+ . after_transform
525+ . iter ( )
526+ . map ( |& scope_id| self . scope_ids_map . get ( scope_id) )
527+ . collect :: < Vec < _ > > ( ) ;
528+ let mut rebuilt = scope_ids. rebuilt . iter ( ) . copied ( ) . map ( Option :: Some ) . collect :: < Vec < _ > > ( ) ;
529+
530+ after_transform. sort_unstable ( ) ;
531+ rebuilt. sort_unstable ( ) ;
532+
533+ Pair :: new ( after_transform, rebuilt)
534+ }
535+
536+ /// Remap pair of arrays of `SymbolId`s.
537+ /// Map `after_transform` IDs to `rebuilt` IDs.
538+ /// Sort both sets.
539+ fn remap_symbol_ids_sets (
540+ & self ,
541+ symbol_ids : & Pair < Vec < SymbolId > > ,
542+ ) -> Pair < Vec < Option < SymbolId > > > {
543+ let mut after_transform = symbol_ids
544+ . after_transform
545+ . iter ( )
546+ . map ( |& symbol_id| self . symbol_ids_map . get ( symbol_id) )
547+ . collect :: < Vec < _ > > ( ) ;
548+ let mut rebuilt = symbol_ids. rebuilt . iter ( ) . copied ( ) . map ( Option :: Some ) . collect :: < Vec < _ > > ( ) ;
549+
550+ after_transform. sort_unstable ( ) ;
551+ rebuilt. sort_unstable ( ) ;
552+
553+ Pair :: new ( after_transform, rebuilt)
554+ }
545555}
546556
547557/// Collection of `ScopeId`s, `SymbolId`s and `ReferenceId`s from an AST.
0 commit comments