packages/okam-build/lib/processor/js/transform/visitor.js
function transformMiniProgram(t, path, declarationPath, config, opts) {
    if (t.isObjectExpression(declarationPath)) {
        // extract the config information defined in the code
        declarationPath.traverse(
            getCodeTraverseVisitors(t, config, opts)
        );
    }
    else if (opts.isExtension) {
        return;
    }
    else {
        throw path.buildCodeFrameError('export require plain object');
    }

    let baseClassName = path.scope.generateUid(opts.baseName);
    let rootPath = path.findParent(p => t.isProgram(p));
    let bodyPath = rootPath.get('body.0');

    // ensure the inserted import declaration is after the leading comment
    removeComments(t, bodyPath, 'leadingComments');

    // insert the base name import statement
    bodyPath.insertBefore(
        createImportDeclaration(baseClassName, opts.baseId, t)
    );

    if (opts.isApp) {
        // insert the app extension use statements
        appTransformer.extendAppFramework(
            t, path, bodyPath, baseClassName, opts
        );
    }

    let callArgs = createInitCallArgs(declarationPath, config.config, opts, t);
    let needExport = opts.needExport || !opts.baseClass;
    let toReplacePath = needExport
        ? path.get('declaration')
        : path;
    // wrap the export module using the base name
    let callExpression = t.callExpression(
        t.identifier(baseClassName),
        callArgs
    );
    if (opts.isBehavior || !opts.baseClass) {
        toReplacePath.replaceWith(t.expressionStatement(
            callExpression
        ));
    }
    else {
        toReplacePath.replaceWith(
            t.expressionStatement(
                t.callExpression(
                    t.identifier(opts.baseClass),
                    [
                        callExpression
                    ]
                )
            )
        );
    }

    // stop traverse to avoid the new created export default statement above
    // that be revisited in this plugin `ExportDefaultDeclaration` visitor
    // path.stop();
}
function transformMiniProgram(t, path, declarationPath, config, opts) {
    if (t.isObjectExpression(declarationPath)) {
        // extract the config information defined in the code
        declarationPath.traverse(
            getCodeTraverseVisitors(t, config, opts)
        );
    }
    else if (opts.isExtension) {
        return;
    }
    else {
        throw path.buildCodeFrameError('export require plain object');
    }

    let baseClassName = path.scope.generateUid(opts.baseName);
    let rootPath = path.findParent(p => t.isProgram(p));
    let bodyPath = rootPath.get('body.0');

    // ensure the inserted import declaration is after the leading comment
    removeComments(t, bodyPath, 'leadingComments');

    // insert the base name import statement
    bodyPath.insertBefore(
        createImportDeclaration(baseClassName, opts.baseId, t)
    );

    if (opts.isApp) {
        // insert the app extension use statements
        appTransformer.extendAppFramework(
            t, path, bodyPath, baseClassName, opts
        );
    }

    let callArgs = createInitCallArgs(declarationPath, config.config, opts, t);
    let needExport = opts.needExport || !opts.baseClass;
    let toReplacePath = needExport
        ? path.get('declaration')
        : path;
    // wrap the export module using the base name
    let callExpression = t.callExpression(
        t.identifier(baseClassName),
        callArgs
    );
    if (opts.isBehavior || !opts.baseClass) {
        toReplacePath.replaceWith(t.expressionStatement(
            callExpression
        ));
    }
    else {
        toReplacePath.replaceWith(
            t.expressionStatement(
                t.callExpression(
                    t.identifier(opts.baseClass),
                    [
                        callExpression
                    ]
                )
            )
        );
    }

    // stop traverse to avoid the new created export default statement above
    // that be revisited in this plugin `ExportDefaultDeclaration` visitor
    // path.stop();
}
Transform mini program code

@inner
@param {Object} t the babel type definition
@param {Object} path the node path to transform
@param {Object} declarationPath the declaration statement path to process
@param {Object} config the config used to cache the config information
defined in the code
@param {Object} opts the transformation options