Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

fix: add language fallback for template code #407

Merged
merged 3 commits into from Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/index.spec.ts
Expand Up @@ -53,7 +53,7 @@ describe('Rollup Plugin Vue', () => {

expect(code).toEqual(
expect.stringContaining(
`import { render } from "example.vue?vue&type=template&id=063a7d4c"`
`import { render } from "example.vue?vue&type=template&id=063a7d4c&lang.js"`
)
)
expect(code).toEqual(expect.stringContaining(`script.render = render`))
Expand All @@ -66,7 +66,7 @@ describe('Rollup Plugin Vue', () => {
)
expect(code).toEqual(
expect.stringContaining(
`import { render } from "example.vue?vue&type=template&id=063a7d4c"`
`import { render } from "example.vue?vue&type=template&id=063a7d4c&lang.js"`
)
)
expect(code).toEqual(expect.stringContaining(`script.render = render`))
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Expand Up @@ -146,7 +146,7 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
if (query.src) {
this.addWatchFile(query.filename);
}

if (query.type === 'template') {
debug(`transform(${id})`)
const block = descriptor.template!
Expand Down Expand Up @@ -478,7 +478,7 @@ function getTemplateCode(
const idQuery = `&id=${id}`
const scopedQuery = hasScoped ? `&scoped=true` : ``
const srcQuery = descriptor.template.src ? `&src` : ``
const attrsQuery = attrsToQuery(descriptor.template.attrs)
const attrsQuery = attrsToQuery(descriptor.template.attrs, 'js')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add true as third argument to always force .js

const query = `?vue&type=template${idQuery}${srcQuery}${scopedQuery}${attrsQuery}`
templateRequest = _(src + query)
templateImport = `import { ${renderFnName} } from ${templateRequest}`
Expand Down