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

Commit

Permalink
fix: add language fallback for template code (#407)
Browse files Browse the repository at this point in the history
* fix: add language fallback for template code

* tests: expect lang.js in template

* fix: always force language fallback
  • Loading branch information
Nerixyz authored Oct 24, 2020
1 parent 09c41b7 commit e334e8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
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
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
const descriptor = getDescriptor(query.filename)
const hasScoped = descriptor.styles.some((s) => s.scoped)
if (query.src) {
this.addWatchFile(query.filename);
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', true)
const query = `?vue&type=template${idQuery}${srcQuery}${scopedQuery}${attrsQuery}`
templateRequest = _(src + query)
templateImport = `import { ${renderFnName} } from ${templateRequest}`
Expand Down Expand Up @@ -638,12 +638,15 @@ function _(any: any) {
return JSON.stringify(any)
}

function normalizeSourceMap(map: SFCTemplateCompileResults['map'], id: string): any {
function normalizeSourceMap(
map: SFCTemplateCompileResults['map'],
id: string
): any {
if (!map) return null as any

if (!id.includes('type=script')) {
map.file = id;
map.sources[0] = id;
map.file = id
map.sources[0] = id
}

return {
Expand Down

0 comments on commit e334e8c

Please sign in to comment.