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 6bb5020
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/uni-cli-shared/src/mp/usingComponents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
type ExportDefaultDeclaration,
type IfStatement,
type ImportDeclaration,
type Node,
Expand All @@ -8,8 +7,10 @@ import {
type Program,
type Statement,
type StringLiteral,
assertExportDefaultDeclaration,
isBlockStatement,
isCallExpression,
isExportDefaultDeclaration,
isIdentifier,
isIfStatement,
isImportDeclaration,
Expand Down Expand Up @@ -201,35 +202,35 @@ function parseVueComponentName(filename: string) {

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

assertExportDefaultDeclaration(exportDefaultDecliaration)

if (!exportDefaultDecliaration) return name

let defineComponentDeclaration: ObjectExpression | null = null

const { declaration } = exportDefaultDecliaration

if (declaration.type === 'ObjectExpression') {
if (isObjectExpression(declaration)) {
defineComponentDeclaration = declaration
} else if (
declaration.type === 'CallExpression' &&
declaration.callee.type === 'Identifier' &&
/_*defineComponent/.test(declaration.callee.name)
isCallExpression(declaration) &&
isIdentifier(declaration.callee) &&
/_*defineComponent/.test(declaration.callee.name) &&
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
}
Expand Down

0 comments on commit 6bb5020

Please sign in to comment.