Skip to content

Commit

Permalink
fix(mini-runner): 编译时移除组件文件引用,遗漏了 npm 包中组件,close #5139
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 7, 2020
1 parent c889d55 commit ea7023b
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions packages/taro-mini-runner/src/loaders/fileParseLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,41 +470,33 @@ function processAst (
},
ImportDeclaration (astPath) {
const node = astPath.node
const source = node.source
let value = source.value
const specifiers = node.specifiers
let needRemove = false
if (!isNpmPkg(value)) {
specifiers.forEach(item => {
if (customComponents.has(item.local.name)) {
needRemove = true
}
})
if (needRemove) {
astPath.remove()
specifiers.forEach(item => {
if (customComponents.has(item.local.name)) {
needRemove = true
}
})
if (needRemove) {
astPath.remove()
}
},
CallExpression (astPath) {
const node = astPath.node
const callee = node.callee as t.Identifier
if (callee.name === 'require') {
const parentNode = astPath.parentPath.node as t.VariableDeclarator
const args = node.arguments as t.StringLiteral[]
let value = args[0].value
let needRemove = false
if (!isNpmPkg(value)) {
const id = parentNode.id
if (t.isObjectPattern(id)) {
const properties = id.properties
properties.forEach(property => {
if (t.isObjectProperty(property) && customComponents.has((property.value as t.Identifier).name)) {
needRemove = true
}
})
} else if (t.isIdentifier(id) && customComponents.has(id.name)) {
needRemove = true
}
const id = parentNode.id
if (t.isObjectPattern(id)) {
const properties = id.properties
properties.forEach(property => {
if (t.isObjectProperty(property) && customComponents.has((property.value as t.Identifier).name)) {
needRemove = true
}
})
} else if (t.isIdentifier(id) && customComponents.has(id.name)) {
needRemove = true
}
if (needRemove) {
astPath.parentPath.parentPath.remove()
Expand Down

0 comments on commit ea7023b

Please sign in to comment.