From 746d3757efd15f158e5a2fc99c2ddaab69bb8985 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Mon, 20 May 2024 01:16:44 +0800 Subject: [PATCH 01/10] =?UTF-8?q?fix:=20=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E8=87=AA=E8=B0=83=E7=94=A8=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0usingComponents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-cli-shared/src/mp/usingComponents.ts | 71 ++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index 599137f887..a11a10b50f 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -1,7 +1,9 @@ import { + type ExportDefaultDeclaration, type IfStatement, type ImportDeclaration, type Node, + type ObjectExpression, type ObjectProperty, type Program, type Statement, @@ -28,6 +30,7 @@ import { BINDING_COMPONENTS, EXTNAME_VUE_RE } from '../constants' import { isAppVue, normalizeMiniProgramFilename, removeExt } from '../utils' import { cleanUrl, parseVueRequest } from '../vite/utils' import { addMiniProgramUsingComponents } from '../json/mp/jsonFile' +import path from 'path' type BindingComponents = Record< string, @@ -190,11 +193,56 @@ export async function updateMiniProgramGlobalComponents( } } +function parseVueComponentName(filename: string) { + let name = path.basename(removeExt(filename)) + + const ast = scriptDescriptors.get(filename) + if (!ast) return name + + const exportDefaultDecliaration = scriptDescriptors + .get(filename) + ?.ast.body.find( + (v) => v.type === 'ExportDefaultDeclaration' + ) as ExportDefaultDeclaration | null + + if (!exportDefaultDecliaration) return name + + let defineComponentDeclaration: ObjectExpression | null = null + + const { declaration } = exportDefaultDecliaration + + if (declaration.type === 'ObjectExpression') { + defineComponentDeclaration = declaration + } else if ( + declaration.type === 'CallExpression' && + declaration.callee.type === 'Identifier' && + declaration.callee.name === '_defineComponent' + ) { + defineComponentDeclaration = + (declaration.arguments[0] as ObjectExpression | undefined) || null + } + + if (!defineComponentDeclaration) return name + + for (const prop of defineComponentDeclaration.properties) { + if ( + prop.type === 'ObjectProperty' && + prop.key.type === 'Identifier' && + prop.key.name === '__name' && + prop.value.type === 'StringLiteral' + ) { + return prop.value.value + } + } + return name +} + function createUsingComponents( bindingComponents: BindingComponents, imports: ImportDeclaration[], inputDir: string, - normalizeComponentName: (name: string) => string + normalizeComponentName: (name: string) => string, + filename?: string ) { const usingComponents: Record = {} imports.forEach(({ source: { value }, specifiers: [specifier] }) => { @@ -211,6 +259,22 @@ function createUsingComponents( ) } }) + + if (filename) { + const componentName = parseVueComponentName(filename) + + if ( + Object.keys(bindingComponents).find( + (v) => bindingComponents[v].tag === componentName + ) && + !usingComponents[componentName] + ) { + usingComponents[componentName] = addLeadingSlash( + removeExt(normalizeMiniProgramFilename(filename, inputDir)) + ) + } + } + return usingComponents } @@ -250,7 +314,8 @@ export function updateMiniProgramComponentsByMainFilename( bindingComponents, imports, inputDir, - normalizeComponentName + normalizeComponentName, + mainFilename ) ) } @@ -347,6 +412,7 @@ interface ParseDescriptor { } export interface ScriptDescriptor extends TemplateDescriptor { setupBindingComponents: BindingComponents + ast: Program } async function parseGlobalDescriptor( @@ -396,6 +462,7 @@ export async function parseScriptDescriptor( bindingComponents: parseComponents(ast), setupBindingComponents: findBindingComponents(ast.body), imports, + ast, } scriptDescriptors.set(filename, descriptor) From 043ca3b7e66456e8852667d5902174c5ade61f10 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Mon, 20 May 2024 01:26:26 +0800 Subject: [PATCH 02/10] chore: update --- packages/uni-cli-shared/src/mp/usingComponents.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index a11a10b50f..2fafac1365 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -261,14 +261,16 @@ function createUsingComponents( }) if (filename) { - const componentName = parseVueComponentName(filename) + const name = parseVueComponentName(filename) if ( - Object.keys(bindingComponents).find( - (v) => bindingComponents[v].tag === componentName - ) && - !usingComponents[componentName] - ) { + !Object.keys(bindingComponents).find( + (v) => bindingComponents[v].tag === name + ) + ) + return usingComponents + const componentName = normalizeComponentName(hyphenate(name)) + if (!usingComponents[componentName]) { usingComponents[componentName] = addLeadingSlash( removeExt(normalizeMiniProgramFilename(filename, inputDir)) ) From 09440a2114d2ea3e2233704a811f351ec4cd247f Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Tue, 21 May 2024 23:06:52 +0800 Subject: [PATCH 03/10] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/usingComponents.spec.ts | 38 +++++++++++++++++++ .../uni-cli-shared/src/mp/usingComponents.ts | 13 ++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/packages/uni-cli-shared/__tests__/usingComponents.spec.ts b/packages/uni-cli-shared/__tests__/usingComponents.spec.ts index ed7cf78c0b..539ff199fe 100644 --- a/packages/uni-cli-shared/__tests__/usingComponents.spec.ts +++ b/packages/uni-cli-shared/__tests__/usingComponents.spec.ts @@ -301,5 +301,43 @@ export function createApp() { `const _easycom_test = ()=>import('${inputDir}/components/test/test.vue')` ) }) + test(`recursion`, async () => { + await testLocal( + ` + const _sfc_main = { + }; + const __BINDING_COMPONENTS__ = '{"index":{"name":"_component_index","type":"unknown"}}'; + function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { + return {}; + } + import "${filename}?vue&type=style&index=0&lang.css"; + import _export_sfc from "plugin-vue:export-helper"; + export default /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); + `, + { + index: '/pages/index/index', + }, + `` + ) + await testLocal( + `import { defineComponent as _defineComponent } from "vue"; + const __BINDING_COMPONENTS__ = '{"test":{"name":"test","type":"unknown"}}'; + + export default /* @__PURE__ */ _defineComponent({ + __name: "test", + setup(__props) { + return (_ctx, _cache) => { + return {}; + }; + } + }); + import "${inputDir}/pages/index/index.vue?vue&type=style&index=0&lang.css"; +`, + { + test: '/pages/index/index', + }, + `` + ) + }) }) }) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index 2fafac1365..522222b9b4 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -216,7 +216,7 @@ function parseVueComponentName(filename: string) { } else if ( declaration.type === 'CallExpression' && declaration.callee.type === 'Identifier' && - declaration.callee.name === '_defineComponent' + /_*defineComponent/.test(declaration.callee.name) ) { defineComponentDeclaration = (declaration.arguments[0] as ObjectExpression | undefined) || null @@ -228,7 +228,7 @@ function parseVueComponentName(filename: string) { if ( prop.type === 'ObjectProperty' && prop.key.type === 'Identifier' && - prop.key.name === '__name' && + /(__)?name/.test(prop.key.name) && prop.value.type === 'StringLiteral' ) { return prop.value.value @@ -261,15 +261,18 @@ function createUsingComponents( }) if (filename) { - const name = parseVueComponentName(filename) + const componentName = normalizeComponentName( + hyphenate(parseVueComponentName(filename)) + ) if ( !Object.keys(bindingComponents).find( - (v) => bindingComponents[v].tag === name + (v) => + normalizeComponentName(hyphenate(bindingComponents[v].tag)) === + componentName ) ) return usingComponents - const componentName = normalizeComponentName(hyphenate(name)) if (!usingComponents[componentName]) { usingComponents[componentName] = addLeadingSlash( removeExt(normalizeMiniProgramFilename(filename, inputDir)) From c4e5b8b763b3772bc11f637a79aad27bac859e37 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Wed, 22 May 2024 01:40:43 +0800 Subject: [PATCH 04/10] chore: update --- .../__tests__/usingComponents.spec.ts | 23 ++++++ .../uni-cli-shared/src/mp/usingComponents.ts | 76 ++++++++++++++----- 2 files changed, 82 insertions(+), 17 deletions(-) diff --git a/packages/uni-cli-shared/__tests__/usingComponents.spec.ts b/packages/uni-cli-shared/__tests__/usingComponents.spec.ts index 539ff199fe..408429471d 100644 --- a/packages/uni-cli-shared/__tests__/usingComponents.spec.ts +++ b/packages/uni-cli-shared/__tests__/usingComponents.spec.ts @@ -319,6 +319,7 @@ export function createApp() { }, `` ) + await testLocal( `import { defineComponent as _defineComponent } from "vue"; const __BINDING_COMPONENTS__ = '{"test":{"name":"test","type":"unknown"}}'; @@ -338,6 +339,28 @@ export function createApp() { }, `` ) + + await testLocal( + `import { defineComponent as _defineComponent } from "vue"; + const __BINDING_COMPONENTS__ = '{"test":{"name":"test","type":"unknown"}}'; + const component = _defineComponent({ + __name: "test", + setup(__props) { + return (_ctx, _cache) => { + return {}; + }; + } + }); + + export default component; + + import "${inputDir}/pages/index/index.vue?vue&type=style&index=0&lang.css"; +`, + { + test: '/pages/index/index', + }, + `` + ) }) }) }) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index 522222b9b4..940fb8241e 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -1,5 +1,4 @@ import { - type ExportDefaultDeclaration, type IfStatement, type ImportDeclaration, type Node, @@ -8,11 +7,15 @@ import { type Program, type Statement, type StringLiteral, + assertExportDefaultDeclaration, + assertIdentifier, isBlockStatement, isCallExpression, + isExportDefaultDeclaration, isIdentifier, isIfStatement, isImportDeclaration, + isImportSpecifier, isMemberExpression, isObjectExpression, isObjectProperty, @@ -196,40 +199,79 @@ export async function updateMiniProgramGlobalComponents( function parseVueComponentName(filename: string) { let name = path.basename(removeExt(filename)) - const ast = scriptDescriptors.get(filename) + const ast = scriptDescriptors.get(filename)?.ast if (!ast) return name - const exportDefaultDecliaration = scriptDescriptors - .get(filename) - ?.ast.body.find( - (v) => v.type === 'ExportDefaultDeclaration' - ) as ExportDefaultDeclaration | null + // 获取默认导出定义 + const exportDefaultDecliaration = ast.body.find((node) => + isExportDefaultDeclaration(node) + ) + + assertExportDefaultDeclaration(exportDefaultDecliaration) if (!exportDefaultDecliaration) return name + // 获取vue的defineComponent导入变量名 + let defineComponentLocalName: string | null = null + + for (const node of ast.body) { + if ( + isImportDeclaration(node) && + isStringLiteral(node.source, { value: 'vue' }) + ) { + const importSpecifer = node.specifiers.find( + (specifer) => + isImportSpecifier(specifer) && + isIdentifier(specifer.imported, { name: 'defineComponent' }) + ) + if (isImportSpecifier(importSpecifer)) { + defineComponentLocalName = importSpecifer.local.name + } + } + } + + // 获取组件定义对象 let defineComponentDeclaration: ObjectExpression | null = null - const { declaration } = exportDefaultDecliaration + let { declaration } = exportDefaultDecliaration + + // 如果默认导出了变量则尝试查找该变量 + if (isIdentifier(declaration)) { + const { name } = declaration + for (const node of ast.body) { + if (isVariableDeclaration(node)) { + assertIdentifier(declaration) + const declarator = node.declarations.find((declarator) => + isIdentifier(declarator.id, { name }) + ) + if (declarator?.init) { + declaration = declarator.init + } + } else if (isExportDefaultDeclaration(node)) { + break + } + } + } - if (declaration.type === 'ObjectExpression') { + if (isObjectExpression(declaration)) { defineComponentDeclaration = declaration } else if ( - declaration.type === 'CallExpression' && - declaration.callee.type === 'Identifier' && - /_*defineComponent/.test(declaration.callee.name) + defineComponentLocalName && + isCallExpression(declaration) && + isIdentifier(declaration.callee, { name: defineComponentLocalName }) && + isObjectExpression(declaration.arguments[0]) ) { - defineComponentDeclaration = - (declaration.arguments[0] as ObjectExpression | undefined) || null + defineComponentDeclaration = declaration.arguments[0] } if (!defineComponentDeclaration) return name for (const prop of defineComponentDeclaration.properties) { if ( - prop.type === 'ObjectProperty' && - prop.key.type === 'Identifier' && + isObjectProperty(prop) && + isIdentifier(prop.key) && /(__)?name/.test(prop.key.name) && - prop.value.type === 'StringLiteral' + isStringLiteral(prop.value) ) { return prop.value.value } From 60bcea4917b06848e5ad6b4058888a88fdf0ddd7 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Wed, 22 May 2024 01:47:06 +0800 Subject: [PATCH 05/10] chore: update --- packages/uni-cli-shared/src/mp/usingComponents.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index 940fb8241e..97636fbe1b 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -266,6 +266,7 @@ function parseVueComponentName(filename: string) { if (!defineComponentDeclaration) return name + // 尝试从组件定义对象中获取组件名 for (const prop of defineComponentDeclaration.properties) { if ( isObjectProperty(prop) && From 333e22d07d318773751efe4c5a0bccbb3b32a4bf Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Thu, 23 May 2024 01:53:20 +0800 Subject: [PATCH 06/10] =?UTF-8?q?chore:=20=E8=80=83=E8=99=91plugin-vue:exp?= =?UTF-8?q?ort-helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/usingComponents.spec.ts | 70 +++++++++++++------ .../uni-cli-shared/src/mp/usingComponents.ts | 39 ++++++++--- 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/packages/uni-cli-shared/__tests__/usingComponents.spec.ts b/packages/uni-cli-shared/__tests__/usingComponents.spec.ts index 408429471d..ae105ae651 100644 --- a/packages/uni-cli-shared/__tests__/usingComponents.spec.ts +++ b/packages/uni-cli-shared/__tests__/usingComponents.spec.ts @@ -301,9 +301,10 @@ export function createApp() { `const _easycom_test = ()=>import('${inputDir}/components/test/test.vue')` ) }) - test(`recursion`, async () => { - await testLocal( - ` + describe(`recursion`, () => { + test('base', async () => { + await testLocal( + ` const _sfc_main = { }; const __BINDING_COMPONENTS__ = '{"index":{"name":"_component_index","type":"unknown"}}'; @@ -314,14 +315,16 @@ export function createApp() { import _export_sfc from "plugin-vue:export-helper"; export default /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); `, - { - index: '/pages/index/index', - }, - `` - ) + { + index: '/pages/index/index', + }, + `` + ) + }) - await testLocal( - `import { defineComponent as _defineComponent } from "vue"; + test('use defineComponent', async () => { + await testLocal( + `import { defineComponent as _defineComponent } from "vue"; const __BINDING_COMPONENTS__ = '{"test":{"name":"test","type":"unknown"}}'; export default /* @__PURE__ */ _defineComponent({ @@ -334,14 +337,16 @@ export function createApp() { }); import "${inputDir}/pages/index/index.vue?vue&type=style&index=0&lang.css"; `, - { - test: '/pages/index/index', - }, - `` - ) + { + test: '/pages/index/index', + }, + `` + ) + }) - await testLocal( - `import { defineComponent as _defineComponent } from "vue"; + test('export variable', async () => { + await testLocal( + `import { defineComponent as _defineComponent } from "vue"; const __BINDING_COMPONENTS__ = '{"test":{"name":"test","type":"unknown"}}'; const component = _defineComponent({ __name: "test", @@ -356,11 +361,32 @@ export function createApp() { import "${inputDir}/pages/index/index.vue?vue&type=style&index=0&lang.css"; `, - { - test: '/pages/index/index', - }, - `` - ) + { + test: '/pages/index/index', + }, + `` + ) + }) + test('use plugin-vue:export-helper', async () => { + await testLocal( + ` + const _sfc_main = { + __name: 'Test' + }; + const __BINDING_COMPONENTS__ = '{"test":{"name":"_component_test","type":"unknown"}}'; + function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { + return {}; + } + import "${filename}?vue&type=style&index=0&lang.css"; + import _export_sfc from "plugin-vue:export-helper"; + export default /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); + `, + { + test: '/pages/index/index', + }, + `` + ) + }) }) }) }) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index 97636fbe1b..71cead012b 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -8,13 +8,14 @@ import { type Statement, type StringLiteral, assertExportDefaultDeclaration, - assertIdentifier, isBlockStatement, isCallExpression, isExportDefaultDeclaration, + isExpression, isIdentifier, isIfStatement, isImportDeclaration, + isImportDefaultSpecifier, isImportSpecifier, isMemberExpression, isObjectExpression, @@ -211,14 +212,13 @@ function parseVueComponentName(filename: string) { if (!exportDefaultDecliaration) return name - // 获取vue的defineComponent导入变量名 + // 获取vue的defineComponent导入变量名和plugin-vue:export-helper默认导入的本地变量名 let defineComponentLocalName: string | null = null + let exportHelperLocalName: string | null = null for (const node of ast.body) { - if ( - isImportDeclaration(node) && - isStringLiteral(node.source, { value: 'vue' }) - ) { + if (!isImportDeclaration(node)) continue + if (isStringLiteral(node.source, { value: 'vue' })) { const importSpecifer = node.specifiers.find( (specifer) => isImportSpecifier(specifer) && @@ -227,20 +227,37 @@ function parseVueComponentName(filename: string) { if (isImportSpecifier(importSpecifer)) { defineComponentLocalName = importSpecifer.local.name } + } else if ( + isStringLiteral(node.source, { value: 'plugin-vue:export-helper' }) + ) { + const importSpecifer = node.specifiers.find((specifer) => + isImportDefaultSpecifier(specifer) + ) + if (isImportDefaultSpecifier(importSpecifer)) { + exportHelperLocalName = importSpecifer.local.name + } } } + let { declaration } = exportDefaultDecliaration + // 如果默认导出调用plugin-vue:export-helper默认导入的方法则取方法的第一个参数 + if ( + exportHelperLocalName && + isCallExpression(declaration) && + isIdentifier(declaration.callee, { name: exportHelperLocalName }) && + isExpression(declaration.arguments[0]) + ) { + declaration = declaration.arguments[0] + } + // 获取组件定义对象 let defineComponentDeclaration: ObjectExpression | null = null - let { declaration } = exportDefaultDecliaration - - // 如果默认导出了变量则尝试查找该变量 + // 如果declaration是变量则尝试查找该变量 if (isIdentifier(declaration)) { const { name } = declaration for (const node of ast.body) { if (isVariableDeclaration(node)) { - assertIdentifier(declaration) const declarator = node.declarations.find((declarator) => isIdentifier(declarator.id, { name }) ) @@ -274,7 +291,7 @@ function parseVueComponentName(filename: string) { /(__)?name/.test(prop.key.name) && isStringLiteral(prop.value) ) { - return prop.value.value + return prop.value.value || name } } return name From 3f472f34e784090040f8dd65850cc43968a82dd5 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Thu, 23 May 2024 23:34:16 +0800 Subject: [PATCH 07/10] =?UTF-8?q?chore:=20=E8=80=83=E8=99=91plugin-vue:exp?= =?UTF-8?q?ort-helper=E5=89=8D=E5=8F=AF=E8=83=BD=E5=B8=A6\0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-cli-shared/__tests__/usingComponents.spec.ts | 2 +- packages/uni-cli-shared/src/mp/usingComponents.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/uni-cli-shared/__tests__/usingComponents.spec.ts b/packages/uni-cli-shared/__tests__/usingComponents.spec.ts index ae105ae651..245e4c88c9 100644 --- a/packages/uni-cli-shared/__tests__/usingComponents.spec.ts +++ b/packages/uni-cli-shared/__tests__/usingComponents.spec.ts @@ -378,7 +378,7 @@ export function createApp() { return {}; } import "${filename}?vue&type=style&index=0&lang.css"; - import _export_sfc from "plugin-vue:export-helper"; + import _export_sfc from "\0plugin-vue:export-helper"; export default /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); `, { diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index 71cead012b..d4fa18dc21 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -218,7 +218,7 @@ function parseVueComponentName(filename: string) { for (const node of ast.body) { if (!isImportDeclaration(node)) continue - if (isStringLiteral(node.source, { value: 'vue' })) { + if (node.source.value === 'vue') { const importSpecifer = node.specifiers.find( (specifer) => isImportSpecifier(specifer) && @@ -228,7 +228,8 @@ function parseVueComponentName(filename: string) { defineComponentLocalName = importSpecifer.local.name } } else if ( - isStringLiteral(node.source, { value: 'plugin-vue:export-helper' }) + // plugin-vue:export-helper前可能有\0 + /\0?plugin-vue:export-helper/.test(node.source.value) ) { const importSpecifer = node.specifiers.find((specifer) => isImportDefaultSpecifier(specifer) From 4c9bd39c2b75276932d0f7e4d62d81b6b37fe940 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Thu, 23 May 2024 23:37:27 +0800 Subject: [PATCH 08/10] chore: update --- packages/uni-cli-shared/src/mp/usingComponents.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index d4fa18dc21..ff2468ae46 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -229,7 +229,7 @@ function parseVueComponentName(filename: string) { } } else if ( // plugin-vue:export-helper前可能有\0 - /\0?plugin-vue:export-helper/.test(node.source.value) + /^\0?plugin-vue:export-helper$/.test(node.source.value) ) { const importSpecifer = node.specifiers.find((specifer) => isImportDefaultSpecifier(specifer) @@ -289,7 +289,7 @@ function parseVueComponentName(filename: string) { if ( isObjectProperty(prop) && isIdentifier(prop.key) && - /(__)?name/.test(prop.key.name) && + /^(__)?name$/.test(prop.key.name) && isStringLiteral(prop.value) ) { return prop.value.value || name From 89ea077ac144a7bb7e71b38c5f0d4de6a54de282 Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Fri, 21 Jun 2024 01:57:05 +0800 Subject: [PATCH 09/10] Update usingComponents.ts --- packages/uni-cli-shared/src/mp/usingComponents.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index ff2468ae46..bbbb884840 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -7,7 +7,7 @@ import { type Program, type Statement, type StringLiteral, - assertExportDefaultDeclaration, + type ExportDefaultDeclaration, isBlockStatement, isCallExpression, isExportDefaultDeclaration, @@ -206,9 +206,7 @@ function parseVueComponentName(filename: string) { // 获取默认导出定义 const exportDefaultDecliaration = ast.body.find((node) => isExportDefaultDeclaration(node) - ) - - assertExportDefaultDeclaration(exportDefaultDecliaration) + ) as ExportDefaultDeclaration | undefined if (!exportDefaultDecliaration) return name From 533395bf81265b94565616b2a99d6c9af47175ef Mon Sep 17 00:00:00 2001 From: acyza <101238421+acyza@users.noreply.github.com> Date: Fri, 21 Jun 2024 01:59:24 +0800 Subject: [PATCH 10/10] Update usingComponents.ts --- packages/uni-cli-shared/src/mp/usingComponents.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/uni-cli-shared/src/mp/usingComponents.ts b/packages/uni-cli-shared/src/mp/usingComponents.ts index bbbb884840..9bef4b28c8 100644 --- a/packages/uni-cli-shared/src/mp/usingComponents.ts +++ b/packages/uni-cli-shared/src/mp/usingComponents.ts @@ -1,4 +1,5 @@ import { + type ExportDefaultDeclaration, type IfStatement, type ImportDeclaration, type Node, @@ -7,7 +8,6 @@ import { type Program, type Statement, type StringLiteral, - type ExportDefaultDeclaration, isBlockStatement, isCallExpression, isExportDefaultDeclaration,