react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / handlebars / dist / handlebars.runtime.js
80684 views/*!12handlebars v3.0.034Copyright (C) 2011-2014 by Yehuda Katz56Permission is hereby granted, free of charge, to any person obtaining a copy7of this software and associated documentation files (the "Software"), to deal8in the Software without restriction, including without limitation the rights9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10copies of the Software, and to permit persons to whom the Software is11furnished to do so, subject to the following conditions:1213The above copyright notice and this permission notice shall be included in14all copies or substantial portions of the Software.1516THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.2324@license25*/26/* exported Handlebars */27(function (root, factory) {28if (typeof define === 'function' && define.amd) {29define([], factory);30} else if (typeof exports === 'object') {31module.exports = factory();32} else {33root.Handlebars = factory();34}35}(this, function () {36// handlebars/utils.js37var __module2__ = (function() {38"use strict";39var __exports__ = {};40/*jshint -W004 */41var escape = {42"&": "&",43"<": "<",44">": ">",45'"': """,46"'": "'",47"`": "`"48};4950var badChars = /[&<>"'`]/g;51var possible = /[&<>"'`]/;5253function escapeChar(chr) {54return escape[chr];55}5657function extend(obj /* , ...source */) {58for (var i = 1; i < arguments.length; i++) {59for (var key in arguments[i]) {60if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {61obj[key] = arguments[i][key];62}63}64}6566return obj;67}6869__exports__.extend = extend;var toString = Object.prototype.toString;70__exports__.toString = toString;71// Sourced from lodash72// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt73var isFunction = function(value) {74return typeof value === 'function';75};76// fallback for older versions of Chrome and Safari77/* istanbul ignore next */78if (isFunction(/x/)) {79isFunction = function(value) {80return typeof value === 'function' && toString.call(value) === '[object Function]';81};82}83var isFunction;84__exports__.isFunction = isFunction;85/* istanbul ignore next */86var isArray = Array.isArray || function(value) {87return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;88};89__exports__.isArray = isArray;90// Older IE versions do not directly support indexOf so we must implement our own, sadly.91function indexOf(array, value) {92for (var i = 0, len = array.length; i < len; i++) {93if (array[i] === value) {94return i;95}96}97return -1;98}99100__exports__.indexOf = indexOf;101function escapeExpression(string) {102// don't escape SafeStrings, since they're already safe103if (string && string.toHTML) {104return string.toHTML();105} else if (string == null) {106return "";107} else if (!string) {108return string + '';109}110111// Force a string conversion as this will be done by the append regardless and112// the regex test will do this transparently behind the scenes, causing issues if113// an object's to string has escaped characters in it.114string = "" + string;115116if(!possible.test(string)) { return string; }117return string.replace(badChars, escapeChar);118}119120__exports__.escapeExpression = escapeExpression;function isEmpty(value) {121if (!value && value !== 0) {122return true;123} else if (isArray(value) && value.length === 0) {124return true;125} else {126return false;127}128}129130__exports__.isEmpty = isEmpty;function blockParams(params, ids) {131params.path = ids;132return params;133}134135__exports__.blockParams = blockParams;function appendContextPath(contextPath, id) {136return (contextPath ? contextPath + '.' : '') + id;137}138139__exports__.appendContextPath = appendContextPath;140return __exports__;141})();142143// handlebars/exception.js144var __module3__ = (function() {145"use strict";146var __exports__;147148var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];149150function Exception(message, node) {151var loc = node && node.loc,152line,153column;154if (loc) {155line = loc.start.line;156column = loc.start.column;157158message += ' - ' + line + ':' + column;159}160161var tmp = Error.prototype.constructor.call(this, message);162163// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.164for (var idx = 0; idx < errorProps.length; idx++) {165this[errorProps[idx]] = tmp[errorProps[idx]];166}167168if (loc) {169this.lineNumber = line;170this.column = column;171}172}173174Exception.prototype = new Error();175176__exports__ = Exception;177return __exports__;178})();179180// handlebars/base.js181var __module1__ = (function(__dependency1__, __dependency2__) {182"use strict";183var __exports__ = {};184var Utils = __dependency1__;185var Exception = __dependency2__;186187var VERSION = "3.0.0";188__exports__.VERSION = VERSION;var COMPILER_REVISION = 6;189__exports__.COMPILER_REVISION = COMPILER_REVISION;190var REVISION_CHANGES = {1911: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it1922: '== 1.0.0-rc.3',1933: '== 1.0.0-rc.4',1944: '== 1.x.x',1955: '== 2.0.0-alpha.x',1966: '>= 2.0.0-beta.1'197};198__exports__.REVISION_CHANGES = REVISION_CHANGES;199var isArray = Utils.isArray,200isFunction = Utils.isFunction,201toString = Utils.toString,202objectType = '[object Object]';203204function HandlebarsEnvironment(helpers, partials) {205this.helpers = helpers || {};206this.partials = partials || {};207208registerDefaultHelpers(this);209}210211__exports__.HandlebarsEnvironment = HandlebarsEnvironment;HandlebarsEnvironment.prototype = {212constructor: HandlebarsEnvironment,213214logger: logger,215log: log,216217registerHelper: function(name, fn) {218if (toString.call(name) === objectType) {219if (fn) { throw new Exception('Arg not supported with multiple helpers'); }220Utils.extend(this.helpers, name);221} else {222this.helpers[name] = fn;223}224},225unregisterHelper: function(name) {226delete this.helpers[name];227},228229registerPartial: function(name, partial) {230if (toString.call(name) === objectType) {231Utils.extend(this.partials, name);232} else {233if (typeof partial === 'undefined') {234throw new Exception('Attempting to register a partial as undefined');235}236this.partials[name] = partial;237}238},239unregisterPartial: function(name) {240delete this.partials[name];241}242};243244function registerDefaultHelpers(instance) {245instance.registerHelper('helperMissing', function(/* [args, ]options */) {246if(arguments.length === 1) {247// A missing field in a {{foo}} constuct.248return undefined;249} else {250// Someone is actually trying to call something, blow up.251throw new Exception("Missing helper: '" + arguments[arguments.length-1].name + "'");252}253});254255instance.registerHelper('blockHelperMissing', function(context, options) {256var inverse = options.inverse,257fn = options.fn;258259if(context === true) {260return fn(this);261} else if(context === false || context == null) {262return inverse(this);263} else if (isArray(context)) {264if(context.length > 0) {265if (options.ids) {266options.ids = [options.name];267}268269return instance.helpers.each(context, options);270} else {271return inverse(this);272}273} else {274if (options.data && options.ids) {275var data = createFrame(options.data);276data.contextPath = Utils.appendContextPath(options.data.contextPath, options.name);277options = {data: data};278}279280return fn(context, options);281}282});283284instance.registerHelper('each', function(context, options) {285if (!options) {286throw new Exception('Must pass iterator to #each');287}288289var fn = options.fn, inverse = options.inverse;290var i = 0, ret = "", data;291292var contextPath;293if (options.data && options.ids) {294contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.';295}296297if (isFunction(context)) { context = context.call(this); }298299if (options.data) {300data = createFrame(options.data);301}302303function execIteration(key, i, last) {304if (data) {305data.key = key;306data.index = i;307data.first = i === 0;308data.last = !!last;309310if (contextPath) {311data.contextPath = contextPath + key;312}313}314315ret = ret + fn(context[key], {316data: data,317blockParams: Utils.blockParams([context[key], key], [contextPath + key, null])318});319}320321if(context && typeof context === 'object') {322if (isArray(context)) {323for(var j = context.length; i<j; i++) {324execIteration(i, i, i === context.length-1);325}326} else {327var priorKey;328329for(var key in context) {330if(context.hasOwnProperty(key)) {331// We're running the iterations one step out of sync so we can detect332// the last iteration without have to scan the object twice and create333// an itermediate keys array.334if (priorKey) {335execIteration(priorKey, i-1);336}337priorKey = key;338i++;339}340}341if (priorKey) {342execIteration(priorKey, i-1, true);343}344}345}346347if(i === 0){348ret = inverse(this);349}350351return ret;352});353354instance.registerHelper('if', function(conditional, options) {355if (isFunction(conditional)) { conditional = conditional.call(this); }356357// Default behavior is to render the positive path if the value is truthy and not empty.358// The `includeZero` option may be set to treat the condtional as purely not empty based on the359// behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.360if ((!options.hash.includeZero && !conditional) || Utils.isEmpty(conditional)) {361return options.inverse(this);362} else {363return options.fn(this);364}365});366367instance.registerHelper('unless', function(conditional, options) {368return instance.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn, hash: options.hash});369});370371instance.registerHelper('with', function(context, options) {372if (isFunction(context)) { context = context.call(this); }373374var fn = options.fn;375376if (!Utils.isEmpty(context)) {377if (options.data && options.ids) {378var data = createFrame(options.data);379data.contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]);380options = {data:data};381}382383return fn(context, options);384} else {385return options.inverse(this);386}387});388389instance.registerHelper('log', function(message, options) {390var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;391instance.log(level, message);392});393394instance.registerHelper('lookup', function(obj, field) {395return obj && obj[field];396});397}398399var logger = {400methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },401402// State enum403DEBUG: 0,404INFO: 1,405WARN: 2,406ERROR: 3,407level: 1,408409// Can be overridden in the host environment410log: function(level, message) {411if (typeof console !== 'undefined' && logger.level <= level) {412var method = logger.methodMap[level];413(console[method] || console.log).call(console, message);414}415}416};417__exports__.logger = logger;418var log = logger.log;419__exports__.log = log;420var createFrame = function(object) {421var frame = Utils.extend({}, object);422frame._parent = object;423return frame;424};425__exports__.createFrame = createFrame;426return __exports__;427})(__module2__, __module3__);428429// handlebars/safe-string.js430var __module4__ = (function() {431"use strict";432var __exports__;433// Build out our basic SafeString type434function SafeString(string) {435this.string = string;436}437438SafeString.prototype.toString = SafeString.prototype.toHTML = function() {439return "" + this.string;440};441442__exports__ = SafeString;443return __exports__;444})();445446// handlebars/runtime.js447var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) {448"use strict";449var __exports__ = {};450var Utils = __dependency1__;451var Exception = __dependency2__;452var COMPILER_REVISION = __dependency3__.COMPILER_REVISION;453var REVISION_CHANGES = __dependency3__.REVISION_CHANGES;454var createFrame = __dependency3__.createFrame;455456function checkRevision(compilerInfo) {457var compilerRevision = compilerInfo && compilerInfo[0] || 1,458currentRevision = COMPILER_REVISION;459460if (compilerRevision !== currentRevision) {461if (compilerRevision < currentRevision) {462var runtimeVersions = REVISION_CHANGES[currentRevision],463compilerVersions = REVISION_CHANGES[compilerRevision];464throw new Exception("Template was precompiled with an older version of Handlebars than the current runtime. "+465"Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").");466} else {467// Use the embedded version info since the runtime doesn't know about this revision yet468throw new Exception("Template was precompiled with a newer version of Handlebars than the current runtime. "+469"Please update your runtime to a newer version ("+compilerInfo[1]+").");470}471}472}473474__exports__.checkRevision = checkRevision;// TODO: Remove this line and break up compilePartial475476function template(templateSpec, env) {477/* istanbul ignore next */478if (!env) {479throw new Exception("No environment passed to template");480}481if (!templateSpec || !templateSpec.main) {482throw new Exception('Unknown template object: ' + typeof templateSpec);483}484485// Note: Using env.VM references rather than local var references throughout this section to allow486// for external users to override these as psuedo-supported APIs.487env.VM.checkRevision(templateSpec.compiler);488489var invokePartialWrapper = function(partial, context, options) {490if (options.hash) {491context = Utils.extend({}, context, options.hash);492}493494partial = env.VM.resolvePartial.call(this, partial, context, options);495var result = env.VM.invokePartial.call(this, partial, context, options);496497if (result == null && env.compile) {498options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);499result = options.partials[options.name](context, options);500}501if (result != null) {502if (options.indent) {503var lines = result.split('\n');504for (var i = 0, l = lines.length; i < l; i++) {505if (!lines[i] && i + 1 === l) {506break;507}508509lines[i] = options.indent + lines[i];510}511result = lines.join('\n');512}513return result;514} else {515throw new Exception("The partial " + options.name + " could not be compiled when running in runtime-only mode");516}517};518519// Just add water520var container = {521strict: function(obj, name) {522if (!(name in obj)) {523throw new Exception('"' + name + '" not defined in ' + obj);524}525return obj[name];526},527lookup: function(depths, name) {528var len = depths.length;529for (var i = 0; i < len; i++) {530if (depths[i] && depths[i][name] != null) {531return depths[i][name];532}533}534},535lambda: function(current, context) {536return typeof current === 'function' ? current.call(context) : current;537},538539escapeExpression: Utils.escapeExpression,540invokePartial: invokePartialWrapper,541542fn: function(i) {543return templateSpec[i];544},545546programs: [],547program: function(i, data, declaredBlockParams, blockParams, depths) {548var programWrapper = this.programs[i],549fn = this.fn(i);550if (data || depths || blockParams || declaredBlockParams) {551programWrapper = program(this, i, fn, data, declaredBlockParams, blockParams, depths);552} else if (!programWrapper) {553programWrapper = this.programs[i] = program(this, i, fn);554}555return programWrapper;556},557558data: function(data, depth) {559while (data && depth--) {560data = data._parent;561}562return data;563},564merge: function(param, common) {565var ret = param || common;566567if (param && common && (param !== common)) {568ret = Utils.extend({}, common, param);569}570571return ret;572},573574noop: env.VM.noop,575compilerInfo: templateSpec.compiler576};577578var ret = function(context, options) {579options = options || {};580var data = options.data;581582ret._setup(options);583if (!options.partial && templateSpec.useData) {584data = initData(context, data);585}586var depths,587blockParams = templateSpec.useBlockParams ? [] : undefined;588if (templateSpec.useDepths) {589depths = options.depths ? [context].concat(options.depths) : [context];590}591592return templateSpec.main.call(container, context, container.helpers, container.partials, data, blockParams, depths);593};594ret.isTop = true;595596ret._setup = function(options) {597if (!options.partial) {598container.helpers = container.merge(options.helpers, env.helpers);599600if (templateSpec.usePartial) {601container.partials = container.merge(options.partials, env.partials);602}603} else {604container.helpers = options.helpers;605container.partials = options.partials;606}607};608609ret._child = function(i, data, blockParams, depths) {610if (templateSpec.useBlockParams && !blockParams) {611throw new Exception('must pass block params');612}613if (templateSpec.useDepths && !depths) {614throw new Exception('must pass parent depths');615}616617return program(container, i, templateSpec[i], data, 0, blockParams, depths);618};619return ret;620}621622__exports__.template = template;function program(container, i, fn, data, declaredBlockParams, blockParams, depths) {623var prog = function(context, options) {624options = options || {};625626return fn.call(container,627context,628container.helpers, container.partials,629options.data || data,630blockParams && [options.blockParams].concat(blockParams),631depths && [context].concat(depths));632};633prog.program = i;634prog.depth = depths ? depths.length : 0;635prog.blockParams = declaredBlockParams || 0;636return prog;637}638639__exports__.program = program;function resolvePartial(partial, context, options) {640if (!partial) {641partial = options.partials[options.name];642} else if (!partial.call && !options.name) {643// This is a dynamic partial that returned a string644options.name = partial;645partial = options.partials[partial];646}647return partial;648}649650__exports__.resolvePartial = resolvePartial;function invokePartial(partial, context, options) {651options.partial = true;652653if(partial === undefined) {654throw new Exception("The partial " + options.name + " could not be found");655} else if(partial instanceof Function) {656return partial(context, options);657}658}659660__exports__.invokePartial = invokePartial;function noop() { return ""; }661662__exports__.noop = noop;function initData(context, data) {663if (!data || !('root' in data)) {664data = data ? createFrame(data) : {};665data.root = context;666}667return data;668}669return __exports__;670})(__module2__, __module3__, __module1__);671672// handlebars.runtime.js673var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) {674"use strict";675var __exports__;676/*globals Handlebars: true */677var base = __dependency1__;678679// Each of these augment the Handlebars object. No need to setup here.680// (This is done to easily share code between commonjs and browse envs)681var SafeString = __dependency2__;682var Exception = __dependency3__;683var Utils = __dependency4__;684var runtime = __dependency5__;685686// For compatibility and usage outside of module systems, make the Handlebars object a namespace687var create = function() {688var hb = new base.HandlebarsEnvironment();689690Utils.extend(hb, base);691hb.SafeString = SafeString;692hb.Exception = Exception;693hb.Utils = Utils;694hb.escapeExpression = Utils.escapeExpression;695696hb.VM = runtime;697hb.template = function(spec) {698return runtime.template(spec, hb);699};700701return hb;702};703704var Handlebars = create();705Handlebars.create = create;706707/*jshint -W040 */708/* istanbul ignore next */709var root = typeof global !== 'undefined' ? global : window,710$Handlebars = root.Handlebars;711/* istanbul ignore next */712Handlebars.noConflict = function() {713if (root.Handlebars === Handlebars) {714root.Handlebars = $Handlebars;715}716};717718Handlebars['default'] = Handlebars;719720__exports__ = Handlebars;721return __exports__;722})(__module1__, __module4__, __module3__, __module2__, __module5__);723724return __module0__;725}));726727728