Skip to content

Commit

Permalink
fix: upgrade @vue/language-core (#51)
Browse files Browse the repository at this point in the history
Co-authored-by: zhiyuanzmj <32807958+zhiyuanzmj@users.noreply.github.com>
  • Loading branch information
antfu and zhiyuanzmj authored Sep 5, 2024
1 parent 2e3d85f commit 8801060
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 317 deletions.
2 changes: 1 addition & 1 deletion packages/twoslash-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"typescript": "*"
},
"dependencies": {
"@vue/language-core": "~2.0.29",
"@vue/language-core": "~2.1.6",
"twoslash": "workspace:*",
"twoslash-protocol": "workspace:*"
}
Expand Down
9 changes: 5 additions & 4 deletions packages/twoslash-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Language, VueCompilerOptions } from '@vue/language-core'
import { FileMap, createLanguage, createVueLanguagePlugin, defaultMapperFactory, resolveVueCompilerOptions } from '@vue/language-core'
import { FileMap, createLanguage, createVueLanguagePlugin, defaultMapperFactory, resolveVueCompilerOptions, setupGlobalTypes } from '@vue/language-core'
import type { CompilerOptions } from 'typescript'
import ts from 'typescript'
import type {
Expand Down Expand Up @@ -65,7 +65,9 @@ export function createTwoslasher(createOptions: CreateTwoslashVueOptions = {}):
return cache.get(key)!

function getLanguage() {
const vueLanguagePlugin = createVueLanguagePlugin<string>(ts, id => id, () => '', () => true, defaultCompilerOptions, resolveVueCompilerOptions(vueCompilerOptions))
const resolvedVueOptions = resolveVueCompilerOptions(vueCompilerOptions)
resolvedVueOptions.__setupedGlobalTypes = setupGlobalTypes(ts.sys.getCurrentDirectory(), resolvedVueOptions, ts.sys)
const vueLanguagePlugin = createVueLanguagePlugin<string>(ts, defaultCompilerOptions, resolvedVueOptions, id => id)
return createLanguage(
[vueLanguagePlugin],
new FileMap(ts.sys.useCaseSensitiveFileNames),
Expand Down Expand Up @@ -138,9 +140,8 @@ export function createTwoslasher(createOptions: CreateTwoslashVueOptions = {}):

const lang = getVueLanguage(compilerOptions, vueCompilerOptions)
const sourceScript = lang.scripts.set('index.vue', ts.ScriptSnapshot.fromString(strippedCode))!
const fileCompiled = get(sourceScript.generated!.embeddedCodes.values(), 1)!
const fileCompiled = get(sourceScript.generated!.embeddedCodes.values(), 2)!
const compiled = fileCompiled.snapshot.getText(0, fileCompiled.snapshot.getLength())
.replace(/(?=export const __VLS_globalTypesStart)/, '// ---cut-after---\n')

const map = defaultMapperFactory(fileCompiled.mappings)

Expand Down
8 changes: 4 additions & 4 deletions packages/twoslash-vue/test/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ describe('basic', () => {
expect(result.meta.positionQueries)
.toMatchInlineSnapshot(`
[
38,
235,
1676,
1892,
79,
276,
1561,
1729,
]
`)

Expand Down
136 changes: 2 additions & 134 deletions packages/twoslash-vue/test/results/completion.json

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

2 changes: 1 addition & 1 deletion 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

0 comments on commit 8801060

Please sign in to comment.