@@ -136,6 +136,8 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
136136 let previewCompletionCounter = 0 ;
137137 let completionPreview = null ;
138138
139+ let wrapped = false ;
140+
139141 function getPreviewPos ( ) {
140142 const displayPos = repl . _getDisplayPos ( `${ repl . _prompt } ${ repl . line } ` ) ;
141143 const cursorPos = repl . line . length !== repl . cursor ?
@@ -244,8 +246,9 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
244246 function getInputPreview ( input , callback ) {
245247 // For similar reasons as `defaultEval`, wrap expressions starting with a
246248 // curly brace with parenthesis.
247- if ( input . startsWith ( '{' ) && ! input . endsWith ( ';' ) ) {
249+ if ( input . startsWith ( '{' ) && ! input . endsWith ( ';' ) && ! wrapped ) {
248250 input = `(${ input } )` ;
251+ wrapped = true ;
249252 }
250253 sendInspectorCommand ( ( session ) => {
251254 session . post ( 'Runtime.evaluate' , {
@@ -329,13 +332,19 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
329332 return ;
330333 }
331334
332- getInputPreview ( line , ( error , inspected ) => {
335+ const inputPreviewCallback = ( error , inspected ) => {
336+ if ( inspected === null ) {
337+ return ;
338+ }
339+
340+ wrapped = false ;
341+
333342 // Ignore the output if the value is identical to the current line and the
334343 // former preview is not identical to this preview.
335- if ( ( line === inspected && lastInputPreview !== inspected ) ||
336- inspected === null ) {
344+ if ( line === inspected && lastInputPreview !== inspected ) {
337345 return ;
338346 }
347+
339348 if ( error ) {
340349 debug ( 'Error while generating preview' , error ) ;
341350 return ;
@@ -386,7 +395,13 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
386395 repl . output . write ( `\n${ result } ` ) ;
387396 cursorTo ( repl . output , cursorPos . cols ) ;
388397 moveCursor ( repl . output , 0 , - rows - 1 ) ;
389- } ) ;
398+ } ;
399+
400+ getInputPreview ( line , inputPreviewCallback ) ;
401+ if ( wrapped ) {
402+ getInputPreview ( line , inputPreviewCallback ) ;
403+ }
404+ wrapped = false ;
390405 } ;
391406
392407 // -------------------------------------------------------------------------//
0 commit comments