Skip to content

Commit

Permalink
fix: make it work when a default lang was specified (#223)
Browse files Browse the repository at this point in the history
Co-authored-by: sapphi-red <[email protected]>

Fixes #17
  • Loading branch information
dargmuesli authored Aug 11, 2023
1 parent 1e8d16e commit ff68ed3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async function genTemplateCode(
// If the template is not using pre-processor AND is not using external src,
// compile and inline it directly in the main module. When served in vite this
// saves an extra request per SFC which can improve load performance.
if (!template.lang && !template.src) {
if ((!template.lang || template.lang === 'html') && !template.src) {
return transformTemplateInMain(
template.content,
descriptor,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function canInlineMain(
return false
}
const lang = descriptor.script?.lang || descriptor.scriptSetup?.lang
if (!lang) {
if (!lang || lang === 'js') {
return true
}
if (lang === 'ts' && options.devServer) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function resolveTemplateCompilerOptions(
ssr,
ssrCssVars: cssVars,
transformAssetUrls,
preprocessLang: block.lang,
preprocessLang: block.lang === 'html' ? undefined : block.lang,
preprocessOptions,
compilerOptions: {
...options.template?.compilerOptions,
Expand Down
16 changes: 16 additions & 0 deletions playground/vue/DefaultLangs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template lang="html">
<h2>default langs</h2>
<div>
default lang: <span class="default-langs">{{ foo }}</span>
</div>
</template>

<script setup lang="js">
const foo = 'foo'
</script>

<style scoped lang="css">
.default-langs {
color: blue;
}
</style>
2 changes: 2 additions & 0 deletions playground/vue/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<WorkerTest />
<Url />
<TsGeneric msg="hello" />
<DefaultLangs />
</template>

<script setup lang="ts">
Expand All @@ -52,6 +53,7 @@ import WorkerTest from './worker.vue'
import { ref } from 'vue'
import Url from './Url.vue'
import TypeProps from './TypeProps.vue'
import DefaultLangs from './DefaultLangs.vue'
const TsGeneric = defineAsyncComponent(() => import('./TsGeneric.vue'))
Expand Down
7 changes: 7 additions & 0 deletions playground/vue/__tests__/vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,10 @@ describe('macro imported types', () => {
test('TS with generics', async () => {
expect(await page.textContent('.generic')).toMatch('hello')
})

describe('default langs', () => {
test('should work', async () => {
expect(await page.textContent('.default-langs')).toBe('foo')
expect(await getColor('.default-langs')).toBe('blue')
})
})
1 change: 1 addition & 0 deletions playground/vue/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// esbuild transpile should ignore this
"target": "ES5",
"jsx": "preserve",
"allowJs": true,
"paths": {
"~utils": ["../test-utils.ts"],
"~types": ["./types-aliased.d.ts"]
Expand Down

0 comments on commit ff68ed3

Please sign in to comment.