From b8591c12282e9a9daf1032eeb3edc987a62d251c Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Sat, 22 May 2021 20:40:40 +0800 Subject: [PATCH] fix(compat): RENDER_FUNCTION --- packages/uni-h5/dist/uni-h5.cjs.js | 10 ++++++---- packages/uni-h5/dist/uni-h5.es.js | 10 ++++++---- packages/uni-h5/src/framework/setup/index.ts | 12 +++++++----- .../src/configResolved/plugins/easycom.ts | 6 +++++- .../src/configResolved/plugins/pagesJson.ts | 2 +- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index 225e2789b..27a363b42 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -7670,7 +7670,8 @@ function initApp(vm) { appVm.$vm = vm; appVm.globalData = appVm.$options.globalData || {}; } -function wrapperComponentSetup(comp, {init, setup, after}) { +function wrapperComponentSetup(comp, {init, setup, before}) { + before && before(comp); const oldSetup = comp.setup; comp.setup = (props2, ctx) => { const instance = vue.getCurrentInstance(); @@ -7680,7 +7681,6 @@ function wrapperComponentSetup(comp, {init, setup, after}) { return oldSetup(query, ctx); } }; - after && after(comp); } function setupComponent(comp, options) { if (comp && (comp.__esModule || comp[Symbol.toStringTag] === "Module")) { @@ -7715,9 +7715,11 @@ function setupApp(comp) { return route.query; } }, - after(comp2) { + before(comp2) { comp2.mpType = "app"; - comp2.render = () => (vue.openBlock(), vue.createBlock(LayoutComponent)); + comp2.setup = () => () => { + return vue.openBlock(), vue.createBlock(LayoutComponent); + }; } }); } diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 7b447e82a..2e5d89a33 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -13185,7 +13185,8 @@ function initApp(vm) { appVm.$vm = vm; appVm.globalData = appVm.$options.globalData || {}; } -function wrapperComponentSetup(comp, {init: init2, setup, after}) { +function wrapperComponentSetup(comp, {init: init2, setup, before}) { + before && before(comp); const oldSetup = comp.setup; comp.setup = (props2, ctx) => { const instance2 = getCurrentInstance(); @@ -13195,7 +13196,6 @@ function wrapperComponentSetup(comp, {init: init2, setup, after}) { return oldSetup(query, ctx); } }; - after && after(comp); } function setupComponent(comp, options) { if (comp && (comp.__esModule || comp[Symbol.toStringTag] === "Module")) { @@ -13279,9 +13279,11 @@ function setupApp(comp) { }); return route.query; }, - after(comp2) { + before(comp2) { comp2.mpType = "app"; - comp2.render = () => (openBlock(), createBlock(LayoutComponent)); + comp2.setup = () => () => { + return openBlock(), createBlock(LayoutComponent); + }; } }); } diff --git a/packages/uni-h5/src/framework/setup/index.ts b/packages/uni-h5/src/framework/setup/index.ts index 8a7f42970..6b1231a41 100644 --- a/packages/uni-h5/src/framework/setup/index.ts +++ b/packages/uni-h5/src/framework/setup/index.ts @@ -21,13 +21,14 @@ import { usePageMeta, usePageRoute } from './provide' interface SetupComponentOptions { init: (vm: ComponentPublicInstance) => void setup: (instance: ComponentInternalInstance) => Record - after?: (comp: DefineComponent) => void + before?: (comp: DefineComponent) => void } function wrapperComponentSetup( comp: DefineComponent, - { init, setup, after }: SetupComponentOptions + { init, setup, before }: SetupComponentOptions ) { + before && before(comp) const oldSetup = comp.setup comp.setup = (props, ctx) => { const instance = getCurrentInstance()! @@ -37,7 +38,6 @@ function wrapperComponentSetup( return oldSetup(query, ctx) } } - after && after(comp) } function setupComponent(comp: any, options: SetupComponentOptions) { @@ -137,9 +137,11 @@ export function setupApp(comp: any) { }) return route.query }, - after(comp) { + before(comp) { comp.mpType = 'app' - comp.render = () => (openBlock(), createBlock(LayoutComponent)) + comp.setup = () => () => { + return openBlock(), createBlock(LayoutComponent) + } }, }) } diff --git a/packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts b/packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts index 418462e2f..5f64e3635 100644 --- a/packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts +++ b/packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts @@ -49,6 +49,8 @@ const baseComponents = [ 'view', ] +const identifierRE = /^([a-zA-Z_$][a-zA-Z\\d_$]*)$/ + export function uniEasycomPlugin(options: UniPluginFilterOptions): Plugin { const filter = createFilter(options.include, options.exclude) return { @@ -82,7 +84,9 @@ export function uniEasycomPlugin(options: UniPluginFilterOptions): Plugin { if (source) { return ( // 解决局部引入组件优先级(理论上让开发者使用script setup就可以解决局部引入) - `typeof ${name} !== 'undefined' ? ${name} : ` + + (identifierRE.test(name) + ? `typeof ${name} !== 'undefined' ? ${name} : ` + : '') + addImportDeclaration( importDeclarations, `__easycom_${i++}`, diff --git a/packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts b/packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts index 1ad311766..295165f71 100644 --- a/packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts +++ b/packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts @@ -238,7 +238,7 @@ function generatePageRoute( const alias = isEntry ? `\n alias:'/${path}',` : '' return `{ path:'/${isEntry ? '' : path}',${alias} - component:{render(){return renderPage(${name})}}, + component:{setup(){return ()=>renderPage(${name})}}, loader: ${normalizePageIdentifier(path)}Loader, meta: ${JSON.stringify(meta)} }` -- GitLab