Skip to content

Commit

Permalink
fix: script block less component virtual ext should not be .js
Browse files Browse the repository at this point in the history
close #1452, clsoe #1455, close #1417
  • Loading branch information
johnsoncodehk committed Jun 16, 2022
1 parent 714fd49 commit 8e4324a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 0 additions & 2 deletions packages/vue-test-workspace/tsconfig.json
Expand Up @@ -5,8 +5,6 @@
"dom"
],
"strict": true,
"allowJs": true,
"checkJs": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
3 changes: 3 additions & 0 deletions packages/vue-test-workspace/typeChecks/no_script_block.vue
@@ -0,0 +1,3 @@
<!-- should no error even no set allowJs -->
<!-- https://github.com/johnsoncodehk/volar/issues/1452 -->
<template></template>
4 changes: 2 additions & 2 deletions packages/vue-typescript/src/plugins/petite-vue-script.ts
Expand Up @@ -58,8 +58,8 @@ export default function (
codeGen.addText('{}');
}
codeGen.addText(';\n');
codeGen.addText(`const __VLS_ctx = (await import('vue')).defineComponent({});\n`);
codeGen.addText(`declare const __VLS_export: new () => typeof __VLS_scope & import('./__VLS_types').PickNotAny<InstanceType<typeof __VLS_ctx>, {}>;\n`);
codeGen.addText(`const __VLS_component = (await import('vue')).defineComponent({});\n`);
codeGen.addText(`declare const __VLS_export: new () => typeof __VLS_scope & import('./__VLS_types').PickNotAny<InstanceType<typeof __VLS_component>, {}>;\n`);
codeGen.addText('export default __VLS_export;\n');

const file: EmbeddedFile = {
Expand Down
Expand Up @@ -65,7 +65,7 @@ export default function (

writeImportTypes();

tsxCodeGen.addText(`declare var __VLS_ctx: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''} __VLS_types.PickNotAny<InstanceType<typeof __VLS_component>, {}> & {\n`);
tsxCodeGen.addText(`declare var __VLS_ctx: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''} InstanceType<__VLS_types.PickNotAny<typeof __VLS_component, new () => {}>> & {\n`);
/* CSS Module */
for (const cssModule of cssModuleClasses.value) {
tsxCodeGen.addText(`${cssModule.style.module}: Record<string, string>`);
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-typescript/src/sourceFile.ts
Expand Up @@ -219,7 +219,7 @@ export function createSourceFile(
: undefined
);
const scriptLang = computed(() => {
return !sfc.script && !sfc.scriptSetup ? 'js'
return !sfc.script && !sfc.scriptSetup ? 'ts'
: sfc.scriptSetup && sfc.scriptSetup.lang !== 'js' ? sfc.scriptSetup.lang
: sfc.script && sfc.script.lang !== 'js' ? sfc.script.lang
: 'js';
Expand Down

0 comments on commit 8e4324a

Please sign in to comment.