Skip to content

Commit

Permalink
feat(cli): add exportDeclaration support
Browse files Browse the repository at this point in the history
  • Loading branch information
Genuifx committed Mar 4, 2020
1 parent 0267948 commit 2dc9928
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/wxa-cli/src/resolvers/ast/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,19 @@ export default class ASTManager {

let self = this;
let libs = [];
let importStatement = [
t.callExpression.name,
t.importDeclaration.name,
t.exportAllDeclaration.name,
t.exportNamedDeclaration.name].join('|');

traverse(mdl.ast, {
[t.callExpression.name+'|'+t.importDeclaration.name]: (path) => {
[importStatement]: (path) => {
let dep;
let typeOfPath;
const StringLiteralRequire = 'StringLiteralRequire';
const ImportDeclaration = 'ImportDeclaration';
const ExportDeclaration = 'ExportDeclaration';

// commandJS module
if (
Expand All @@ -103,6 +110,13 @@ export default class ASTManager {
) {
dep = path.node.source.value;
typeOfPath = ImportDeclaration;
} else if (
(t.isExportAllDeclaration(path.node) || t.isExportNamedDeclaration(path.node)) &&
t.isLiteral(path.node.source) &&
path.node.source.value
) {
dep = path.node.source.value;
typeOfPath = ExportDeclaration;
} else {
return;
}
Expand Down Expand Up @@ -133,6 +147,10 @@ export default class ASTManager {
path.get('source').replaceWith(t.stringLiteral(resolved));
path.skip();
break;
case ExportDeclaration:
path.get('source').replaceWith(t.stringLiteral(resolved));
path.skip();
break;
}
} catch (e) {
logger.error('解析失败', e);
Expand All @@ -144,6 +162,7 @@ export default class ASTManager {
this.checkUnreachableCode(path);
},
[t.assignmentExpression.name]: (path) => {
// inject platform env to runtime app.
if (
t.isMemberExpression(path.node.left) &&
t.isThisExpression(path.node.left.object) &&
Expand Down

0 comments on commit 2dc9928

Please sign in to comment.