Skip to content

Commit e6f0867

Browse files
committed
feat(tsc): support vueCompilerOptions.extensions option (#3800)
1 parent 6da4619 commit e6f0867

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

packages/tsc/src/index.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1-
import * as vue from '@vue/language-core';
21
import { runTsc } from '@volar/typescript/lib/starters/runTsc';
2+
import * as vue from '@vue/language-core';
33

4-
const windowsPathReg = /\\/g;
4+
let runExtensions = ['.vue'];
55

6-
runTsc(require.resolve('typescript/lib/tsc'), ['.vue'], (ts, options) => {
6+
const windowsPathReg = /\\/g;
7+
const extensionsChangedException = new Error('extensions changed');
8+
const main = () => runTsc(require.resolve('typescript/lib/tsc'), runExtensions, (ts, options) => {
79
const { configFilePath } = options.options;
810
const vueOptions = typeof configFilePath === 'string'
911
? vue.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions
1012
: {};
11-
return vue.createLanguages(
12-
ts,
13-
options.options,
14-
vueOptions,
15-
);
13+
const extensions = vueOptions.extensions ?? ['.vue'];
14+
if (
15+
runExtensions.length === extensions.length
16+
&& runExtensions.every(ext => extensions.includes(ext))
17+
) {
18+
return vue.createLanguages(
19+
ts,
20+
options.options,
21+
vueOptions,
22+
);
23+
}
24+
else {
25+
runExtensions = extensions;
26+
throw extensionsChangedException;
27+
}
1628
});
29+
30+
try {
31+
main();
32+
} catch (err) {
33+
if (err === extensionsChangedException) {
34+
main();
35+
}
36+
}

test-workspace/tsc/petite-vue/main.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script type="module" lang="ts">
2-
import { exactType } from '../../shared';
2+
// @ts-nocheck
3+
import { exactType } from '../shared';
34

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

0 commit comments

Comments
 (0)