hsp/compiler/jsgenerator/processors.js
function formatExpression (expression, firstIndex, walker) {
    var category = expression.category, codeStmts, code = '', nextIndex = firstIndex;
    var exprIndex = firstIndex;
    var expAst;

    if (category === 'jsexptext') {
        //compile the expression to detect errors and parse-out identifiers
        try {
            expAst = exParser(expression.value);
            exIdentifiers(expAst).forEach(function(ident){
                walker.addGlobalRef(ident);
            });
            codeStmts = ['e', exprIndex, ':[9,"',
                ('' + expression.value).replace(/"/g, "\\\"").replace(/\\\\"/g, "\\\""),
                '"'];
            if (expression.bound === false) {
                codeStmts.push(',false');
            }
            codeStmts.push(']');
            code = codeStmts.join('');
        } catch (err) {
            walker.logError("Invalid expression: '" + expression.value + "'", expression);
        }
        nextIndex++;
    } else {
        walker.logError("Unsupported expression: " + category, expression);
    }

    return {
        code : code,
        ast: expAst,
        exprIdx : exprIndex,
        nextIndex : nextIndex
    };
}
function formatExpression (expression, firstIndex, walker) {
    var category = expression.category, codeStmts, code = '', nextIndex = firstIndex;
    var exprIndex = firstIndex;
    var expAst;

    if (category === 'jsexptext') {
        //compile the expression to detect errors and parse-out identifiers
        try {
            expAst = exParser(expression.value);
            exIdentifiers(expAst).forEach(function(ident){
                walker.addGlobalRef(ident);
            });
            codeStmts = ['e', exprIndex, ':[9,"',
                ('' + expression.value).replace(/"/g, "\\\"").replace(/\\\\"/g, "\\\""),
                '"'];
            if (expression.bound === false) {
                codeStmts.push(',false');
            }
            codeStmts.push(']');
            code = codeStmts.join('');
        } catch (err) {
            walker.logError("Invalid expression: '" + expression.value + "'", expression);
        }
        nextIndex++;
    } else {
        walker.logError("Unsupported expression: " + category, expression);
    }

    return {
        code : code,
        ast: expAst,
        exprIdx : exprIndex,
        nextIndex : nextIndex
    };
}
function formatExpression ( expression , firstIndex , walker ) { var category = expression . category , codeStmts , code = '' , nextIndex = firstIndex ; var exprIndex = firstIndex ; var expAst ; if ( category === 'jsexptext' ) { //compile the expression to detect errors and parse-out identifiers try { expAst = exParser ( expression . value ) ; exIdentifiers ( expAst ) . forEach ( function ( ident ) { walker . addGlobalRef ( ident ) ; } ) ; codeStmts = [ 'e' , exprIndex , ':[9,"' , ( '' + expression . value ) . replace ( / " / g , "\\\"" ) . replace ( / \\\\" / g , "\\\"" ) , '"' ] ; if ( expression . bound === false ) { codeStmts . push ( ',false' ) ; } codeStmts . push ( ']' ) ; code = codeStmts . join ( '' ) ; } catch ( err ) { walker . logError ( "Invalid expression: '" + expression . value + "'" , expression ) ; } nextIndex ++ ; } else { walker . logError ( "Unsupported expression: " + category , expression ) ; } return { code : code , ast : expAst , exprIdx : exprIndex , nextIndex : nextIndex } ; }
Formats an expression according to its category.
@param {Object} expression the expression to format.
@param {Integer} firstIndex index of the expression.
@param {TemplateWalker} walker the template walker instance.
@return {Object} the expression string and the next expression index that can be used
Formats an expression according to its category .