Skip to content

Commit 8801060

Browse files
antfuzhiyuanzmj
andauthored
fix: upgrade @vue/language-core (#51)
Co-authored-by: zhiyuanzmj <32807958+zhiyuanzmj@users.noreply.github.com>
1 parent 2e3d85f commit 8801060

File tree

8 files changed

+75
-317
lines changed

8 files changed

+75
-317
lines changed

packages/twoslash-vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"typescript": "*"
5151
},
5252
"dependencies": {
53-
"@vue/language-core": "~2.0.29",
53+
"@vue/language-core": "~2.1.6",
5454
"twoslash": "workspace:*",
5555
"twoslash-protocol": "workspace:*"
5656
}

packages/twoslash-vue/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Language, VueCompilerOptions } from '@vue/language-core'
2-
import { FileMap, createLanguage, createVueLanguagePlugin, defaultMapperFactory, resolveVueCompilerOptions } from '@vue/language-core'
2+
import { FileMap, createLanguage, createVueLanguagePlugin, defaultMapperFactory, resolveVueCompilerOptions, setupGlobalTypes } from '@vue/language-core'
33
import type { CompilerOptions } from 'typescript'
44
import ts from 'typescript'
55
import type {
@@ -65,7 +65,9 @@ export function createTwoslasher(createOptions: CreateTwoslashVueOptions = {}):
6565
return cache.get(key)!
6666

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

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

145146
const map = defaultMapperFactory(fileCompiled.mappings)
146147

packages/twoslash-vue/test/query.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ describe('basic', () => {
1919
expect(result.meta.positionQueries)
2020
.toMatchInlineSnapshot(`
2121
[
22-
38,
23-
235,
24-
1676,
25-
1892,
22+
79,
23+
276,
24+
1561,
25+
1729,
2626
]
2727
`)
2828

packages/twoslash-vue/test/results/completion.json

Lines changed: 2 additions & 134 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/twoslash-vue/test/results/cut-around-vue.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)