Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
acyza committed May 21, 2024
1 parent 09440a2 commit 0cada9c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/uni-cli-shared/src/mp/usingComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type StringLiteral,
isBlockStatement,
isCallExpression,
isExportDefaultDeclaration,
isIdentifier,
isIfStatement,
isImportDeclaration,
Expand Down Expand Up @@ -201,8 +202,8 @@ function parseVueComponentName(filename: string) {

const exportDefaultDecliaration = scriptDescriptors
.get(filename)
?.ast.body.find(
(v) => v.type === 'ExportDefaultDeclaration'
?.ast.body.find((node) =>
isExportDefaultDeclaration(node)
) as ExportDefaultDeclaration | null

if (!exportDefaultDecliaration) return name
Expand All @@ -211,11 +212,11 @@ function parseVueComponentName(filename: string) {

const { declaration } = exportDefaultDecliaration

if (declaration.type === 'ObjectExpression') {
if (isObjectExpression(declaration)) {
defineComponentDeclaration = declaration
} else if (
declaration.type === 'CallExpression' &&
declaration.callee.type === 'Identifier' &&
isCallExpression(declaration) &&
isIdentifier(declaration.callee) &&
/_*defineComponent/.test(declaration.callee.name)
) {
defineComponentDeclaration =
Expand All @@ -226,10 +227,10 @@ function parseVueComponentName(filename: string) {

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
}
Expand Down

0 comments on commit 0cada9c

Please sign in to comment.