From a6bf2427c022fb8054bce60913c87a57c7f10b00 Mon Sep 17 00:00:00 2001 From: susanforme Date: Fri, 27 Feb 2026 16:16:34 +0800 Subject: [PATCH] fix: add getScriptKind to host for Vue JSX/TSX support --- lib/service-host.js | 17 ++++++++ test/vue.js | 103 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/lib/service-host.js b/lib/service-host.js index b950cd3..70e6450 100644 --- a/lib/service-host.js +++ b/lib/service-host.js @@ -34,6 +34,23 @@ function getTypeScriptLanguageServiceHost(path, content) { return snapshot; } }, + getScriptKind: (fileName) => { + const ext = fileName.substring(fileName.lastIndexOf('.') + 1); + switch (ext) { + case 'ts': + return ts.ScriptKind.TS; + case 'tsx': + return ts.ScriptKind.TSX; + case 'js': + return ts.ScriptKind.JS; + case 'jsx': + return ts.ScriptKind.JSX; + case 'json': + return ts.ScriptKind.JSON; + default: + return ts.ScriptKind.Unknown; + } + }, }; } diff --git a/test/vue.js b/test/vue.js index 9dea519..d377545 100644 --- a/test/vue.js +++ b/test/vue.js @@ -91,6 +91,109 @@ Foo t.is(formattedCode, expected); }); +test('works with JSX inside Vue files', async (t) => { + const code = ` +`; + + const formattedCode = await prettify(code, { filepath: 'file.vue' }); + + t.is(formattedCode, code); +}); + +test('removes unused imports in Vue JSX files', async (t) => { + const code = ` +`; + + const expected = ` +`; + + const formattedCode = await prettify(code, { filepath: 'file.vue' }); + + t.is(formattedCode, expected); +}); + +test('works with TSX inside Vue files', async (t) => { + const code = ` +`; + + const formattedCode = await prettify(code, { filepath: 'file.vue' }); + + t.is(formattedCode, code); +}); + +test('removes unused imports in Vue TSX files', async (t) => { + const code = ` +`; + + const expected = ` +`; + + const formattedCode = await prettify(code, { filepath: 'file.vue' }); + + t.is(formattedCode, expected); +}); + +test('works with JSX in Vue setup scripts', async (t) => { + const code = ` +`; + + const formattedCode = await prettify(code, { filepath: 'file.vue' }); + + t.is(formattedCode, code); +}); + test.serial('works with Volar language plugins when not running from the project root', async (t) => { const originalGetCurrentDir = ts.sys.getCurrentDirectory;