Skip to content

Commit

Permalink
feat(tsc): support vueCompilerOptions.extensions option (#3800)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 21, 2023
1 parent 2bcd145 commit a89fbcd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
36 changes: 28 additions & 8 deletions packages/tsc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import * as vue from '@vue/language-core';
import { runTsc } from '@volar/typescript/lib/starters/runTsc';
import * as vue from '@vue/language-core';

const windowsPathReg = /\\/g;
let runExtensions = ['.vue'];

runTsc(require.resolve('typescript/lib/tsc'), ['.vue'], (ts, options) => {
const windowsPathReg = /\\/g;
const extensionsChangedException = new Error('extensions changed');
const main = () => runTsc(require.resolve('typescript/lib/tsc'), runExtensions, (ts, options) => {
const { configFilePath } = options.options;
const vueOptions = typeof configFilePath === 'string'
? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions
: {};
return vue.createLanguages(
ts,
options.options,
vueOptions,
);
const extensions = vueOptions.extensions ?? ['.vue'];
if (
runExtensions.length === extensions.length
&& runExtensions.every(ext => extensions.includes(ext))
) {
return vue.createLanguages(
ts,
options.options,
vueOptions,
);
}
else {
runExtensions = extensions;
throw extensionsChangedException;
}
});

try {
main();
} catch (err) {
if (err === extensionsChangedException) {
main();
}
}
3 changes: 2 additions & 1 deletion test-workspace/tsc/petite-vue/main.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script type="module" lang="ts">
import { exactType } from '../../shared';
// @ts-nocheck
import { exactType } from '../shared';

createApp({ foo: 1, exactType, baz() { return 'baz'; } });

Expand Down

0 comments on commit a89fbcd

Please sign in to comment.