From 59c595c1e897c0addff6306260c344be09a7537c Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 24 Dec 2019 10:51:26 -0500 Subject: [PATCH] refactor: use named export for compiled render function --- .../__tests__/__snapshots__/codegen.spec.ts.snap | 6 +++--- .../__tests__/__snapshots__/compile.spec.ts.snap | 2 +- .../__tests__/__snapshots__/scopeId.spec.ts.snap | 10 +++++----- packages/compiler-core/__tests__/scopeId.spec.ts | 2 +- .../transforms/__snapshots__/hoistStatic.spec.ts.snap | 2 +- .../transforms/__snapshots__/vModel.spec.ts.snap | 6 +++--- packages/compiler-core/src/codegen.ts | 4 ++-- .../templateTransformAssetUrl.spec.ts.snap | 6 +++--- .../__snapshots__/templateTransformSrcset.spec.ts.snap | 2 +- .../compiler-sfc/__tests__/compileTemplate.spec.ts | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap index f599fcfa..785d3be3 100644 --- a/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap @@ -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 }" diff --git a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap index e3e4c726..55bb9f92 100644 --- a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap @@ -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\\", diff --git a/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap index ea08f272..d0fd955c 100644 --- a/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap @@ -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\\")) })" diff --git a/packages/compiler-core/__tests__/scopeId.spec.ts b/packages/compiler-core/__tests__/scopeId.spec.ts index 37cde9c2..de645d17 100644 --- a/packages/compiler-core/__tests__/scopeId.spec.ts +++ b/packages/compiler-core/__tests__/scopeId.spec.ts @@ -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() }) diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap index 5173080d..bce5d8ed 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap @@ -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, [ diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/vModel.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/vModel.spec.ts.snap index 5dac5147..18f9d54f 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/vModel.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/vModel.spec.ts.snap @@ -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, diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index f46b3322..d2352636 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -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() diff --git a/packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap index 580a70b4..d6d255ca 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/templateTransformAssetUrl.spec.ts.snap @@ -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 }), diff --git a/packages/compiler-sfc/__tests__/__snapshots__/templateTransformSrcset.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/templateTransformSrcset.spec.ts.snap index 2ea6edbd..78c4bffa 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/templateTransformSrcset.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/templateTransformSrcset.spec.ts.snap @@ -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\\", { diff --git a/packages/compiler-sfc/__tests__/compileTemplate.spec.ts b/packages/compiler-sfc/__tests__/compileTemplate.spec.ts index 03a32ba0..fa86618b 100644 --- a/packages/compiler-sfc/__tests__/compileTemplate.spec.ts +++ b/packages/compiler-sfc/__tests__/compileTemplate.spec.ts @@ -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', () => {