@@ -29,7 +29,7 @@ function addDummy(sources, targets, obj, options, directionS, directionT){
2929
3030 let dummyId = "dummy_" + dummyCount , o , port ;
3131 dummyCount ++ ;
32- obj . children . push ( drawNodeNew ( dummyId , '' , 'Dummy' , sources , options ) ) ;
32+ obj . children . push ( drawNodeNew ( dummyId , dummyId , 'Dummy' , sources , options ) ) ;
3333 if ( sources && sources . length > 0 ) {
3434 o = drawEdgeNew ( sources [ 0 ] , dummyId , obj ) , port = o . targetPort ;
3535 obj . edges . push ( o ) ;
@@ -134,12 +134,13 @@ function drawNodeNew(id, label, type, properties, options){
134134 }
135135 else if ( o . type === 'function' ) {
136136 o . fullFunctionCode = label ;
137- const prettyCode = require ( 'js-beautify' ) ( o . fullFunctionCode )
138-
139- if ( options . renderFunctionsInView ) {
137+ const prettyCode = require ( 'js-beautify' ) ( o . fullFunctionCode ) ,
138+ { nLines, maxLineLength } = textualPropertiesOfCode ( prettyCode )
139+
140+ // uncomment the second clause if you want always to display 1-liner functions inline in the view
141+ if ( options . renderFunctionsInView /*|| nLines === 1*/ ) {
140142 // ok cool, then render this function body directly in the view
141- const { nLines, maxLineLength } = textualPropertiesOfCode ( prettyCode ) ,
142- charWidthForCode = defaultCharWidth * 0.63
143+ const charWidthForCode = defaultCharWidth * 0.63
143144
144145 o . width = Math . min ( maxWidth , maxLineLength * charWidthForCode ) ;
145146 o . height = Math . max ( 2.25 , nLines ) * defaultCharHeight ; // use at least two lines; makes one-line functions look better
@@ -202,12 +203,12 @@ function drawNodeNew(id, label, type, properties, options){
202203 properties . forEach ( s => { // a source id
203204 if ( visited [ s ] ) { // if the source is visited
204205 visited [ s ] . forEach ( a => { // find out if any of its activation was success
205- if ( activations [ a ] . response . success ) { // if so, dummy is visited
206- if ( visited [ dummyId ] == undefined ) {
207- visited [ dummyId ] = [ ] ;
206+ if ( activations [ a ] . response . success ) { // if so, dummy is visited
207+ if ( visited [ o . id ] == undefined ) {
208+ visited [ o . id ] = [ ] ;
208209 o . visited = [ ] ;
209210 }
210- visited [ dummyId ] . push ( a ) ;
211+ visited [ o . id ] . push ( a ) ;
211212 o . visited . push ( a ) ;
212213 }
213214 } )
@@ -331,11 +332,11 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
331332 }
332333 else if ( ir . type === 'if' ) {
333334 let firstTestId = gm . children . length ,
334- lastTestId = ir2graph ( ir . test , gm , `${ id } -test` , undefined , options ) ,
335+ lastTestId = ir2graph ( ir . test , gm , `${ id } -test` , undefined , options ) ,
335336 firstConsId = gm . children . length ,
336- lastConsId = ir2graph ( ir . consequent , gm , `${ id } -consequent` , undefined , options ) ,
337+ lastConsId = ir2graph ( ir . consequent , gm , `${ id } -consequent` , undefined , options ) ,
337338 firstAltId = gm . children . length ,
338- lastAltId = ir2graph ( ir . alternate , gm , `${ id } -alternate` , undefined , options ) ;
339+ lastAltId = ir2graph ( ir . alternate , gm , `${ id } -alternate` , undefined , options )
339340
340341 if ( prevId ) // connect prevId to the first node in test
341342 prevId . forEach ( pid => gm . edges . push ( drawEdgeNew ( pid , gm . children [ firstTestId ] . id , gm ) ) ) ;
@@ -354,8 +355,9 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
354355 gm . edges . push ( drawEdgeNew ( ltid , gm . children [ firstAltId ] . id , gm , 'false' ) ) ;
355356 else
356357 lastAltId = [ ltid ] ;
357-
358- return lastAltId . concat ( lastConsId ) ;
358+
359+ const exitConcentrator = addDummy ( lastAltId . concat ( lastConsId ) , undefined , gm , options ) ;
360+ return [ exitConcentrator ]
359361 }
360362 else if ( ir . type === 'try' ) {
361363 // insert a compound node for try
0 commit comments