All files / src amd.js

100% Statements 22/22
87.5% Branches 14/16
100% Functions 3/3
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49    1x   1x 35x 67x 61x     6x 6x 1x     5x 5x   5x 4x         1x 4x   4x 1x   3x 1x     2x   2x           3x 3x          
"use strict";
 
const {generateModuleName} = require("./util");
 
module.exports.getDefineExpression = function getDefineExpression(t, bodyPaths) {
    for (const bodyStatementPath of bodyPaths) {
        if ( !t.isExpressionStatement(bodyStatementPath) ) {
            continue;
        }
 
        const expression = bodyStatementPath.get("expression");
        if ( !t.isCallExpression(expression) ) {
            continue;
        }
 
        const calleeNode = expression.get("callee");
        const nameNode = calleeNode.get("name");
 
        if ( nameNode.node == "define" ) {
            return expression;
        }
    }
};
 
module.exports.onAmdModule = function onAmdModule(t, meta, defineExpression) {
    const options = meta.opts || {};
 
    if ( !options.moduleName ) {
        return;
    }
    if ( !isAnonymousDefine(t, defineExpression) ) {
        return;
    }
 
    const moduleName = generateModuleName(meta);                
                
    defineExpression.node.arguments.unshift(
        t.stringLiteral( moduleName )
    );
};
 
function isAnonymousDefine(t, defineExpression) {
    const args = defineExpression.get("arguments") || [];
    return (
        args[0] && 
            t.isArrayExpression( args[0] )
    );
}