Skip to content

Commit

Permalink
feat(twoslash-vue): support custom vueCompilerOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 16, 2024
1 parent ca5b567 commit f31e39d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/twoslash-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { VueCompilerOptions } from '@vue/language-core'
import { SourceMap, createVueLanguage, sharedTypes } from '@vue/language-core'
import ts from 'typescript'
import type {
Expand All @@ -16,7 +17,14 @@ import {
resolveNodePositions,
} from 'twoslash'

interface CreateTwoslashVueOptions extends CreateTwoslashOptions {
export interface VueSpecificOptions {
/**
* Vue Compiler options
*/
vueCompilerOptions?: Partial<VueCompilerOptions>
}

export interface CreateTwoslashVueOptions extends CreateTwoslashOptions, VueSpecificOptions {
/**
* Render the generated code in the output instead of the Vue file
*
Expand All @@ -25,13 +33,16 @@ interface CreateTwoslashVueOptions extends CreateTwoslashOptions {
debugShowGeneratedCode?: boolean
}

export interface TwoslashVueExecuteOptions extends TwoslashExecuteOptions, VueSpecificOptions {
}

/**
* Create a twoslasher instance that add additional support for Vue SFC.
*/
export function createTwoslasher(createOptions: CreateTwoslashVueOptions = {}): TwoslashInstance {
const twoslasherBase = createTwoslasherBase(createOptions)

function twoslasher(code: string, extension?: string, options: TwoslashExecuteOptions = {}) {
function twoslasher(code: string, extension?: string, options: TwoslashVueExecuteOptions = {}) {
if (extension !== 'vue')
return twoslasherBase(code, extension, options)

Expand All @@ -42,6 +53,10 @@ export function createTwoslasher(createOptions: CreateTwoslashVueOptions = {}):
...defaultCompilerOptions,
...options.compilerOptions,
},
{
...createOptions.vueCompilerOptions,
...options.vueCompilerOptions,
},
)

const sourceMeta = {
Expand Down

0 comments on commit f31e39d

Please sign in to comment.