8787 <p class =" custom-block-title" >Syntax Error</p >
8888 <p >See Output tab for details</p >
8989 </div >
90- <div v-else-if =" metadata" :class =" $style.highlight" v-html =" metadataHtml" ></div >
90+ <div v-else-if =" metadata.exists " :class =" $style.highlight" v-html =" metadataHtml" ></div >
9191 <div v-else >No metadata</div >
9292 </div >
9393 </div >
@@ -221,7 +221,14 @@ const errorLine = ref<number | null>(null);
221221const ast = ref <unknown >(null );
222222const astHtml = ref (' ' );
223223
224- const metadata = ref <unknown >(null );
224+ type OptionalMetadata = {
225+ exists: false ;
226+ } | {
227+ exists: true ;
228+ value: unknown ;
229+ };
230+
231+ const metadata = ref <OptionalMetadata >({ exists: false });
225232const metadataHtml = ref (' ' );
226233
227234function parse() {
@@ -235,7 +242,11 @@ function parse() {
235242 const [ast_, metadata_] = runner .value .parse (code .value );
236243 logs .value = [];
237244 ast .value = ast_ ;
238- metadata .value = metadata_ ?.get (null ) ?? null ;
245+ if (metadata_ ?.has (null )) {
246+ metadata .value = { exists: true , value: metadata_ .get (null ) };
247+ } else {
248+ metadata .value = { exists: false };
249+ }
239250 } catch (err ) {
240251 if (runner .value .isAiScriptError (err )) {
241252 logs .value = [{
@@ -252,7 +263,7 @@ function parse() {
252263 }
253264 }
254265 ast .value = null ;
255- metadata .value = null ;
266+ metadata .value = { exists: false } ;
256267 }
257268 }
258269}
@@ -423,12 +434,12 @@ onMounted(async () => {
423434
424435 watch (metadata , async (newMetadata ) => {
425436 if (highlighter ) {
426- if (newMetadata == null ) {
437+ if (! newMetadata . exists ) {
427438 metadataHtml .value = ' ' ;
428439 return ;
429440 }
430441
431- metadataHtml .value = highlighter .codeToHtml (JSON .stringify (newMetadata , null , 2 ), {
442+ metadataHtml .value = highlighter .codeToHtml (JSON .stringify (newMetadata . value , null , 2 ), {
432443 lang: ' json' ,
433444 themes: {
434445 light: ' github-light' ,
0 commit comments