From ea7023b6cfc824a73b164b355f707ec748370de1 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Tue, 24 Dec 2019 11:25:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(mini-runner):=20=E7=BC=96=E8=AF=91=E6=97=B6?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=BB=84=E4=BB=B6=E6=96=87=E4=BB=B6=E5=BC=95?= =?UTF-8?q?=E7=94=A8=EF=BC=8C=E9=81=97=E6=BC=8F=E4=BA=86=20npm=20=E5=8C=85?= =?UTF-8?q?=E4=B8=AD=E7=BB=84=E4=BB=B6=EF=BC=8Cclose=20#5139?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/loaders/fileParseLoader.ts | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/packages/taro-mini-runner/src/loaders/fileParseLoader.ts b/packages/taro-mini-runner/src/loaders/fileParseLoader.ts index ae600aad6087..a228e474b3ca 100644 --- a/packages/taro-mini-runner/src/loaders/fileParseLoader.ts +++ b/packages/taro-mini-runner/src/loaders/fileParseLoader.ts @@ -470,19 +470,15 @@ 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) { @@ -490,21 +486,17 @@ function processAst ( 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()