react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / handlebars / lib / handlebars / compiler / helpers.js
80713 viewsimport Exception from "../exception";12export function SourceLocation(source, locInfo) {3this.source = source;4this.start = {5line: locInfo.first_line,6column: locInfo.first_column7};8this.end = {9line: locInfo.last_line,10column: locInfo.last_column11};12}1314export function stripFlags(open, close) {15return {16open: open.charAt(2) === '~',17close: close.charAt(close.length-3) === '~'18};19}2021export function stripComment(comment) {22return comment.replace(/^\{\{~?\!-?-?/, '')23.replace(/-?-?~?\}\}$/, '');24}2526export function preparePath(data, parts, locInfo) {27/*jshint -W040 */28locInfo = this.locInfo(locInfo);2930var original = data ? '@' : '',31dig = [],32depth = 0,33depthString = '';3435for(var i=0,l=parts.length; i<l; i++) {36var part = parts[i].part;37original += (parts[i].separator || '') + part;3839if (part === '..' || part === '.' || part === 'this') {40if (dig.length > 0) {41throw new Exception('Invalid path: ' + original, {loc: locInfo});42} else if (part === '..') {43depth++;44depthString += '../';45}46} else {47dig.push(part);48}49}5051return new this.PathExpression(data, depth, dig, original, locInfo);52}5354export function prepareMustache(path, params, hash, open, strip, locInfo) {55/*jshint -W040 */56// Must use charAt to support IE pre-1057var escapeFlag = open.charAt(3) || open.charAt(2),58escaped = escapeFlag !== '{' && escapeFlag !== '&';5960return new this.MustacheStatement(path, params, hash, escaped, strip, this.locInfo(locInfo));61}6263export function prepareRawBlock(openRawBlock, content, close, locInfo) {64/*jshint -W040 */65if (openRawBlock.path.original !== close) {66var errorNode = {loc: openRawBlock.path.loc};6768throw new Exception(openRawBlock.path.original + " doesn't match " + close, errorNode);69}7071locInfo = this.locInfo(locInfo);72var program = new this.Program([content], null, {}, locInfo);7374return new this.BlockStatement(75openRawBlock.path, openRawBlock.params, openRawBlock.hash,76program, undefined,77{}, {}, {},78locInfo);79}8081export function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) {82/*jshint -W040 */83// When we are chaining inverse calls, we will not have a close path84if (close && close.path && openBlock.path.original !== close.path.original) {85var errorNode = {loc: openBlock.path.loc};8687throw new Exception(openBlock.path.original + ' doesn\'t match ' + close.path.original, errorNode);88}8990program.blockParams = openBlock.blockParams;9192var inverse,93inverseStrip;9495if (inverseAndProgram) {96if (inverseAndProgram.chain) {97inverseAndProgram.program.body[0].closeStrip = close.strip;98}99100inverseStrip = inverseAndProgram.strip;101inverse = inverseAndProgram.program;102}103104if (inverted) {105inverted = inverse;106inverse = program;107program = inverted;108}109110return new this.BlockStatement(111openBlock.path, openBlock.params, openBlock.hash,112program, inverse,113openBlock.strip, inverseStrip, close && close.strip,114this.locInfo(locInfo));115}116117118