Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Sep 26, 2023
1 parent a6cb062 commit 1c2750b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 30 deletions.
8 changes: 0 additions & 8 deletions .vitepress/errors.data.ts

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/markdown-it": "^12.2.3",
"@types/node": "^16.9.1",
"@vue/compiler-core": "npm:@vue/compiler-core-canary@minor",
"@vue/runtime-core": "npm:@vue/runtime-core-canary@minor",
"terser": "^5.14.2"
},
"pnpm": {
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/errors/ErrorsTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script setup lang="ts">
defineProps<{
kind: string
errors: Record<any, string>
highlight?: any
}>()
</script>

<template>
<table>
<thead>
<tr>
<th>Code</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<tr
v-for="(msg, code) of errors"
:class="{ highlight: highlight === `${kind}-${code}` }"
>
<td :id="`${kind}-${code}`" v-text="code" />
<td v-text="msg" />
</tr>
</tbody>
</table>
</template>

<style scoped>
.highlight {
color: var(--vt-c-yellow-darker);
font-weight: bold;
}
</style>
14 changes: 14 additions & 0 deletions src/errors/errors.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineLoader } from 'vitepress'
import { errorMessages } from '@vue/compiler-core'

function filterEmptyMsg(data: Record<number, string>) {
return Object.fromEntries(Object.entries(data).filter(([_, msg]) => msg))
}

export default defineLoader({
load() {
return {
compiler: filterEmptyMsg(errorMessages)
}
}
})
32 changes: 10 additions & 22 deletions src/errors/index.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
<script setup>
import { data } from '../../.vitepress/errors.data.ts'
const hash = location.hash.slice(1)
import { ref, onMounted } from 'vue'
import { data } from './errors.data.ts'
import ErrorsTable from './ErrorsTable.vue'

const highlight = ref()
onMounted(() => {
highlight.value = location.hash.slice(1)
})
</script>

# Error Reference {#error-reference}

<table>
<thead>
<tr>
<th>Code</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<tr v-for="(msg, code) of data.errorMessages" :class="{ highlight: hash === String(code) }">
<td :id="code" v-text="code" />
<td v-text="msg" />
</tr>
</tbody>
</table>
## Compiler Errors {#compiler-errors}

<style scoped>
.highlight {
color: var(--vt-c-yellow-darker);
font-weight: bold;
}
</style>
<ErrorsTable kind="compiler" :errors="data.compiler" :highlight="highlight" />

0 comments on commit 1c2750b

Please sign in to comment.