import remapVars = require ( './remap-vars' ) ; /**
 * Matches line-ending of win, mac, and unix type
 */ const EOLS = /[^\r\n]+/g ; /**
 * Helper class for the `parseChunks` function.
 */ class ParseHelper { private lastPos = 0 ; private output = true ; param source param props constructor ( private source , private props ) { } /**
     * Final flush. The final output is always in "active" state.
     */ public flush ( ) { return this . commit ( this . lastPos , this . source . length ) ; } param offset public flushPrev ( offset ) { if ( this . output ) { this . commit ( this . lastPos , offset ) ; } } param start param end param output returns public flushLine ( start , end , output ) { if ( end < this . source . length ) { end += this . source . substr ( end , 2 ) === '\r\n' ? 2 : 1 ; } if ( output !== this . output ) { this . output = output ; this . flushit ( start , end ) ; } else if ( output ) { this . remove ( start , end ) ; } return end ; } param start param end returns private commit ( start , end ) { if ( start >= end ) { return false ; } this . lastPos = end ; const chunk = this . source . slice ( start , end ) ; return chunk . indexOf ( '$_' ) > - 1 && remapVars ( this . props , chunk , start ) ; } param start param end returns private remove ( start , end ) { this . lastPos = end ; const block = this . props . keepLines ? this . source . slice ( start , end ) . replace ( EOLS , '' ) : '' ; this . props . magicStr . overwrite ( start , end , block ) ; } param start param end private flushit ( start , end ) { if ( this . output ) { this . remove ( this . lastPos , end ) ; } else { this . commit ( this . lastPos , start ) ; } } } export = ParseHelper ;