From 00873931871ce1a32c0aa4d3d4de010a4c76e71e Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 20 Jan 2022 18:43:37 +0800 Subject: [PATCH] fix(mp): component with setup-maybe-ref (#3213) --- .../uni-cli-shared/src/mp/usingComponents.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index 7badfac9a..870085295 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -237,11 +237,26 @@ function findBindingComponent( }) } +function normalizeComponentId(id: string) { + // _unref(test) => test + if (id.includes('_unref(')) { + return id.replace('_unref(', '').replace(')', '') + } + // $setup["test"] => test + if (id.includes('$setup[')) { + return id.replace('$setup["', '').replace('"', '') + } + return id +} + function parseBindingComponents( templateBindingComponents: BindingComponents, scriptBindingComponents: BindingComponents ) { - const bindingComponents: BindingComponents = { ...templateBindingComponents } + const bindingComponents: BindingComponents = {} + Object.keys(templateBindingComponents).forEach((id) => { + bindingComponents[normalizeComponentId(id)] = templateBindingComponents[id] + }) Object.keys(scriptBindingComponents).forEach((id) => { const { tag } = scriptBindingComponents[id] const name = findBindingComponent(tag, templateBindingComponents) -- GitLab