-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from MAXLZ1/feature/gen-vue-type
feat: 支持生成.vue文件的类型
- Loading branch information
Showing
13 changed files
with
5,855 additions
and
3,152 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {createProgram} from 'vue-tsc' | ||
import ts from 'typescript' | ||
import { getFileNames } from './getTSConfig' | ||
|
||
const cache: { | ||
languageService?: ts.LanguageService | ||
cwd: string | ||
} = {cwd: ''} | ||
|
||
function getVueTsService(options: ts.CompilerOptions, cwd: string) { | ||
if (cache.languageService && cache.cwd === cwd) { | ||
return cache.languageService | ||
} | ||
cache.cwd = cwd | ||
|
||
const rootFileNames = getFileNames(cwd).filter(fileName => fileName.endsWith('.vue')) | ||
|
||
const host = ts.createCompilerHost(options, undefined) | ||
|
||
const program = createProgram({ | ||
rootNames: rootFileNames, | ||
options, | ||
host | ||
}) | ||
|
||
const service = program.__vue.languageService.__internal__.languageService | ||
cache.languageService = service | ||
|
||
return service | ||
} | ||
|
||
export {getVueTsService} |
Oops, something went wrong.