react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / handlebars / dist / cjs / handlebars / compiler / helpers.js
80728 views"use strict";1var Exception = require("../exception")["default"];23function SourceLocation(source, locInfo) {4this.source = source;5this.start = {6line: locInfo.first_line,7column: locInfo.first_column8};9this.end = {10line: locInfo.last_line,11column: locInfo.last_column12};13}1415exports.SourceLocation = SourceLocation;function stripFlags(open, close) {16return {17open: open.charAt(2) === '~',18close: close.charAt(close.length-3) === '~'19};20}2122exports.stripFlags = stripFlags;function stripComment(comment) {23return comment.replace(/^\{\{~?\!-?-?/, '')24.replace(/-?-?~?\}\}$/, '');25}2627exports.stripComment = stripComment;function preparePath(data, parts, locInfo) {28/*jshint -W040 */29locInfo = this.locInfo(locInfo);3031var original = data ? '@' : '',32dig = [],33depth = 0,34depthString = '';3536for(var i=0,l=parts.length; i<l; i++) {37var part = parts[i].part;38original += (parts[i].separator || '') + part;3940if (part === '..' || part === '.' || part === 'this') {41if (dig.length > 0) {42throw new Exception('Invalid path: ' + original, {loc: locInfo});43} else if (part === '..') {44depth++;45depthString += '../';46}47} else {48dig.push(part);49}50}5152return new this.PathExpression(data, depth, dig, original, locInfo);53}5455exports.preparePath = preparePath;function prepareMustache(path, params, hash, open, strip, locInfo) {56/*jshint -W040 */57// Must use charAt to support IE pre-1058var escapeFlag = open.charAt(3) || open.charAt(2),59escaped = escapeFlag !== '{' && escapeFlag !== '&';6061return new this.MustacheStatement(path, params, hash, escaped, strip, this.locInfo(locInfo));62}6364exports.prepareMustache = prepareMustache;function prepareRawBlock(openRawBlock, content, close, locInfo) {65/*jshint -W040 */66if (openRawBlock.path.original !== close) {67var errorNode = {loc: openRawBlock.path.loc};6869throw new Exception(openRawBlock.path.original + " doesn't match " + close, errorNode);70}7172locInfo = this.locInfo(locInfo);73var program = new this.Program([content], null, {}, locInfo);7475return new this.BlockStatement(76openRawBlock.path, openRawBlock.params, openRawBlock.hash,77program, undefined,78{}, {}, {},79locInfo);80}8182exports.prepareRawBlock = prepareRawBlock;function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) {83/*jshint -W040 */84// When we are chaining inverse calls, we will not have a close path85if (close && close.path && openBlock.path.original !== close.path.original) {86var errorNode = {loc: openBlock.path.loc};8788throw new Exception(openBlock.path.original + ' doesn\'t match ' + close.path.original, errorNode);89}9091program.blockParams = openBlock.blockParams;9293var inverse,94inverseStrip;9596if (inverseAndProgram) {97if (inverseAndProgram.chain) {98inverseAndProgram.program.body[0].closeStrip = close.strip;99}100101inverseStrip = inverseAndProgram.strip;102inverse = inverseAndProgram.program;103}104105if (inverted) {106inverted = inverse;107inverse = program;108program = inverted;109}110111return new this.BlockStatement(112openBlock.path, openBlock.params, openBlock.hash,113program, inverse,114openBlock.strip, inverseStrip, close && close.strip,115this.locInfo(locInfo));116}117118exports.prepareBlock = prepareBlock;119120