Skip to content

Commit

Permalink
fix(mini-runner): 组件引用支持 import as 语法
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 7, 2020
1 parent 978cef0 commit 0f0d834
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export default class MiniPlugin {
if (isTaroComponent) {
return component.path
}
const componentName = component.name!.split('|')[1] || component.name
const { ast } = transformResult
traverse(ast, {
ExportNamedDeclaration (astPath) {
Expand All @@ -274,14 +275,14 @@ export default class MiniPlugin {
if (source && source.type === 'StringLiteral') {
specifiers.forEach(specifier => {
const exported = specifier.exported
if (kebabCase(exported.name) === component.name) {
if (kebabCase(exported.name) === componentName) {
componentRealPath = resolveScriptPath(path.resolve(path.dirname(component.path as string), source.value))
}
})
} else {
specifiers.forEach(specifier => {
const exported = specifier.exported
if (kebabCase(exported.name) === component.name) {
if (kebabCase(exported.name) === componentName) {
importExportName = exported.name
}
})
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-mini-runner/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export function buildUsingComponents (
componentPath = component.path
}
if (component.name) {
usingComponents[component.name] = (componentPath as string).replace(path.extname(componentPath as string), '')
const componentName = component.name.split('|')[0]
usingComponents[componentName] = (componentPath as string).replace(path.extname(componentPath as string), '')
}
}
return Object.assign({}, isComponent ? { component: true } : { usingComponents: {} }, components.length ? {
Expand Down

0 comments on commit 0f0d834

Please sign in to comment.