@@ -285,6 +285,8 @@ function cleanUpContainer(container: string): string {
285285 container = container . replace ( / = / g, ' = ' ) ;
286286 container = container . replace ( / \( / g, ' ( ' ) ;
287287 container = container . replace ( / \) / g, ' ) ' ) ;
288+ container = container . replace ( / \[ / g, ' [ ' ) ;
289+ container = container . replace ( / \] / g, ' ] ' ) ;
288290 container = container . replace ( / \/ \/ / g, ' // ' ) ;
289291 container = container . replace ( / \/ \* / g, ' /* ' ) ;
290292
@@ -326,7 +328,7 @@ function findMaxLength(container: string, moduleIsParameterized: boolean): numbe
326328 let lastPort : string = undefined ; // eslint-disable-line no-undef-init
327329 let lastParameter : string = undefined ; // eslint-disable-line no-undef-init
328330 let passedEqualSign = false ;
329-
331+ let numBracketPast = 0 ;
330332 let state = ProcessingState . INITIAL ;
331333
332334 for ( let i = 0 ; i < keys . length ; i ++ ) {
@@ -351,7 +353,13 @@ function findMaxLength(container: string, moduleIsParameterized: boolean): numbe
351353 }
352354 } else if ( state === ProcessingState . PARAMETERS ) {
353355 if ( keys [ i ] === ')' ) {
354- state = ProcessingState . PORTS ;
356+ if ( numBracketPast === 0 ) {
357+ state = ProcessingState . PORTS ;
358+ } else {
359+ numBracketPast -= 1 ;
360+ }
361+ } else if ( keys [ i ] === '(' ) {
362+ numBracketPast += 1 ;
355363 } else if ( keys [ i ] === ',' && lastParameter ) {
356364 maxLength = Math . max ( lastParameter . length , maxLength ) ;
357365 lastParameter = undefined ;
@@ -369,13 +377,19 @@ function findMaxLength(container: string, moduleIsParameterized: boolean): numbe
369377 lastParameter = undefined ;
370378 }
371379
372- if ( keys [ i ] === ')' ) {
380+ if ( keys [ i ] === ')' && numBracketPast == 0 ) {
373381 state = ProcessingState . COMPLETE ;
374382 } else if ( keys [ i ] === ',' && lastPort ) {
375383 maxLength = Math . max ( lastPort . length , maxLength ) ;
376384 lastPort = undefined ;
385+ } else if ( keys [ i ] === '[' ) {
386+ numBracketPast += 1 ;
387+ } else if ( keys [ i ] === ']' ) {
388+ numBracketPast -= 1 ;
377389 } else if ( ! isPortSymbol ( keys [ i ] ) && ! isEmptyKey ( keys [ i ] ) ) {
378- lastPort = keys [ i ] . trim ( ) ;
390+ if ( numBracketPast == 0 ) {
391+ lastPort = keys [ i ] . trim ( ) ;
392+ }
379393 }
380394 }
381395
@@ -416,14 +430,16 @@ function parseContainer(symbol: string, container: string, moduleIsParameterized
416430 }
417431
418432 const output = [ ] ;
433+
419434 const keys = container . split ( ' ' ) ;
420435
421436 // This is a bit funky, but the for loop below actually checks if these varaibles
422437 // are undefined so it is important that they are initialized as such
423438 let lastPort : string = undefined ; // eslint-disable-line no-undef-init
424439 let lastParameter : string = undefined ; // eslint-disable-line no-undef-init
425- let lastParameterDefault : string = undefined ; // eslint-disable-line no-undef-init
440+ let parameterDefault = [ ] ;
426441
442+ let numBracketPast = 0 ;
427443 let passedEqualSign = false ;
428444
429445 let state = ProcessingState . INITIAL ;
@@ -450,14 +466,19 @@ function parseContainer(symbol: string, container: string, moduleIsParameterized
450466 }
451467 } else if ( state === ProcessingState . PARAMETERS ) {
452468 if ( keys [ i ] === ')' ) {
453- state = ProcessingState . PORTS ;
469+ if ( numBracketPast === 0 ) {
470+ state = ProcessingState . PORTS ;
471+ } else {
472+ numBracketPast -= 1 ;
473+ parameterDefault . push ( keys [ i ] . trim ( ) ) ;
474+ }
454475 } else if ( keys [ i ] === ',' && lastParameter ) {
455476 // Set with default value if it exists
456477 if ( passedEqualSign ) {
457478 output . push (
458479 `${ padding } .${ lastParameter } ${ ' ' . repeat ( maxLength - lastParameter . length ) } ${ ' ' . repeat ( 4 ) } (`
459480 ) ;
460- output . push ( `${ lastParameterDefault } )` ) ;
481+ output . push ( `${ parameterDefault . join ( '' ) } )` ) ; // This will butcher default values for strings with spaces included, sorry.
461482
462483 passedEqualSign = false ;
463484 } else {
@@ -472,9 +493,13 @@ function parseContainer(symbol: string, container: string, moduleIsParameterized
472493 lastParameter = undefined ;
473494 } else if ( keys [ i ] === '=' ) {
474495 passedEqualSign = true ;
496+ parameterDefault = [ ] ;
475497 } else if ( ! isParameterSymbol ( keys [ i ] ) && ! isEmptyKey ( keys [ i ] ) ) {
476498 if ( passedEqualSign ) {
477- lastParameterDefault = keys [ i ] . trim ( ) ;
499+ if ( keys [ i ] === '(' ) {
500+ numBracketPast += 1 ;
501+ }
502+ parameterDefault . push ( keys [ i ] . trim ( ) ) ;
478503 } else {
479504 lastParameter = keys [ i ] . trim ( ) ;
480505 }
@@ -486,7 +511,7 @@ function parseContainer(symbol: string, container: string, moduleIsParameterized
486511 output . push (
487512 `${ padding } .${ lastParameter } ${ ' ' . repeat ( maxLength - lastParameter . length ) } ${ ' ' . repeat ( 4 ) } (`
488513 ) ;
489- output . push ( `${ lastParameterDefault } )\n` ) ;
514+ output . push ( `${ parameterDefault . join ( '' ) } )\n` ) ;
490515
491516 passedEqualSign = false ;
492517 } else {
@@ -500,7 +525,7 @@ function parseContainer(symbol: string, container: string, moduleIsParameterized
500525 lastParameter = undefined ;
501526 }
502527
503- if ( keys [ i ] === ')' ) {
528+ if ( keys [ i ] === ')' && numBracketPast == 0 ) {
504529 state = ProcessingState . COMPLETE ;
505530 } else if ( keys [ i ] === ',' && lastPort ) {
506531 output . push (
@@ -510,7 +535,13 @@ function parseContainer(symbol: string, container: string, moduleIsParameterized
510535
511536 lastPort = undefined ;
512537 } else if ( ! isPortSymbol ( keys [ i ] ) && ! isEmptyKey ( keys [ i ] ) ) {
513- lastPort = keys [ i ] . trim ( ) ;
538+ if ( keys [ i ] === '[' ) {
539+ numBracketPast += 1 ;
540+ } else if ( keys [ i ] === ']' ) {
541+ numBracketPast -= 1 ;
542+ } else if ( numBracketPast == 0 ) {
543+ lastPort = keys [ i ] . trim ( ) ;
544+ }
514545 }
515546 }
516547
@@ -522,7 +553,7 @@ function parseContainer(symbol: string, container: string, moduleIsParameterized
522553 output . push (
523554 `${ padding } .${ lastParameter } ${ ' ' . repeat ( maxLength - lastParameter . length ) } ${ ' ' . repeat ( 4 ) } (`
524555 ) ;
525- output . push ( `${ lastParameterDefault } )\n` ) ;
556+ output . push ( `${ parameterDefault . join ( '' ) } )\n` ) ;
526557
527558 passedEqualSign = false ;
528559 } else {
0 commit comments