Skip to content

Commit

Permalink
feat: support @ts-check, @ts-nocheck for template
Browse files Browse the repository at this point in the history
close #1369
  • Loading branch information
johnsoncodehk committed Jun 2, 2022
1 parent ab363ae commit f644e22
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Expand Up @@ -61,6 +61,10 @@
"type": "boolean",
"markdownDescription": "https://github.com/johnsoncodehk/volar/issues/1249"
},
"experimentalUseScriptLeadingCommentInTemplate": {
"type": "boolean",
"markdownDescription": "https://github.com/johnsoncodehk/volar/issues/1369"
},
"experimentalResolveStyleCssClasses": {
"enum": [
"scoped",
Expand Down
1 change: 1 addition & 0 deletions packages/vue-typescript/src/types.ts
Expand Up @@ -20,4 +20,5 @@ export interface VueCompilerOptions {
experimentalDisableTemplateSupport?: boolean;
experimentalResolveStyleCssClasses?: 'scoped' | 'always' | 'never';
experimentalAllowTypeNarrowingInInlineHandlers?: boolean;
experimentalUseScriptLeadingCommentInTemplate?: boolean;
}
15 changes: 15 additions & 0 deletions packages/vue-typescript/src/use/useSfcTemplateScript.ts
Expand Up @@ -39,6 +39,20 @@ export function useSfcTemplateScript(
disableTemplateScript: boolean,
) {
const baseFileName = path.basename(fileName);
const scriptLeadingComment = computed(() => {
let comments: string[] = [];
if (compilerOptions.experimentalUseScriptLeadingCommentInTemplate ?? true) {
for (const _script of [script, scriptSetup]) {
if (_script.value) {
const commentRanges = ts.getLeadingCommentRanges(_script.value.content, 0);
if (commentRanges) {
comments = commentRanges.map(range => _script.value!.content.substring(range.pos, range.end));
}
}
}
}
return comments.join('\n');
});
const cssModuleClasses = computed(() =>
styleFiles.value.reduce((obj, style) => {
if (style.data.module) {
Expand Down Expand Up @@ -85,6 +99,7 @@ export function useSfcTemplateScript(

const codeGen = new CodeGen<EmbeddedFileMappingData>();

codeGen.addText(scriptLeadingComment.value + '\n');
codeGen.addText(`import * as __VLS_types from './__VLS_types';\n`);

if (script.value || scriptSetup.value) {
Expand Down

0 comments on commit f644e22

Please sign in to comment.