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

Commit e334e8c

Browse files
authored
fix: add language fallback for template code (#407)
* fix: add language fallback for template code * tests: expect lang.js in template * fix: always force language fallback
1 parent 09c41b7 commit e334e8c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('Rollup Plugin Vue', () => {
5353

5454
expect(code).toEqual(
5555
expect.stringContaining(
56-
`import { render } from "example.vue?vue&type=template&id=063a7d4c"`
56+
`import { render } from "example.vue?vue&type=template&id=063a7d4c&lang.js"`
5757
)
5858
)
5959
expect(code).toEqual(expect.stringContaining(`script.render = render`))
@@ -66,7 +66,7 @@ describe('Rollup Plugin Vue', () => {
6666
)
6767
expect(code).toEqual(
6868
expect.stringContaining(
69-
`import { render } from "example.vue?vue&type=template&id=063a7d4c"`
69+
`import { render } from "example.vue?vue&type=template&id=063a7d4c&lang.js"`
7070
)
7171
)
7272
expect(code).toEqual(expect.stringContaining(`script.render = render`))

src/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
144144
const descriptor = getDescriptor(query.filename)
145145
const hasScoped = descriptor.styles.some((s) => s.scoped)
146146
if (query.src) {
147-
this.addWatchFile(query.filename);
147+
this.addWatchFile(query.filename)
148148
}
149-
149+
150150
if (query.type === 'template') {
151151
debug(`transform(${id})`)
152152
const block = descriptor.template!
@@ -478,7 +478,7 @@ function getTemplateCode(
478478
const idQuery = `&id=${id}`
479479
const scopedQuery = hasScoped ? `&scoped=true` : ``
480480
const srcQuery = descriptor.template.src ? `&src` : ``
481-
const attrsQuery = attrsToQuery(descriptor.template.attrs)
481+
const attrsQuery = attrsToQuery(descriptor.template.attrs, 'js', true)
482482
const query = `?vue&type=template${idQuery}${srcQuery}${scopedQuery}${attrsQuery}`
483483
templateRequest = _(src + query)
484484
templateImport = `import { ${renderFnName} } from ${templateRequest}`
@@ -638,12 +638,15 @@ function _(any: any) {
638638
return JSON.stringify(any)
639639
}
640640

641-
function normalizeSourceMap(map: SFCTemplateCompileResults['map'], id: string): any {
641+
function normalizeSourceMap(
642+
map: SFCTemplateCompileResults['map'],
643+
id: string
644+
): any {
642645
if (!map) return null as any
643646

644647
if (!id.includes('type=script')) {
645-
map.file = id;
646-
map.sources[0] = id;
648+
map.file = id
649+
map.sources[0] = id
647650
}
648651

649652
return {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy