tools/ast_passes.js
function( src, fileName ) {
        var ast = parse(src, fileName);
        walk.simple(ast, {
            ExpressionStatement: function( node ) {
                if( node.expression.type !== 'CallExpression' ) {
                    return;
                }

                var start = node.start;
                var end = node.end;
                node = node.expression;
                var callee = node.callee;
                if( callee.name === "CONSTANT" &&
                    callee.type === "Identifier" ) {

                    if( node.arguments.length !== 2 ) {
                        throw new Error( "Exactly 2 arguments must be passed to CONSTANT\n" +
                            src.substring(start, end)
                        );
                    }

                    if( node.arguments[0].type !== "Identifier" ) {
                        throw new Error( "Can only define identifier as a constant\n" +
                            src.substring(start, end)
                        );
                    }

                    var args = node.arguments;

                    var name = args[0];
                    var nameStr = name.name;
                    var expr = args[1];

                    var e = eval;
                    constants[nameStr] = {
                        identifier: name,
                        value: e(nodeToString(expr))
                    };
                    walk.simple( expr, {
                        Identifier: function( node ) {
                            ignore.push(node);
                        }
                    });
                    global[nameStr] = constants[nameStr].value;
                }
            }
        });
    }
function( src, fileName ) {
        var ast = parse(src, fileName);
        walk.simple(ast, {
            ExpressionStatement: function( node ) {
                if( node.expression.type !== 'CallExpression' ) {
                    return;
                }

                var start = node.start;
                var end = node.end;
                node = node.expression;
                var callee = node.callee;
                if( callee.name === "CONSTANT" &&
                    callee.type === "Identifier" ) {

                    if( node.arguments.length !== 2 ) {
                        throw new Error( "Exactly 2 arguments must be passed to CONSTANT\n" +
                            src.substring(start, end)
                        );
                    }

                    if( node.arguments[0].type !== "Identifier" ) {
                        throw new Error( "Can only define identifier as a constant\n" +
                            src.substring(start, end)
                        );
                    }

                    var args = node.arguments;

                    var name = args[0];
                    var nameStr = name.name;
                    var expr = args[1];

                    var e = eval;
                    constants[nameStr] = {
                        identifier: name,
                        value: e(nodeToString(expr))
                    };
                    walk.simple( expr, {
                        Identifier: function( node ) {
                            ignore.push(node);
                        }
                    });
                    global[nameStr] = constants[nameStr].value;
                }
            }
        });
    }
function ( src , fileName ) { var ast = parse ( src , fileName ) ; walk . simple ( ast , { ExpressionStatement : function ( node ) { if ( node . expression . type !== 'CallExpression' ) { return ; } var start = node . start ; var end = node . end ; node = node . expression ; var callee = node . callee ; if ( callee . name === "CONSTANT" && callee . type === "Identifier" ) { if ( node . arguments . length !== 2 ) { throw new Error ( "Exactly 2 arguments must be passed to CONSTANT\n" + src . substring ( start , end ) ) ; } if ( node . arguments [ 0 ] . type !== "Identifier" ) { throw new Error ( "Can only define identifier as a constant\n" + src . substring ( start , end ) ) ; } var args = node . arguments ; var name = args [ 0 ] ; var nameStr = name . name ; var expr = args [ 1 ] ; var e = eval ; constants [ nameStr ] = { identifier : name , value : e ( nodeToString ( expr ) ) } ; walk . simple ( expr , { Identifier : function ( node ) { ignore . push ( node ) ; } } ) ; global [ nameStr ] = constants [ nameStr ] . value ; } } } ) ; }
Parse constants in from constants.js
Parse constants in from constants . js