-
-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tsc): support
vueCompilerOptions.extensions
option (#3800)
- Loading branch information
1 parent
2bcd145
commit a89fbcd
Showing
2 changed files
with
30 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters