fileoverview export class RedirectManager { private _redirects : Map < string , string > = new Map ( ) ; /** Adds a new `hop` to the list */ public add ( destination , source ) { this . _redirects . set ( destination , source ) ; } /**
     * Calculates the number of `hop`s for a given target.
     *
     *  Known issues: it doesn't support multiple redirects to the same url. This shouldn't happen very
     * often in the same page
     */ public calculate ( target ) { let targetUrl = target ; const hops = [ targetUrl ] ; while ( this . _redirects . has ( targetUrl ) ) { targetUrl = this . _redirects . get ( targetUrl ) ! ; const finish = hops . includes ( targetUrl ) ; hops . unshift ( targetUrl ) ; if ( finish ) { break ; } } hops . pop ( ) ; return hops ; } }