Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use .ts/.tsx extension for internal virtual .js/.jsx codegen files #3353

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/vue-language-core/src/plugins/vue-tsx.ts
Expand Up @@ -24,7 +24,7 @@ const plugin: VueLanguagePlugin = (ctx) => {
const tsx = useTsx(fileName, sfc);
const fileNames: string[] = [];

if (['js', 'ts', 'jsx', 'tsx'].includes(tsx.lang.value)) {
if (['ts', 'tsx'].includes(tsx.lang.value)) {
fileNames.push(fileName + '.' + tsx.lang.value);
}

Expand Down Expand Up @@ -117,10 +117,16 @@ export default plugin;
function createTsx(fileName: string, _sfc: Sfc, { vueCompilerOptions, compilerOptions, codegenStack }: Parameters<VueLanguagePlugin>[0]) {

const lang = computed(() => {
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';
let lang = 'ts';

if (_sfc.scriptSetup && _sfc.scriptSetup.lang !== 'js') {
lang = _sfc.scriptSetup.lang;
} else if (_sfc.script && _sfc.script.lang !== 'js') {
lang = _sfc.script.lang;
}

// Normalize 'js*' to 'ts*' as generated files are technically written in TypeScript.
return lang.replace(/^js/, 'ts');
});
const scriptRanges = computed(() =>
_sfc.scriptAst
Expand Down
Expand Up @@ -4,8 +4,10 @@
v-for="col in slotFilters"
:key="col"
#[`filter-cell-${col}`]="{ column }"
></template>
>{{ column }}</template>
</Foo>
</template>

<script setup></script>
<script setup>
const slotFilters = [1, 2]
</script>
@@ -1,3 +1,4 @@
<script>
// @ts-expect-error
''.at('0');
</script>