Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(twoslash-vue): support cut-before #41

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading