hsp/compiler/jsgenerator/index.js
function _generateLineMap (res, file) {
    if (res.errors && res.errors.length) {
        return;
    }
    var syntaxTree = res.syntaxTree, templates = [];
    // identify the templates in the syntax tree
    for (var i = 0; i < syntaxTree.length; i++) {
        if (syntaxTree[i].type === 'template') {
            templates.push(syntaxTree[i]);
        }
    }

    var nbrOfLinesInCompiledTemplate = 5; //all generated templates got fixed no of LOC
    var lineMap = [], pos = HEADER_SZ, template;
    var pos1 = -1; // position of the next template start
    var pos2 = -1; // position of the next template end
    var tplIdx = -1; // position of the current template

    for (var i = 0; i < (file.split(/\n/g).length + 1); i++) {
        if (i === 0 || i === pos2) {
            // end of current template: let's determine next pos1 and pos2
            tplIdx = (i === 0) ? 0 : tplIdx + 1;
            if (tplIdx < templates.length) {
                // there is another template
                template = templates[tplIdx];
                pos1 = template.startLine;
                pos2 = Math.max(template.endLine, pos1);
            } else {
                // last template has been found
                tplIdx = pos1 = pos2 = -1;
            }
            if (i === 0) {
                lineMap[0] = 0;
            }
            i++;
        }
        if (i === pos1) {
            for (var j = pos1; j < (pos2 + 1); j++) {
                // all lines are set to the template start
                lineMap[i] = pos;
                i++;
            }
            pos += nbrOfLinesInCompiledTemplate;
            i -= 2; // to enter the i===pos2 clause at next step
        } else {
            lineMap[i] = pos;
            pos++;
        }
    }
    return lineMap;
}
function _generateLineMap (res, file) {
    if (res.errors && res.errors.length) {
        return;
    }
    var syntaxTree = res.syntaxTree, templates = [];
    // identify the templates in the syntax tree
    for (var i = 0; i < syntaxTree.length; i++) {
        if (syntaxTree[i].type === 'template') {
            templates.push(syntaxTree[i]);
        }
    }

    var nbrOfLinesInCompiledTemplate = 5; //all generated templates got fixed no of LOC
    var lineMap = [], pos = HEADER_SZ, template;
    var pos1 = -1; // position of the next template start
    var pos2 = -1; // position of the next template end
    var tplIdx = -1; // position of the current template

    for (var i = 0; i < (file.split(/\n/g).length + 1); i++) {
        if (i === 0 || i === pos2) {
            // end of current template: let's determine next pos1 and pos2
            tplIdx = (i === 0) ? 0 : tplIdx + 1;
            if (tplIdx < templates.length) {
                // there is another template
                template = templates[tplIdx];
                pos1 = template.startLine;
                pos2 = Math.max(template.endLine, pos1);
            } else {
                // last template has been found
                tplIdx = pos1 = pos2 = -1;
            }
            if (i === 0) {
                lineMap[0] = 0;
            }
            i++;
        }
        if (i === pos1) {
            for (var j = pos1; j < (pos2 + 1); j++) {
                // all lines are set to the template start
                lineMap[i] = pos;
                i++;
            }
            pos += nbrOfLinesInCompiledTemplate;
            i -= 2; // to enter the i===pos2 clause at next step
        } else {
            lineMap[i] = pos;
            pos++;
        }
    }
    return lineMap;
}
function _generateLineMap ( res , file ) { if ( res . errors && res . errors . length ) { return ; } var syntaxTree = res . syntaxTree , templates = [ ] ; // identify the templates in the syntax tree for ( var i = 0 ; i < syntaxTree . length ; i ++ ) { if ( syntaxTree [ i ] . type === 'template' ) { templates . push ( syntaxTree [ i ] ) ; } } var nbrOfLinesInCompiledTemplate = 5 ; //all generated templates got fixed no of LOC var lineMap = [ ] , pos = HEADER_SZ , template ; var pos1 = - 1 ; // position of the next template start var pos2 = - 1 ; // position of the next template end var tplIdx = - 1 ; // position of the current template for ( var i = 0 ; i < ( file . split ( / \n / g ) . length + 1 ) ; i ++ ) { if ( i === 0 || i === pos2 ) { // end of current template: let's determine next pos1 and pos2 tplIdx = ( i === 0 ) ? 0 : tplIdx + 1 ; if ( tplIdx < templates . length ) { // there is another template template = templates [ tplIdx ] ; pos1 = template . startLine ; pos2 = Math . max ( template . endLine , pos1 ) ; } else { // last template has been found tplIdx = pos1 = pos2 = - 1 ; } if ( i === 0 ) { lineMap [ 0 ] = 0 ; } i ++ ; } if ( i === pos1 ) { for ( var j = pos1 ; j < ( pos2 + 1 ) ; j ++ ) { // all lines are set to the template start lineMap [ i ] = pos ; i ++ ; } pos += nbrOfLinesInCompiledTemplate ; i -= 2 ; // to enter the i===pos2 clause at next step } else { lineMap [ i ] = pos ; pos ++ ; } } return lineMap ; }
Generate the line map of a compilatin result
@param {JSON} res the result object of a compilation - cf. compile function
@param {String} file the template file (before compilation)
Generate the line map of a compilatin result