Skip to content

Commit

Permalink
fix(language-core): inject as assertion of useCssModule into corr…
Browse files Browse the repository at this point in the history
…ect location (#4952)
  • Loading branch information
KazariEX authored Oct 28, 2024
1 parent 57d6d86 commit e7663b7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/language-core/lib/codegen/script/scriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,27 +193,31 @@ function* generateSetupFunction(
}
}
if (scriptSetupRanges.cssModules.length) {
for (const { define: { arg, exp } } of scriptSetupRanges.cssModules) {
for (const { define } of scriptSetupRanges.cssModules) {
setupCodeModifies.push([
arg ? [
[`(`],
define.start,
define.start
], [
define.arg ? [
` as Omit<__VLS_StyleModules, '$style'>[`,
generateSfcBlockSection(scriptSetup, arg.start, arg.end, codeFeatures.all),
`]`
generateSfcBlockSection(scriptSetup, define.arg.start, define.arg.end, codeFeatures.all),
`])`
] : [
` as __VLS_StyleModules[`,
['', scriptSetup.name, exp.start, codeFeatures.verification],
['', scriptSetup.name, define.exp.start, codeFeatures.verification],
`'$style'`,
['', scriptSetup.name, exp.end, codeFeatures.verification],
`]`
['', scriptSetup.name, define.exp.end, codeFeatures.verification],
`])`
],
exp.end,
exp.end
define.end,
define.end
]);
}
}
const isTs = options.lang !== 'js' && options.lang !== 'jsx';
for (const { define } of scriptSetupRanges.templateRefs) {
if (!define?.arg) {
if (!define.arg) {
continue;
}
if (isTs) {
Expand Down
31 changes: 31 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/cssModule/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts" setup>
import { useCssModule } from 'vue';
import { exactType } from '../../shared';
const style = useCssModule();
exactType(style, {} as Record<string, string> & {
style: string;
});
const foo = useCssModule('foo');
exactType(foo, {} as Record<string, string> & {
foo: string;
});
const bar = useCssModule('bar');
exactType(bar, {} as Record<string, string> & {
bar: string;
});
</script>

<style module>
.style { }
</style>

<style module="foo">
.foo { }
</style>

<style module="bar">
.bar { }
</style>

0 comments on commit e7663b7

Please sign in to comment.