refactor: use named export for compiled render function

This commit is contained in:
Evan You 2019-12-24 10:51:26 -05:00
parent 4d20981eb0
commit 59c595c1e8
10 changed files with 21 additions and 21 deletions

View File

@ -14,7 +14,7 @@ return function render() {
exports[`compiler: codegen CacheExpression 1`] = `
"
export default function render() {
export function render() {
const _ctx = this
const _cache = _ctx.$cache
return _cache[1] || (_cache[1] = foo)
@ -23,7 +23,7 @@ export default function render() {
exports[`compiler: codegen CacheExpression w/ isVNode: true 1`] = `
"
export default function render() {
export function render() {
const _ctx = this
const _cache = _ctx.$cache
return _cache[1] || (
@ -167,7 +167,7 @@ return function render() {
exports[`compiler: codegen module mode preamble 1`] = `
"import { createVNode, resolveDirective } from \\"vue\\"
export default function render() {
export function render() {
const _ctx = this
return null
}"

View File

@ -50,7 +50,7 @@ return function render() {
exports[`compiler: integration tests module mode 1`] = `
"import { toString, openBlock, createVNode, createBlock, createCommentVNode, Fragment, renderList, createTextVNode } from \\"vue\\"
export default function render() {
export function render() {
const _ctx = this
return (openBlock(), createBlock(\\"div\\", {
id: \\"foo\\",

View File

@ -9,7 +9,7 @@ const _hoisted_1 = createVNode(\\"div\\", null, \\"hello\\")
const _hoisted_2 = createVNode(\\"div\\", null, \\"world\\")
popScopeId()
export default withId(function render() {
export const render = withId(function render() {
const _ctx = this
return (openBlock(), createBlock(\\"div\\", null, [
_hoisted_1,
@ -22,7 +22,7 @@ exports[`scopeId compiler support should wrap default slot 1`] = `
"import { createVNode, resolveComponent, createBlock, openBlock, withScopeId } from \\"vue\\"
const withId = withScopeId(\\"test\\")
export default withId(function render() {
export const render = withId(function render() {
const _ctx = this
const _component_Child = resolveComponent(\\"Child\\")
@ -39,7 +39,7 @@ exports[`scopeId compiler support should wrap dynamic slots 1`] = `
"import { createVNode, resolveComponent, renderList, createSlots, createBlock, openBlock, withScopeId } from \\"vue\\"
const withId = withScopeId(\\"test\\")
export default withId(function render() {
export const render = withId(function render() {
const _ctx = this
const _component_Child = resolveComponent(\\"Child\\")
@ -68,7 +68,7 @@ exports[`scopeId compiler support should wrap named slots 1`] = `
"import { toString, createTextVNode, createVNode, resolveComponent, createBlock, openBlock, withScopeId } from \\"vue\\"
const withId = withScopeId(\\"test\\")
export default withId(function render() {
export const render = withId(function render() {
const _ctx = this
const _component_Child = resolveComponent(\\"Child\\")
@ -88,7 +88,7 @@ exports[`scopeId compiler support should wrap render function 1`] = `
"import { createVNode, createBlock, openBlock, withScopeId } from \\"vue\\"
const withId = withScopeId(\\"test\\")
export default withId(function render() {
export const render = withId(function render() {
const _ctx = this
return (openBlock(), createBlock(\\"div\\"))
})"

View File

@ -19,7 +19,7 @@ describe('scopeId compiler support', () => {
})
expect(ast.helpers).toContain(WITH_SCOPE_ID)
expect(code).toMatch(`const withId = withScopeId("test")`)
expect(code).toMatch(`export default withId(function render() {`)
expect(code).toMatch(`export const render = withId(function render() {`)
expect(code).toMatchSnapshot()
})

View File

@ -210,7 +210,7 @@ return function render() {
exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist elements with cached handlers 1`] = `
"import { createVNode, createBlock, openBlock } from \\"vue\\"
export default function render() {
export function render() {
const _ctx = this
const _cache = _ctx.$cache
return (openBlock(), createBlock(\\"div\\", null, [

View File

@ -3,7 +3,7 @@
exports[`compiler: transform v-model compound expression (with prefixIdentifiers) 1`] = `
"import { createVNode, createBlock, openBlock } from \\"vue\\"
export default function render() {
export function render() {
const _ctx = this
return (openBlock(), createBlock(\\"input\\", {
modelValue: _ctx.model[_ctx.index],
@ -30,7 +30,7 @@ return function render() {
exports[`compiler: transform v-model simple exprssion (with prefixIdentifiers) 1`] = `
"import { createVNode, createBlock, openBlock } from \\"vue\\"
export default function render() {
export function render() {
const _ctx = this
return (openBlock(), createBlock(\\"input\\", {
modelValue: _ctx.model,
@ -72,7 +72,7 @@ return function render() {
exports[`compiler: transform v-model with dynamic argument (with prefixIdentifiers) 1`] = `
"import { createVNode, createBlock, openBlock } from \\"vue\\"
export default function render() {
export function render() {
const _ctx = this
return (openBlock(), createBlock(\\"input\\", {
[_ctx.value]: _ctx.model,

View File

@ -224,12 +224,12 @@ export function generate(
}
genHoists(ast.hoists, context)
newline()
push(`export default `)
push(`export `)
}
// enter render function
if (genScopeId) {
push(`withId(`)
push(`const render = withId(`)
}
push(`function render() {`)
indent()

View File

@ -7,7 +7,7 @@ import _imports_0 from '@svg/file.svg'
const _hoisted_1 = _imports_0 + '#fragment'
export default function render() {
export function render() {
const _ctx = this
return (openBlock(), createBlock(\\"use\\", { href: _hoisted_1 }))
}"
@ -16,7 +16,7 @@ export default function render() {
exports[`compiler sfc: transform asset url support uri is empty 1`] = `
"import { createVNode, createBlock, openBlock } from \\"vue\\"
export default function render() {
export function render() {
const _ctx = this
return (openBlock(), createBlock(\\"use\\", { href: '' }))
}"
@ -28,7 +28,7 @@ import _imports_0 from './logo.png'
import _imports_1 from 'fixtures/logo.png'
export default function render() {
export function render() {
const _ctx = this
return (openBlock(), createBlock(Fragment, null, [
createVNode(\\"img\\", { src: _imports_0 }),

View File

@ -13,7 +13,7 @@ const _hoisted_5 = _imports_0 + '2x, ' + _imports_0
const _hoisted_6 = _imports_0 + '2x, ' + _imports_0 + '3x'
const _hoisted_7 = _imports_0 + ', ' + _imports_0 + '2x, ' + _imports_0 + '3x'
export default function render() {
export function render() {
const _ctx = this
return (openBlock(), createBlock(Fragment, null, [
createVNode(\\"img\\", {

View File

@ -9,7 +9,7 @@ test('should work', () => {
expect(result.errors.length).toBe(0)
expect(result.source).toBe(source)
// should expose render fn
expect(result.code).toMatch(`export default function render()`)
expect(result.code).toMatch(`export function render()`)
})
test('preprocess pug', () => {