src/mustacheparser.js
function handleText(text, isAttr) {
		let match, result = '', lastIndex = 0;
		let cat = isAttr ? ' + ' : ', ';
		if (!text.match(syntax)) {
			return result += "'" + text.substr(lastIndex).replace(/\n/g, '').replace(/'/g, '\\\'') + "'" + cat;
		}
		// locate mustache syntax within the text
		while (match = syntax.exec(text)) {
			if (match.index < lastIndex) continue;
			let frag = text.substring(lastIndex, match.index).replace(/^\s+/g, '');
			if (frag.length > 0) {
				result += "'" + frag.replace(/\n/g, '').replace(/'/g, '\\\'') + "'" + cat;
			}
			lastIndex = match.index + match[0].length;
			let key = match[1];
			// of "{{#test}}" value will be "test"
			let value = key.substr(1);
			if (key[0] === '#') {
				// handle block start
				result += `spread(toArray(${getData()}, '${value}').map(function (e, i, a) {
						var data$${level + 1} = merge({}, data${0 >= level ? '' : '$' + level}, {'.': e, '.index': i, '.length': a.length}, e);
						return [].concat(`;
				level += 1;
				usesMerge = true;
				usesSpread = true;
			} else if (key[0] === '/') {
				// handle block end
				result += '\'\'); }))' + (isAttr ? '.join("")' : '') + cat;
				level -= 1;
				if (level < 0) {
					throw new Error('Unexpected end of block: ' + key.substr(1));
				}
			} else if (key[0] === '^') {
				// handle inverted block start
				result += `(safeAccess(${getData()}, '${value}') && (typeof safeAccess(${getData()}, '${value}') === 'boolean' || safeAccess(${getData()}, '${value}').length > 0)) ? '' : spread([1].map(function() { var data$${level + 1} = merge({}, data${0 >= level ? '' : '$' + level}); return [].concat(`;
				usesMerge = true;
				usesSpread = true;
				level += 1;
			} else if (key[0] === '%') {
				// handle style rendering "{{%myvar}}" - only to be used for attribute values!
				result += key.substr(1).split(/\s*,\s*/).map(value => `renderStyle(safeAccess(${getData()}, '${value}'), ${getData()})`).join(' + ');
				usesRenderStyle = true;
			} else if (key[0] === '+') {
				// handle deep data transfer "{{+myvar}}"
				result += `safeAccess(${getData()}, '${value}')${cat}`;
			} else if (key[0] !== '{' && key[0] !== '!') {
				// handle non-escaping prints "{{{myvar}}}"
				value = key;
				result += `''+safeAccess(${getData()}, '${value}', true)${cat}`
			} else if (key[0] !== '!') {
				// regular prints "{{myvar}}"
				result += `''+safeAccess(${getData()}, '${value}')${cat}`;
			} // ignore comments
		}
		if (text.substr(lastIndex).length > 0) {
			result += "'" + text.substr(lastIndex).replace(/\n/g, '').replace(/'/g, '\\\'') + "'" + cat;
		}
		return result;
	}
function handleText(text, isAttr) {
		let match, result = '', lastIndex = 0;
		let cat = isAttr ? ' + ' : ', ';
		if (!text.match(syntax)) {
			return result += "'" + text.substr(lastIndex).replace(/\n/g, '').replace(/'/g, '\\\'') + "'" + cat;
		}
		// locate mustache syntax within the text
		while (match = syntax.exec(text)) {
			if (match.index < lastIndex) continue;
			let frag = text.substring(lastIndex, match.index).replace(/^\s+/g, '');
			if (frag.length > 0) {
				result += "'" + frag.replace(/\n/g, '').replace(/'/g, '\\\'') + "'" + cat;
			}
			lastIndex = match.index + match[0].length;
			let key = match[1];
			// of "{{#test}}" value will be "test"
			let value = key.substr(1);
			if (key[0] === '#') {
				// handle block start
				result += `spread(toArray(${getData()}, '${value}').map(function (e, i, a) {
						var data$${level + 1} = merge({}, data${0 >= level ? '' : '$' + level}, {'.': e, '.index': i, '.length': a.length}, e);
						return [].concat(`;
				level += 1;
				usesMerge = true;
				usesSpread = true;
			} else if (key[0] === '/') {
				// handle block end
				result += '\'\'); }))' + (isAttr ? '.join("")' : '') + cat;
				level -= 1;
				if (level < 0) {
					throw new Error('Unexpected end of block: ' + key.substr(1));
				}
			} else if (key[0] === '^') {
				// handle inverted block start
				result += `(safeAccess(${getData()}, '${value}') && (typeof safeAccess(${getData()}, '${value}') === 'boolean' || safeAccess(${getData()}, '${value}').length > 0)) ? '' : spread([1].map(function() { var data$${level + 1} = merge({}, data${0 >= level ? '' : '$' + level}); return [].concat(`;
				usesMerge = true;
				usesSpread = true;
				level += 1;
			} else if (key[0] === '%') {
				// handle style rendering "{{%myvar}}" - only to be used for attribute values!
				result += key.substr(1).split(/\s*,\s*/).map(value => `renderStyle(safeAccess(${getData()}, '${value}'), ${getData()})`).join(' + ');
				usesRenderStyle = true;
			} else if (key[0] === '+') {
				// handle deep data transfer "{{+myvar}}"
				result += `safeAccess(${getData()}, '${value}')${cat}`;
			} else if (key[0] !== '{' && key[0] !== '!') {
				// handle non-escaping prints "{{{myvar}}}"
				value = key;
				result += `''+safeAccess(${getData()}, '${value}', true)${cat}`
			} else if (key[0] !== '!') {
				// regular prints "{{myvar}}"
				result += `''+safeAccess(${getData()}, '${value}')${cat}`;
			} // ignore comments
		}
		if (text.substr(lastIndex).length > 0) {
			result += "'" + text.substr(lastIndex).replace(/\n/g, '').replace(/'/g, '\\\'') + "'" + cat;
		}
		return result;
	}
function handleText ( text , isAttr ) { let match , result = '' , lastIndex = 0 ; let cat = isAttr ? ' + ' : ', ' ; if ( ! text . match ( syntax ) ) { return result += "'" + text . substr ( lastIndex ) . replace ( / \n / g , '' ) . replace ( / ' / g , '\\\'' ) + "'" + cat ; } // locate mustache syntax within the text while ( match = syntax . exec ( text ) ) { if ( match . index < lastIndex ) continue ; let frag = text . substring ( lastIndex , match . index ) . replace ( / ^\s+ / g , '' ) ; if ( frag . length > 0 ) { result += "'" + frag . replace ( / \n / g , '' ) . replace ( / ' / g , '\\\'' ) + "'" + cat ; } lastIndex = match . index + match [ 0 ] . length ; let key = match [ 1 ] ; // of "{{#test}}" value will be "test" let value = key . substr ( 1 ) ; if ( key [ 0 ] === '#' ) { // handle block start result += ` ${ getData ( ) } ${ value } ${ level + 1 } ${ 0 >= level ? '' : '$' + level } ` ; level += 1 ; usesMerge = true ; usesSpread = true ; } else if ( key [ 0 ] === '/' ) { // handle block end result += '\'\'); }))' + ( isAttr ? '.join("")' : '' ) + cat ; level -= 1 ; if ( level < 0 ) { throw new Error ( 'Unexpected end of block: ' + key . substr ( 1 ) ) ; } } else if ( key [ 0 ] === '^' ) { // handle inverted block start result += ` ${ getData ( ) } ${ value } ${ getData ( ) } ${ value } ${ getData ( ) } ${ value } ${ level + 1 } ${ 0 >= level ? '' : '$' + level } ` ; usesMerge = true ; usesSpread = true ; level += 1 ; } else if ( key [ 0 ] === '%' ) { // handle style rendering "{{%myvar}}" - only to be used for attribute values! result += key . substr ( 1 ) . split ( / \s*,\s* / ) . map ( value => ` ${ getData ( ) } ${ value } ${ getData ( ) } ` ) . join ( ' + ' ) ; usesRenderStyle = true ; } else if ( key [ 0 ] === '+' ) { // handle deep data transfer "{{+myvar}}" result += ` ${ getData ( ) } ${ value } ${ cat } ` ; } else if ( key [ 0 ] !== '{' && key [ 0 ] !== '!' ) { // handle non-escaping prints "{{{myvar}}}" value = key ; result += ` ${ getData ( ) } ${ value } ${ cat } ` } else if ( key [ 0 ] !== '!' ) { // regular prints "{{myvar}}" result += ` ${ getData ( ) } ${ value } ${ cat } ` ; } // ignore comments } if ( text . substr ( lastIndex ) . length > 0 ) { result += "'" + text . substr ( lastIndex ) . replace ( / \n / g , '' ) . replace ( / ' / g , '\\\'' ) + "'" + cat ; } return result ; }
text is the only place where mustache code can be found
text is the only place where mustache code can be found