function evaluate({ typeChecker, node, environment: { preset = exports.EnvironmentPresetKind.NODE, extra = {} } = {}, typescript = TSModule__namespace, logLevel = 0 /* SILENT */, policy: { deterministic = false, network = false, console = false, maxOps = Infinity, maxOpDuration = Infinity, io = {
    read: true,
    write: false
}, process = {
    exit: false,
    spawnChild: false
} } = {}, reporting: reportingInput = {} }) {
    // Take the simple path first. This may be far more performant than building up an environment
    const simpleLiteralResult = evaluateSimpleLiteral(node, typescript);
    if (simpleLiteralResult.success)
        return simpleLiteralResult;
    // Otherwise, build an environment and get to work
    // Sanitize the evaluation policy based on the input options
    const policy = {
        deterministic,
        maxOps,
        maxOpDuration,
        network,
        console,
        io: {
            read: typeof io === "boolean" ? io : io.read,
            write: typeof io === "boolean" ? io : io.write
        },
        process: {
            exit: typeof process === "boolean" ? process : process.exit,
            spawnChild: typeof process === "boolean" ? process : process.spawnChild
        }
    };
    // Sanitize the Reporting options based on the input options
    const reporting = Object.assign(Object.assign({}, reportingInput), { reportedErrorSet: createReportedErrorSet() });
    // Prepare a reference to the Node that is currently being evaluated
    let currentNode = node;
    // Prepare a logger
    const logger = new Logger(logLevel);
    // Prepare the initial environment
    const initialEnvironment = createLexicalEnvironment({
        inputEnvironment: {
            preset,
            extra
        },
        policy,
        getCurrentNode: () => currentNode
    });
    // Prepare a Stack
    const stack = createStack();
    // Prepare a NodeEvaluator
    const nodeEvaluator = createNodeEvaluator({
        policy,
        typeChecker,
        typescript,
        logger,
        stack,
        reporting: reporting,
        nextNode: nextNode => (currentNode = nextNode)
    });
    try {
        let value;
        if (isExpression(node, typescript)) {
            value = nodeEvaluator.expression(node, initialEnvironment, createStatementTraversalStack());
        }
        else if (isStatement(node, typescript)) {
            nodeEvaluator.statement(node, initialEnvironment);
            value = stack.pop();
        }
        else if (isDeclaration(node, typescript)) {
            nodeEvaluator.declaration(node, initialEnvironment, createStatementTraversalStack());
            value = stack.pop();
        }
        // Otherwise, throw an UnexpectedNodeError
        else {
            // noinspection ExceptionCaughtLocallyJS
            throw new UnexpectedNodeError({ node, typescript });
        }
        // Log the value before returning
        logger.logResult(value);
        return {
            success: true,
            value
        };
    }
    catch (reason) {
        // Report the Error
        reportError(reporting, reason, node);
        return {
            success: false,
            reason
        };
    }
}
/**
 * Will get a literal value for the given Expression, ExpressionStatement, or Declaration.
 */
Will get a literal value for the given Expression, ExpressionStatement, or Declaration.
Will get a literal value for the given Expression ExpressionStatement or Declaration .
function evaluate({ typeChecker, node, environment: { preset = exports.EnvironmentPresetKind.NODE, extra = {} } = {}, typescript = TSModule__namespace, logLevel = 0 , policy: { deterministic = false, network = false, console = false, maxOps = Infinity, maxOpDuration = Infinity, io = {
    read: true,
    write: false
}, process = {
    exit: false,
    spawnChild: false
} } = {}, reporting: reportingInput = {} }) {
    const simpleLiteralResult = evaluateSimpleLiteral(node, typescript);
    if (simpleLiteralResult.success)
        return simpleLiteralResult;
    const policy = {
        deterministic,
        maxOps,
        maxOpDuration,
        network,
        console,
        io: {
            read: typeof io === "boolean" ? io : io.read,
            write: typeof io === "boolean" ? io : io.write
        },
        process: {
            exit: typeof process === "boolean" ? process : process.exit,
            spawnChild: typeof process === "boolean" ? process : process.spawnChild
        }
    };
    const reporting = Object.assign(Object.assign({}, reportingInput), { reportedErrorSet: createReportedErrorSet() });
    let currentNode = node;
    const logger = new Logger(logLevel);
    const initialEnvironment = createLexicalEnvironment({
        inputEnvironment: {
            preset,
            extra
        },
        policy,
        getCurrentNode: () => currentNode
    });
    const stack = createStack();
    const nodeEvaluator = createNodeEvaluator({
        policy,
        typeChecker,
        typescript,
        logger,
        stack,
        reporting: reporting,
        nextNode: nextNode => (currentNode = nextNode)
    });
    try {
        let value;
        if (isExpression(node, typescript)) {
            value = nodeEvaluator.expression(node, initialEnvironment, createStatementTraversalStack());
        }
        else if (isStatement(node, typescript)) {
            nodeEvaluator.statement(node, initialEnvironment);
            value = stack.pop();
        }
        else if (isDeclaration(node, typescript)) {
            nodeEvaluator.declaration(node, initialEnvironment, createStatementTraversalStack());
            value = stack.pop();
        }
        else {
            throw new UnexpectedNodeError({ node, typescript });
        }
        logger.logResult(value);
        return {
            success: true,
            value
        };
    }
    catch (reason) {
        reportError(reporting, reason, node);
        return {
            success: false,
            reason
        };
    }
}
function evaluate ( { typeChecker , node , environment : { preset = exports . EnvironmentPresetKind . NODE , extra = { } } = { } , typescript = TSModule__namespace , logLevel = 0 , policy : { deterministic = false , network = false , console = false , maxOps = Infinity , maxOpDuration = Infinity , io = { read : true , write : false } , process = { exit : false , spawnChild : false } } = { } , reporting : reportingInput = { } } ) { const simpleLiteralResult = evaluateSimpleLiteral ( node , typescript ) ; if ( simpleLiteralResult . success ) return simpleLiteralResult ; const policy = { deterministic , maxOps , maxOpDuration , network , console , io : { read : typeof io === "boolean" ? io : io . read , write : typeof io === "boolean" ? io : io . write } , process : { exit : typeof process === "boolean" ? process : process . exit , spawnChild : typeof process === "boolean" ? process : process . spawnChild } } ; const reporting = Object . assign ( Object . assign ( { } , reportingInput ) , { reportedErrorSet : createReportedErrorSet ( ) } ) ; let currentNode = node ; const logger = new Logger ( logLevel ) ; const initialEnvironment = createLexicalEnvironment ( { inputEnvironment : { preset , extra } , policy , getCurrentNode : ( ) => currentNode } ) ; const stack = createStack ( ) ; const nodeEvaluator = createNodeEvaluator ( { policy , typeChecker , typescript , logger , stack , reporting : reporting , nextNode : nextNode => ( currentNode = nextNode ) } ) ; try { let value ; if ( isExpression ( node , typescript ) ) { value = nodeEvaluator . expression ( node , initialEnvironment , createStatementTraversalStack ( ) ) ; } else if ( isStatement ( node , typescript ) ) { nodeEvaluator . statement ( node , initialEnvironment ) ; value = stack . pop ( ) ; } else if ( isDeclaration ( node , typescript ) ) { nodeEvaluator . declaration ( node , initialEnvironment , createStatementTraversalStack ( ) ) ; value = stack . pop ( ) ; } else { throw new UnexpectedNodeError ( { node , typescript } ) ; } logger . logResult ( value ) ; return { success : true , value } ; } catch ( reason ) { reportError ( reporting , reason , node ) ; return { success : false , reason } ; } }
Will get a literal value for the given Expression, ExpressionStatement, or Declaration.
Will get a literal value for the given Expression ExpressionStatement or Declaration .
/* SILENT */ // Take the simple path first. This may be far more performant than building up an environment // Otherwise, build an environment and get to work // Sanitize the evaluation policy based on the input options // Sanitize the Reporting options based on the input options // Prepare a reference to the Node that is currently being evaluated // Prepare a logger // Prepare the initial environment // Prepare a Stack // Prepare a NodeEvaluator // Otherwise, throw an UnexpectedNodeError // noinspection ExceptionCaughtLocallyJS // Log the value before returning // Report the Error