@@ -70,7 +70,6 @@ export function createRuntime(initialCode) {
7070  let  code  =  initialCode ; 
7171  let  prevCode  =  null ; 
7272  let  isRunning  =  false ; 
73-   let  noSyntaxError  =  false ; 
7473
7574  const  runtime  =  new  Runtime ( BUILTINS ) ; 
7675  const  main  =  runtime . module ( ) ; 
@@ -129,9 +128,10 @@ export function createRuntime(initialCode) {
129128        if  ( isRunning )  rerun ( code ) ; 
130129      } , 
131130      rejected ( error )  { 
132-         console . error ( error ) ; 
131+         const  e  =  state . syntaxError  ||  error ; 
132+         console . error ( e ) ; 
133133        clear ( state ) ; 
134-         echo ( state ,  error ) ; 
134+         echo ( state ,  e ) ; 
135135      } , 
136136    } ; 
137137  } 
@@ -149,16 +149,11 @@ export function createRuntime(initialCode) {
149149    } 
150150  } 
151151
152-   function  transpile ( cell ,   code )  { 
152+   function  transpile ( cell )  { 
153153    try  { 
154154      return  transpileJavaScript ( cell ) ; 
155155    }  catch  ( error )  { 
156-       console . error ( error ) ; 
157-       const  changes  =  removeChanges ( code ) ; 
158-       const  errorMsg  =  formatError ( error )  +  "\n" ; 
159-       changes . push ( { from : 0 ,  insert : errorMsg } ) ; 
160-       dispatch ( changes ) ; 
161-       return  null ; 
156+       return  { body : cell ,  inputs : [ ] ,  outputs : [ ] ,  error} ; 
162157    } 
163158  } 
164159
@@ -202,25 +197,19 @@ export function createRuntime(initialCode) {
202197  } 
203198
204199  function  rerun ( code )  { 
205-     // If the code is the same as the pervious one, and the previous code has no syntax error, 
206-     // there is no need to to update the position of blocks. So skip the diffing and just 
207-     // refresh the outputs. 
208-     if  ( code  ===  prevCode  &&  noSyntaxError )  return  refresh ( code ) ; 
200+     if  ( code  ===  prevCode )  return  refresh ( code ) ; 
209201
210202    prevCode  =  code ; 
211203    isRunning  =  true ; 
212-     noSyntaxError  =  false ; 
213204
214205    const  nodes  =  split ( code ) ; 
215206    if  ( ! nodes )  return ; 
216207
217208    for  ( const  node  of  nodes )  { 
218209      const  cell  =  code . slice ( node . start ,  node . end ) ; 
219-       const  transpiled  =  transpile ( cell ,   code ) ; 
210+       const  transpiled  =  transpile ( cell ) ; 
220211      node . transpiled  =  transpiled ; 
221212    } 
222-     if  ( nodes . some ( ( n )  =>  ! n . transpiled ) )  return ; 
223-     noSyntaxError  =  true ; 
224213
225214    const  groups  =  group ( nodes ,  ( n )  =>  code . slice ( n . start ,  n . end ) ) ; 
226215    const  enter  =  [ ] ; 
@@ -265,9 +254,9 @@ export function createRuntime(initialCode) {
265254    // @ref  https://github.com/observablehq/notebook-kit/blob/02914e034fd21a50ebcdca08df57ef5773864125/src/runtime/define.ts#L33 
266255    for  ( const  node  of  enter )  { 
267256      const  vid  =  uid ( ) ; 
268-       const  state  =  { values : [ ] ,  variables : [ ] ,  error : null ,  doc : false } ; 
257+       const  { inputs,  body,  outputs,  error =  null }  =  node . transpiled ; 
258+       const  state  =  { values : [ ] ,  variables : [ ] ,  error : null ,  syntaxError : error ,  doc : false } ; 
269259      node . state  =  state ; 
270-       const  { inputs,  body,  outputs}  =  node . transpiled ; 
271260      const  v  =  main . variable ( observer ( state ) ,  { shadow : { } } ) ; 
272261      if  ( inputs . includes ( "echo" ) )  { 
273262        state . doc  =  true ; 
0 commit comments