File tree Expand file tree Collapse file tree 4 files changed +19
-6
lines changed
Expand file tree Collapse file tree 4 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -288,7 +288,17 @@ export class StateBuilder {
288288
289289 parentName ( state : State ) {
290290 let name = state . name || "" ;
291- if ( name . indexOf ( '.' ) !== - 1 ) return name . substring ( 0 , name . lastIndexOf ( '.' ) ) ;
291+
292+ let segments = name . split ( '.' ) ;
293+ if ( segments . length > 1 ) {
294+ if ( state . parent ) {
295+ throw new Error ( `States that specify the 'parent:' property should not have a '.' in their name (${ name } )` ) ;
296+ }
297+ var lastSegment = segments . pop ( ) ;
298+ if ( lastSegment === '**' ) segments . pop ( ) ;
299+ return segments . join ( "." ) ;
300+ }
301+
292302 if ( ! state . parent ) return "" ;
293303 return isString ( state . parent ) ? state . parent : state . parent . name ;
294304 }
Original file line number Diff line number Diff line change @@ -26,9 +26,7 @@ export class StateMatcher {
2626 return state ;
2727 } else if ( isStr ) {
2828 let matches = values ( this . _states )
29- . map ( state => ( { state, glob : new Glob ( state . name ) } ) )
30- . filter ( ( { state, glob} ) => glob . matches ( name ) )
31- . map ( ( { state, glob} ) => state ) ;
29+ . filter ( state => new Glob ( state . name ) . matches ( name ) ) ;
3230
3331 if ( matches . length > 1 ) {
3432 console . log ( `stateMatcher.find: Found multiple matches for ${ name } using glob: ` , matches . map ( match => match . name ) ) ;
Original file line number Diff line number Diff line change @@ -13,8 +13,9 @@ describe('state helpers', function() {
1313 states [ 'home.about.people.person' ] = { name : 'home.about.people.person' , parent : states [ 'home.about.people' ] } ;
1414 states [ 'home.about.company' ] = { name : 'home.about.company' , parent : states [ 'home.about' ] } ;
1515 states [ 'other' ] = { name : 'other' , parent : states [ '' ] } ;
16- states [ 'other.foo' ] = { name : 'other.foo' , parent : states [ 'other' ] } ;
16+ states [ 'other.foo' ] = { name : 'other.foo' } ;
1717 states [ 'other.foo.bar' ] = { name : 'other.foo.bar' } ;
18+ states [ 'home.error' ] = { name : 'home.error' , parent : states [ 'home' ] } ;
1819
1920 states [ 'home.withData' ] = {
2021 name : 'home.withData' ,
@@ -106,6 +107,9 @@ describe('state helpers', function() {
106107 it ( 'should return empty string if state has no parent' , function ( ) {
107108 expect ( builder . parentName ( states [ '' ] ) ) . toBe ( "" ) ;
108109 } ) ;
110+ it ( 'should error if parent: is specified *AND* the state name has a dot (.) in it' , function ( ) {
111+ expect ( ( ) => builder . parentName ( states [ 'home.error' ] ) ) . toThrowError ( ) ;
112+ } ) ;
109113 } ) ;
110114 } ) ;
111115
Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ export function tree2Array(tree, inheritName) {
88 function processState ( parent , state , name ) {
99 var substates = omit . apply ( null , [ state ] . concat ( stateProps ) ) ;
1010 var thisState = pick . apply ( null , [ state ] . concat ( stateProps ) ) ;
11- thisState = extend ( thisState , { name : name , parent : parent } ) ;
11+ thisState . name = name ;
12+ if ( ! inheritName ) thisState . parent = parent ;
1213
1314 return [ thisState ] . concat ( processChildren ( thisState , substates ) ) ;
1415 }
You can’t perform that action at this time.
0 commit comments