Skip to content

Commit

Permalink
feat(twoslash-vue): support cut-before (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanzmj authored Jun 11, 2024
1 parent 6560647 commit 7a2b1ac
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/twoslash-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function createTwoslasher(createOptions: CreateTwoslashVueOptions = {}):
...sourceMeta.removals,
...result.meta.removals
.map((r) => {
const start = map.toSourceOffset(r[0])?.[0]
const start = map.toSourceOffset(r[0])?.[0] ?? code.match(/(?<=<script[\s\S]*>\s)/)?.index
const end = map.toSourceOffset(r[1])?.[0]
if (start == null || end == null || start < 0 || end < 0 || start >= end)
return undefined
Expand Down
23 changes: 23 additions & 0 deletions packages/twoslash-vue/test/fixtures/cut-around-vue.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup lang="ts">
import { ref } from "vue"
// ---cut-before---
interface Foo {
bar: string
}
// ---cut---
const { hi } = useFoo()
function useFoo() {
const hi = ref<Foo>({ bar: "hello" })
return { hi }
}
// ---cut-after---
declare const foo: {
hi: string
}
</script>

<template>
<div>
{{ hi.bar }}
</div>
</template>
89 changes: 89 additions & 0 deletions packages/twoslash-vue/test/results/cut-around-vue.json

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

0 comments on commit 7a2b1ac

Please sign in to comment.