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: make it work when a default lang was specified #223

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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