diff --git a/.vitepress/pages/Playground.vue b/.vitepress/pages/Playground.vue
index 6402fd5..0c28387 100644
--- a/.vitepress/pages/Playground.vue
+++ b/.vitepress/pages/Playground.vue
@@ -87,7 +87,7 @@
Syntax Error
See Output tab for details
-
+
No metadata
@@ -221,7 +221,14 @@ const errorLine = ref(null);
const ast = ref(null);
const astHtml = ref('');
-const metadata = ref(null);
+type OptionalMetadata = {
+ exists: false;
+} | {
+ exists: true;
+ value: unknown;
+};
+
+const metadata = ref({ exists: false });
const metadataHtml = ref('');
function parse() {
@@ -235,7 +242,11 @@ function parse() {
const [ast_, metadata_] = runner.value.parse(code.value);
logs.value = [];
ast.value = ast_;
- metadata.value = metadata_?.get(null) ?? null;
+ if (metadata_?.has(null)) {
+ metadata.value = { exists: true, value: metadata_.get(null) };
+ } else {
+ metadata.value = { exists: false };
+ }
} catch (err) {
if (runner.value.isAiScriptError(err)) {
logs.value = [{
@@ -252,7 +263,7 @@ function parse() {
}
}
ast.value = null;
- metadata.value = null;
+ metadata.value = { exists: false };
}
}
}
@@ -423,12 +434,12 @@ onMounted(async () => {
watch(metadata, async (newMetadata) => {
if (highlighter) {
- if (newMetadata == null) {
+ if (!newMetadata.exists) {
metadataHtml.value = '';
return;
}
- metadataHtml.value = highlighter.codeToHtml(JSON.stringify(newMetadata, null, 2), {
+ metadataHtml.value = highlighter.codeToHtml(JSON.stringify(newMetadata.value, null, 2), {
lang: 'json',
themes: {
light: 'github-light',