function findTs2_3EnumIife(name, statement) {
    if (!ts.isExpressionStatement(statement) || !ts.isCallExpression(statement.expression)) {
        return null;
    }
    const funcExpr = ast_utils_1.drilldownNodes(statement, [
        { prop: null, kind: ts.SyntaxKind.ExpressionStatement },
        { prop: 'expression', kind: ts.SyntaxKind.CallExpression },
        { prop: 'expression', kind: ts.SyntaxKind.ParenthesizedExpression },
        { prop: 'expression', kind: ts.SyntaxKind.FunctionExpression },
    ]);
    if (funcExpr === null) {
        return null;
    }
    if (!(funcExpr.parameters.length === 1
        && funcExpr.parameters[0].name.kind === ts.SyntaxKind.Identifier
        && funcExpr.parameters[0].name.text === name)) {
        return null;
    }
    // In TS 2.3 enums, the IIFE contains only expressions with a certain format.
    // If we find any that is different, we ignore the whole thing.
    for (const innerStmt of funcExpr.body.statements) {
        const innerBinExpr = ast_utils_1.drilldownNodes(innerStmt, [
            { prop: null, kind: ts.SyntaxKind.ExpressionStatement },
            { prop: 'expression', kind: ts.SyntaxKind.BinaryExpression },
        ]);
        if (innerBinExpr === null) {
            return null;
        }
        if (!(innerBinExpr.operatorToken.kind === ts.SyntaxKind.FirstAssignment
            && innerBinExpr.left.kind === ts.SyntaxKind.ElementAccessExpression)) {
            return null;
        }
        const innerElemAcc = innerBinExpr.left;
        if (!(innerElemAcc.expression.kind === ts.SyntaxKind.Identifier
            && innerElemAcc.expression.text === name
            && innerElemAcc.argumentExpression
            && innerElemAcc.argumentExpression.kind === ts.SyntaxKind.BinaryExpression)) {
            return null;
        }
        const innerArgBinExpr = innerElemAcc.argumentExpression;
        if (innerArgBinExpr.left.kind !== ts.SyntaxKind.ElementAccessExpression) {
            return null;
        }
        const innerArgElemAcc = innerArgBinExpr.left;
        if (!(innerArgElemAcc.expression.kind === ts.SyntaxKind.Identifier
            && innerArgElemAcc.expression.text === name)) {
            return null;
        }
    }
    return statement.expression;
}
// TS 2.3 enums have statements that are inside a IIFE.
TS 2.3 enums have statements that are inside a IIFE.
TS 2 . 3 enums have statements that are inside a IIFE .
function findTs2_3EnumIife(name, statement) {
    if (!ts.isExpressionStatement(statement) || !ts.isCallExpression(statement.expression)) {
        return null;
    }
    const funcExpr = ast_utils_1.drilldownNodes(statement, [
        { prop: null, kind: ts.SyntaxKind.ExpressionStatement },
        { prop: 'expression', kind: ts.SyntaxKind.CallExpression },
        { prop: 'expression', kind: ts.SyntaxKind.ParenthesizedExpression },
        { prop: 'expression', kind: ts.SyntaxKind.FunctionExpression },
    ]);
    if (funcExpr === null) {
        return null;
    }
    if (!(funcExpr.parameters.length === 1
        && funcExpr.parameters[0].name.kind === ts.SyntaxKind.Identifier
        && funcExpr.parameters[0].name.text === name)) {
        return null;
    }
    for (const innerStmt of funcExpr.body.statements) {
        const innerBinExpr = ast_utils_1.drilldownNodes(innerStmt, [
            { prop: null, kind: ts.SyntaxKind.ExpressionStatement },
            { prop: 'expression', kind: ts.SyntaxKind.BinaryExpression },
        ]);
        if (innerBinExpr === null) {
            return null;
        }
        if (!(innerBinExpr.operatorToken.kind === ts.SyntaxKind.FirstAssignment
            && innerBinExpr.left.kind === ts.SyntaxKind.ElementAccessExpression)) {
            return null;
        }
        const innerElemAcc = innerBinExpr.left;
        if (!(innerElemAcc.expression.kind === ts.SyntaxKind.Identifier
            && innerElemAcc.expression.text === name
            && innerElemAcc.argumentExpression
            && innerElemAcc.argumentExpression.kind === ts.SyntaxKind.BinaryExpression)) {
            return null;
        }
        const innerArgBinExpr = innerElemAcc.argumentExpression;
        if (innerArgBinExpr.left.kind !== ts.SyntaxKind.ElementAccessExpression) {
            return null;
        }
        const innerArgElemAcc = innerArgBinExpr.left;
        if (!(innerArgElemAcc.expression.kind === ts.SyntaxKind.Identifier
            && innerArgElemAcc.expression.text === name)) {
            return null;
        }
    }
    return statement.expression;
}
function findTs2_3EnumIife ( name , statement ) { if ( ! ts . isExpressionStatement ( statement ) || ! ts . isCallExpression ( statement . expression ) ) { return null ; } const funcExpr = ast_utils_1 . drilldownNodes ( statement , [ { prop : null , kind : ts . SyntaxKind . ExpressionStatement } , { prop : 'expression' , kind : ts . SyntaxKind . CallExpression } , { prop : 'expression' , kind : ts . SyntaxKind . ParenthesizedExpression } , { prop : 'expression' , kind : ts . SyntaxKind . FunctionExpression } , ] ) ; if ( funcExpr === null ) { return null ; } if ( ! ( funcExpr . parameters . length === 1 && funcExpr . parameters [ 0 ] . name . kind === ts . SyntaxKind . Identifier && funcExpr . parameters [ 0 ] . name . text === name ) ) { return null ; } for ( const innerStmt of funcExpr . body . statements ) { const innerBinExpr = ast_utils_1 . drilldownNodes ( innerStmt , [ { prop : null , kind : ts . SyntaxKind . ExpressionStatement } , { prop : 'expression' , kind : ts . SyntaxKind . BinaryExpression } , ] ) ; if ( innerBinExpr === null ) { return null ; } if ( ! ( innerBinExpr . operatorToken . kind === ts . SyntaxKind . FirstAssignment && innerBinExpr . left . kind === ts . SyntaxKind . ElementAccessExpression ) ) { return null ; } const innerElemAcc = innerBinExpr . left ; if ( ! ( innerElemAcc . expression . kind === ts . SyntaxKind . Identifier && innerElemAcc . expression . text === name && innerElemAcc . argumentExpression && innerElemAcc . argumentExpression . kind === ts . SyntaxKind . BinaryExpression ) ) { return null ; } const innerArgBinExpr = innerElemAcc . argumentExpression ; if ( innerArgBinExpr . left . kind !== ts . SyntaxKind . ElementAccessExpression ) { return null ; } const innerArgElemAcc = innerArgBinExpr . left ; if ( ! ( innerArgElemAcc . expression . kind === ts . SyntaxKind . Identifier && innerArgElemAcc . expression . text === name ) ) { return null ; } } return statement . expression ; }
TS 2.3 enums have statements that are inside a IIFE.
TS 2 . 3 enums have statements that are inside a IIFE .
// In TS 2.3 enums, the IIFE contains only expressions with a certain format. // If we find any that is different, we ignore the whole thing.