packages/okam-build/lib/processor/js/transform/component.js
function getRequiredModulePath(valuePath, moduleName, t, removeRequireDeclaration = false) {
    let bindVar = valuePath.scope.bindings[moduleName];
    if (!bindVar) {
        throw valuePath.buildCodeFrameError(`the variable ${moduleName} import declaration is not found`);
    }

    let declareNodePath = bindVar.path;
    let parentStatementPath = bindVar.path.getStatementParent();

    // check import statement
    if (t.isImportDeclaration(parentStatementPath)) {
        let id = parentStatementPath.node.source.value;
        if (removeRequireDeclaration) {
            let toRemovePath = declareNodePath;
            if (t.isImportDefaultSpecifier(declareNodePath.node)) {
                toRemovePath = declareNodePath.parentPath;
            }
            removeNode(t, toRemovePath, {tail: true});
        }
        return id;
    }
    else if (t.isVariableDeclarator(declareNodePath)) {
        // check require statement
        let initNode = declareNodePath.node.init;
        let id = getRequireExpressionModuleId(initNode, t);
        if (id) {
            removeRequireDeclaration && removeVariableDeclaration(
                t, bindVar, {tail: true}
            );
            return id;
        }
    }

    throw valuePath.buildCodeFrameError(`the variable ${moduleName} import declaration is not found`);
}
function getRequiredModulePath(valuePath, moduleName, t, removeRequireDeclaration = false) {
    let bindVar = valuePath.scope.bindings[moduleName];
    if (!bindVar) {
        throw valuePath.buildCodeFrameError(`the variable ${moduleName} import declaration is not found`);
    }

    let declareNodePath = bindVar.path;
    let parentStatementPath = bindVar.path.getStatementParent();

    // check import statement
    if (t.isImportDeclaration(parentStatementPath)) {
        let id = parentStatementPath.node.source.value;
        if (removeRequireDeclaration) {
            let toRemovePath = declareNodePath;
            if (t.isImportDefaultSpecifier(declareNodePath.node)) {
                toRemovePath = declareNodePath.parentPath;
            }
            removeNode(t, toRemovePath, {tail: true});
        }
        return id;
    }
    else if (t.isVariableDeclarator(declareNodePath)) {
        // check require statement
        let initNode = declareNodePath.node.init;
        let id = getRequireExpressionModuleId(initNode, t);
        if (id) {
            removeRequireDeclaration && removeVariableDeclaration(
                t, bindVar, {tail: true}
            );
            return id;
        }
    }

    throw valuePath.buildCodeFrameError(`the variable ${moduleName} import declaration is not found`);
}
function getRequiredModulePath ( valuePath , moduleName , t , removeRequireDeclaration = false ) { let bindVar = valuePath . scope . bindings [ moduleName ] ; if ( ! bindVar ) { throw valuePath . buildCodeFrameError ( ` ${ moduleName } ` ) ; } let declareNodePath = bindVar . path ; let parentStatementPath = bindVar . path . getStatementParent ( ) ; // check import statement if ( t . isImportDeclaration ( parentStatementPath ) ) { let id = parentStatementPath . node . source . value ; if ( removeRequireDeclaration ) { let toRemovePath = declareNodePath ; if ( t . isImportDefaultSpecifier ( declareNodePath . node ) ) { toRemovePath = declareNodePath . parentPath ; } removeNode ( t , toRemovePath , { tail : true } ) ; } return id ; } else if ( t . isVariableDeclarator ( declareNodePath ) ) { // check require statement let initNode = declareNodePath . node . init ; let id = getRequireExpressionModuleId ( initNode , t ) ; if ( id ) { removeRequireDeclaration && removeVariableDeclaration ( t , bindVar , { tail : true } ) ; return id ; } } throw valuePath . buildCodeFrameError ( ` ${ moduleName } ` ) ; }
Get the required module path or id information

@inner
@param {Object} valuePath the used module variable node path
@param {string} moduleName the module variable name
@param {Object} t the babel type definition
@param {boolean=} removeRequireDeclaration whether remove the module require
declaration statement.
@return {string}
Get the required module path or id information