From c641176dcd401cf49a75fbfee0ba35fe5a451dc7 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 24 Oct 2020 18:04:25 +0200 Subject: [PATCH 1/3] fix: add language fallback for template code --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 626565c..70ea234 100644 --- a/src/index.ts +++ b/src/index.ts @@ -146,7 +146,7 @@ export default function PluginVue(userOptions: Partial = {}): Plugin { if (query.src) { this.addWatchFile(query.filename); } - + if (query.type === 'template') { debug(`transform(${id})`) const block = descriptor.template! @@ -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') const query = `?vue&type=template${idQuery}${srcQuery}${scopedQuery}${attrsQuery}` templateRequest = _(src + query) templateImport = `import { ${renderFnName} } from ${templateRequest}` From f4866ed2318bb50d7e5b2210693f21582ac7eb5d Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 24 Oct 2020 19:17:14 +0200 Subject: [PATCH 2/3] tests: expect lang.js in template --- src/index.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.spec.ts b/src/index.spec.ts index c3bf002..78bd46c 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -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`)) @@ -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`)) From 65467e8c6a6b3150c3fadd606ea10515a922ceee Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 24 Oct 2020 19:36:53 +0200 Subject: [PATCH 3/3] fix: always force language fallback --- src/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 70ea234..e71f860 100644 --- a/src/index.ts +++ b/src/index.ts @@ -144,7 +144,7 @@ export default function PluginVue(userOptions: Partial = {}): 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') { @@ -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, 'js') + 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}` @@ -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 {