1+ var $$UMFP ; // reference to $UrlMatcherFactoryProvider
2+
13/**
24 * @ngdoc object
35 * @name ui.router.util.type:UrlMatcher
@@ -80,12 +82,12 @@ function UrlMatcher(pattern, config) {
8082 searchPlaceholder = / ( [: ] ? ) ( [ \w - ] + ) | \{ ( \w + ) (?: \: ( (?: [ ^ { } \\ ] + | \\ .| \{ (?: [ ^ { } \\ ] + | \\ .) * \} ) + ) ) ? \} / g,
8183 compiled = '^' , last = 0 , m ,
8284 segments = this . segments = [ ] ,
83- params = this . params = new $$UrlMatcherFactoryProvider . ParamSet ( ) ;
85+ params = this . params = new $$UMFP . ParamSet ( ) ;
8486
8587 function addParameter ( id , type , config ) {
8688 if ( ! / ^ \w + ( - + \w + ) * $ / . test ( id ) ) throw new Error ( "Invalid parameter name '" + id + "' in pattern '" + pattern + "'" ) ;
8789 if ( params [ id ] ) throw new Error ( "Duplicate parameter name '" + id + "' in pattern '" + pattern + "'" ) ;
88- params [ id ] = new $$UrlMatcherFactoryProvider . Param ( id , type , config ) ;
90+ params [ id ] = new $$UMFP . Param ( id , type , config ) ;
8991 return params [ id ] ;
9092 }
9193
@@ -102,13 +104,12 @@ function UrlMatcher(pattern, config) {
102104 // The number of segments is always 1 more than the number of parameters.
103105 function matchDetails ( m , isSearch ) {
104106 var id , regexp , segment , type , typeId , cfg ;
105- var $types = UrlMatcher . prototype . $types ;
106107 var defaultTypeId = ( isSearch ? "searchParam" : "pathParam" ) ;
107108 id = m [ 2 ] || m [ 3 ] ; // IE[78] returns '' for unmatched groups instead of null
108109 segment = pattern . substring ( last , m . index ) ;
109110 regexp = isSearch ? m [ 4 ] : m [ 4 ] || ( m [ 1 ] == '*' ? '.*' : null ) ;
110111 typeId = regexp || defaultTypeId ;
111- type = $types [ typeId ] || extend ( { } , $types [ defaultTypeId ] , { pattern : new RegExp ( regexp ) } ) ;
112+ type = $$UMFP . type ( typeId ) || extend ( { } , $$UMFP . type ( defaultTypeId ) , { pattern : new RegExp ( regexp ) } ) ;
112113 cfg = config . params [ id ] ;
113114 return {
114115 id : id , regexp : regexp , segment : segment , type : type , cfg : cfg
@@ -182,7 +183,7 @@ UrlMatcher.prototype.concat = function (pattern, config) {
182183 // Because order of search parameters is irrelevant, we can add our own search
183184 // parameters to the end of the new pattern. Parse the new pattern by itself
184185 // and then join the bits together, but it's much easier to do this on a string level.
185- return $$UrlMatcherFactoryProvider . compile ( this . sourcePath + pattern + this . sourceSearch , config ) ;
186+ return $$UMFP . compile ( this . sourcePath + pattern + this . sourceSearch , config ) ;
186187} ;
187188
188189UrlMatcher . prototype . toString = function ( ) {
@@ -322,8 +323,6 @@ UrlMatcher.prototype.format = function (values) {
322323 return result . replace ( '//' , '/' ) ;
323324} ;
324325
325- UrlMatcher . prototype . $types = { } ;
326-
327326/**
328327 * @ngdoc object
329328 * @name ui.router.util.type:Type
@@ -427,7 +426,6 @@ Type.prototype.$subPattern = function() {
427426
428427Type . prototype . pattern = / .* / ;
429428
430- var $$UrlMatcherFactoryProvider ;
431429/**
432430 * @ngdoc object
433431 * @name ui.router.util.$urlMatcherFactory
@@ -437,7 +435,7 @@ var $$UrlMatcherFactoryProvider;
437435 * is also available to providers under the name `$urlMatcherFactoryProvider`.
438436 */
439437function $UrlMatcherFactory ( ) {
440- $$UrlMatcherFactoryProvider = this ;
438+ $$UMFP = this ;
441439
442440 var isCaseInsensitive = false , isStrictMode = true ;
443441
@@ -456,7 +454,7 @@ function $UrlMatcherFactory() {
456454 }
457455 }
458456
459- var enqueue = true , typeQueue = [ ] , injector , defaultTypes = {
457+ var $types , enqueue = true , typeQueue = [ ] , injector , defaultTypes = {
460458 "searchParam" : {
461459 encode : normalizeStringOrArray ,
462460 decode : normalizeStringOrArray ,
@@ -707,7 +705,10 @@ function $UrlMatcherFactory() {
707705 * </pre>
708706 */
709707 this . type = function ( name , def ) {
710- if ( ! isDefined ( def ) ) return UrlMatcher . prototype . $types [ name ] ;
708+ if ( ! isDefined ( def ) ) {
709+ if ( ! isDefined ( $types ) ) throw new Error ( "Please wait until runtime to retrieve types." ) ;
710+ return $types [ name ] ;
711+ }
711712 typeQueue . push ( { name : name , def : def } ) ;
712713 if ( ! enqueue ) flushTypeQueue ( ) ;
713714 return this ;
@@ -717,11 +718,11 @@ function $UrlMatcherFactory() {
717718 this . $get = [ '$injector' , function ( $injector ) {
718719 injector = $injector ;
719720 enqueue = false ;
720- UrlMatcher . prototype . $types = { } ;
721+ $types = { } ;
721722 flushTypeQueue ( ) ;
722723
723724 forEach ( defaultTypes , function ( type , name ) {
724- if ( ! UrlMatcher . prototype . $types [ name ] ) UrlMatcher . prototype . $types [ name ] = new Type ( type ) ;
725+ if ( ! $types [ name ] ) $types [ name ] = new Type ( type ) ;
725726 } ) ;
726727 return this ;
727728 } ] ;
@@ -731,11 +732,11 @@ function $UrlMatcherFactory() {
731732 // before actually wiring up and assigning type definitions
732733 function flushTypeQueue ( ) {
733734 forEach ( typeQueue , function ( type ) {
734- if ( UrlMatcher . prototype . $types [ type . name ] ) {
735+ if ( $types [ type . name ] ) {
735736 throw new Error ( "A type named '" + type . name + "' has already been defined." ) ;
736737 }
737738 var def = new Type ( isInjectable ( type . def ) ? injector . invoke ( type . def ) : type . def ) ;
738- UrlMatcher . prototype . $types [ type . name ] = def ;
739+ $types [ type . name ] = def ;
739740 } ) ;
740741 }
741742
@@ -758,7 +759,7 @@ function $UrlMatcherFactory() {
758759 function getType ( config , urlType ) {
759760 if ( config . type && urlType ) throw new Error ( "Param '" + id + "' has two type configurations." ) ;
760761 if ( urlType ) return urlType ;
761- if ( ! config . type ) return UrlMatcher . prototype . $types . pathParam ;
762+ if ( ! config . type ) return $types . pathParam ;
762763 return config . type instanceof Type ? config . type : new Type ( config . type ) ;
763764 }
764765
0 commit comments