Skip to content

Commit

Permalink
feat: 添加package
Browse files Browse the repository at this point in the history
  • Loading branch information
jien.li committed Dec 29, 2023
1 parent fa814b8 commit 832144a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/cli/packages/babelPlugins/miniappVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,21 @@ const visitor = {
},
FunctionDeclaration: {
exit(astPath, state) {
let modules = utils_1.default.getAnu(state);
let name = astPath.node.id.name;
const functionBody = astPath.get('body');
const node = functionBody.get('body');
const newBody = node[node.length - 1];
if (newBody) {
const returnValue = newBody.get('argument');
if (t.isConditionalExpression(returnValue.node)) {
const { test, consequent, alternate } = returnValue.node;
if (consequent.type === 'NullLiteral') {
const newConditionalExpression = t.conditionalExpression(test, t.stringLiteral(''), alternate);
returnValue.replaceWith(newConditionalExpression);
}
}
}
let modules = utils_1.default.getAnu(state);
if (/^[A-Z]/.test(name) &&
modules.componentType === 'Component' &&
!modules.parentName &&
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/packages/wxHelpers/classDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ const template_1 = __importDefault(require("@babel/template"));
const utils_1 = __importDefault(require("../utils"));
module.exports = {
enter(astPath, state) {
const className = astPath.node.id.name;
const renderMethod = astPath.get('body').get('body').find((method) => method.isClassMethod() && method.get('key').isIdentifier({ name: 'render' }));
if (renderMethod) {
const returnStatement = renderMethod.get('body').get('body').find((statement) => statement.isReturnStatement());
if (returnStatement) {
const renderContent = returnStatement.get('argument');
const { type, test, consequent, alternate } = renderContent.node;
if (type === 'ConditionalExpression' && consequent.type === 'NullLiteral') {
if (consequent.type === 'NullLiteral') {
const newConditionalExpression = t.conditionalExpression(test, t.stringLiteral(''), alternate);
renderContent.replaceWith(newConditionalExpression);
}
}
}
}
let modules = utils_1.default.getAnu(state);
modules.className = astPath.node.id.name;
modules.parentName = generator_1.default(astPath.node.superClass).code || 'Object';
Expand Down

0 comments on commit 832144a

Please sign in to comment.