Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix: prevent error when SFC script contains variable named render (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
thebanjomatic committed Oct 15, 2021
1 parent e72844f commit 7a6f9e9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function transformMain(
pluginContext
)
// script
const scriptVar = 'script'
const scriptVar = '__vue2_script'
const { scriptCode, map: scriptMap } = await genScriptCode(
scriptVar,
descriptor,
Expand All @@ -49,21 +49,21 @@ ${templateCode}
const ${cssModuleVar} = {}
${stylesCode}
/* normalize component */
import normalizer from "${vueComponentNormalizer}"
var __component__ = /*#__PURE__*/normalizer(
script,
render,
staticRenderFns,
import __vue2_normalizer from "${vueComponentNormalizer}"
var __component__ = /*#__PURE__*/__vue2_normalizer(
__vue2_script,
__vue2_render,
__vue2_staticRenderFns,
${hasFunctional ? `true` : `false`},
injectStyles,
__vue2_injectStyles,
${scoped ? JSON.stringify(descriptor.id) : `null`},
null,
null
)
`.trim() + `\n`

result += `
function injectStyles (context) {
function __vue2_injectStyles (context) {
for(let o in ${cssModuleVar}){
this[o] = ${cssModuleVar}[o]
}
Expand Down Expand Up @@ -183,7 +183,7 @@ async function genTemplateRequest(
) {
const template = descriptor.template
if (!template) {
return { code: `let render, staticRenderFns` }
return { code: `let __vue2_render, __vue2_staticRenderFns` }
}
const src = template.src || filename
const srcQuery = template.src ? `&src` : ``
Expand All @@ -192,7 +192,7 @@ async function genTemplateRequest(
const query = `?vue${from}&type=template${srcQuery}${attrsQuery}`
const templateRequest = src + query
return {
code: `import { render, staticRenderFns } from '${templateRequest}'`,
code: `import { render as __vue2_render, staticRenderFns as __vue2_staticRenderFns } from '${templateRequest}'`,
templateRequest,
}
}
Expand Down

0 comments on commit 7a6f9e9

Please sign in to comment.