vendor/assets/javascripts/handlebars.js in handlebars_assets-0.23.4 vs vendor/assets/javascripts/handlebars.js in handlebars_assets-0.23.5
- old
+ new
@@ -1,9 +1,9 @@
/**!
@license
- handlebars v4.1.2
+ handlebars v4.3.1
Copyright (C) 2011-2017 by Yehuda Katz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -273,23 +273,26 @@
var _logger = __webpack_require__(20);
var _logger2 = _interopRequireDefault(_logger);
- var VERSION = '4.1.2';
+ var VERSION = '4.3.1';
exports.VERSION = VERSION;
- var COMPILER_REVISION = 7;
-
+ var COMPILER_REVISION = 8;
exports.COMPILER_REVISION = COMPILER_REVISION;
+ var LAST_COMPATIBLE_COMPILER_REVISION = 7;
+
+ exports.LAST_COMPATIBLE_COMPILER_REVISION = LAST_COMPATIBLE_COMPILER_REVISION;
var REVISION_CHANGES = {
1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
2: '== 1.0.0-rc.3',
3: '== 1.0.0-rc.4',
4: '== 1.x.x',
5: '== 2.0.0-alpha.x',
6: '>= 2.0.0-beta.1',
- 7: '>= 4.0.0'
+ 7: '>= 4.0.0 <4.3.0',
+ 8: '>= 4.3.0'
};
exports.REVISION_CHANGES = REVISION_CHANGES;
var objectType = '[object Object]';
@@ -369,10 +372,11 @@
exports.escapeExpression = escapeExpression;
exports.isEmpty = isEmpty;
exports.createFrame = createFrame;
exports.blockParams = blockParams;
exports.appendContextPath = appendContextPath;
+
var escape = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
@@ -586,10 +590,11 @@
var _interopRequireDefault = __webpack_require__(1)['default'];
exports.__esModule = true;
exports.registerDefaultHelpers = registerDefaultHelpers;
+ exports.moveHelperToHooks = moveHelperToHooks;
var _helpersBlockHelperMissing = __webpack_require__(11);
var _helpersBlockHelperMissing2 = _interopRequireDefault(_helpersBlockHelperMissing);
@@ -625,10 +630,19 @@
_helpersLog2['default'](instance);
_helpersLookup2['default'](instance);
_helpersWith2['default'](instance);
}
+ function moveHelperToHooks(instance, helperName, keepHelper) {
+ if (instance.helpers[helperName]) {
+ instance.hooks[helperName] = instance.helpers[helperName];
+ if (!keepHelper) {
+ delete instance.helpers[helperName];
+ }
+ }
+ }
+
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
@@ -1067,27 +1081,32 @@
var _exception2 = _interopRequireDefault(_exception);
var _base = __webpack_require__(4);
+ var _helpers = __webpack_require__(10);
+
function checkRevision(compilerInfo) {
var compilerRevision = compilerInfo && compilerInfo[0] || 1,
currentRevision = _base.COMPILER_REVISION;
- if (compilerRevision !== currentRevision) {
- if (compilerRevision < currentRevision) {
- var runtimeVersions = _base.REVISION_CHANGES[currentRevision],
- compilerVersions = _base.REVISION_CHANGES[compilerRevision];
- throw new _exception2['default']('Template was precompiled with an older version of Handlebars than the current runtime. ' + 'Please update your precompiler to a newer version (' + runtimeVersions + ') or downgrade your runtime to an older version (' + compilerVersions + ').');
- } else {
- // Use the embedded version info since the runtime doesn't know about this revision yet
- throw new _exception2['default']('Template was precompiled with a newer version of Handlebars than the current runtime. ' + 'Please update your runtime to a newer version (' + compilerInfo[1] + ').');
- }
+ if (compilerRevision >= _base.LAST_COMPATIBLE_COMPILER_REVISION && compilerRevision <= _base.COMPILER_REVISION) {
+ return;
}
+
+ if (compilerRevision < _base.LAST_COMPATIBLE_COMPILER_REVISION) {
+ var runtimeVersions = _base.REVISION_CHANGES[currentRevision],
+ compilerVersions = _base.REVISION_CHANGES[compilerRevision];
+ throw new _exception2['default']('Template was precompiled with an older version of Handlebars than the current runtime. ' + 'Please update your precompiler to a newer version (' + runtimeVersions + ') or downgrade your runtime to an older version (' + compilerVersions + ').');
+ } else {
+ // Use the embedded version info since the runtime doesn't know about this revision yet
+ throw new _exception2['default']('Template was precompiled with a newer version of Handlebars than the current runtime. ' + 'Please update your runtime to a newer version (' + compilerInfo[1] + ').');
+ }
}
function template(templateSpec, env) {
+
/* istanbul ignore next */
if (!env) {
throw new _exception2['default']('No environment passed to template');
}
if (!templateSpec || !templateSpec.main) {
@@ -1095,27 +1114,32 @@
}
templateSpec.main.decorator = templateSpec.main_d;
// Note: Using env.VM references rather than local var references throughout this section to allow
- // for external users to override these as psuedo-supported APIs.
+ // for external users to override these as pseudo-supported APIs.
env.VM.checkRevision(templateSpec.compiler);
+ // backwards compatibility for precompiled templates with compiler-version 7 (<4.3.0)
+ var templateWasPrecompiledWithCompilerV7 = templateSpec.compiler && templateSpec.compiler[0] === 7;
+
function invokePartialWrapper(partial, context, options) {
if (options.hash) {
context = Utils.extend({}, context, options.hash);
if (options.ids) {
options.ids[0] = true;
}
}
-
partial = env.VM.resolvePartial.call(this, partial, context, options);
- var result = env.VM.invokePartial.call(this, partial, context, options);
+ var optionsWithHooks = Utils.extend({}, options, { hooks: this.hooks });
+
+ var result = env.VM.invokePartial.call(this, partial, context, optionsWithHooks);
+
if (result == null && env.compile) {
options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);
- result = options.partials[options.name](context, options);
+ result = options.partials[options.name](context, optionsWithHooks);
}
if (result != null) {
if (options.indent) {
var lines = result.split('\n');
for (var i = 0, l = lines.length; i < l; i++) {
@@ -1178,19 +1202,10 @@
while (value && depth--) {
value = value._parent;
}
return value;
},
- merge: function merge(param, common) {
- var obj = param || common;
-
- if (param && common && param !== common) {
- obj = Utils.extend({}, common, param);
- }
-
- return obj;
- },
// An empty object to use as replacement for null-contexts
nullContext: _Object$seal({}),
noop: env.VM.noop,
compilerInfo: templateSpec.compiler
@@ -1223,22 +1238,29 @@
}
ret.isTop = true;
ret._setup = function (options) {
if (!options.partial) {
- container.helpers = container.merge(options.helpers, env.helpers);
+ container.helpers = Utils.extend({}, env.helpers, options.helpers);
if (templateSpec.usePartial) {
- container.partials = container.merge(options.partials, env.partials);
+ container.partials = Utils.extend({}, env.partials, options.partials);
}
if (templateSpec.usePartial || templateSpec.useDecorators) {
- container.decorators = container.merge(options.decorators, env.decorators);
+ container.decorators = Utils.extend({}, env.decorators, options.decorators);
}
+
+ container.hooks = {};
+
+ var keepHelperInHelpers = options.allowCallsToHelperMissing || templateWasPrecompiledWithCompilerV7;
+ _helpers.moveHelperToHooks(container, 'helperMissing', keepHelperInHelpers);
+ _helpers.moveHelperToHooks(container, 'blockHelperMissing', keepHelperInHelpers);
} else {
container.helpers = options.helpers;
container.partials = options.partials;
container.decorators = options.decorators;
+ container.hooks = options.hooks;
}
};
ret._child = function (i, data, blockParams, depths) {
if (templateSpec.useBlockParams && !blockParams) {
@@ -1271,10 +1293,14 @@
prog.depth = depths ? depths.length : 0;
prog.blockParams = declaredBlockParams || 0;
return prog;
}
+ /**
+ * This is currently part of the official API, therefore implementation details should not be changed.
+ */
+
function resolvePartial(partial, context, options) {
if (!partial) {
if (options.name === '@partial-block') {
partial = options.data['partial-block'];
} else {
@@ -2573,11 +2599,11 @@
var current = body[i == null ? body.length - 1 : i - 1];
if (!current || current.type !== 'ContentStatement' || !multiple && current.leftStripped) {
return;
}
- // We omit the last node if it's whitespace only and not preceeded by a non-content node.
+ // We omit the last node if it's whitespace only and not preceded by a non-content node.
var original = current.value;
current.value = current.value.replace(multiple ? /\s+$/ : /[ \t]+$/, '');
current.leftStripped = current.value !== original;
return current.leftStripped;
}
@@ -3865,11 +3891,11 @@
// The purpose of this opcode is to take a block of the form
// `{{#this.foo}}...{{/this.foo}}`, resolve the value of `foo`, and
// replace it on the stack with the result of properly
// invoking blockHelperMissing.
blockValue: function blockValue(name) {
- var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
+ var blockHelperMissing = this.aliasable('container.hooks.blockHelperMissing'),
params = [this.contextName(0)];
this.setupHelperArgs(name, 0, params);
var blockName = this.popStack();
params.splice(1, 0, blockName);
@@ -3883,11 +3909,11 @@
// Compiler value, before: lastHelper=value of last found helper, if any
// On stack, after, if no lastHelper: same as [blockValue]
// On stack, after, if lastHelper: value
ambiguousBlockValue: function ambiguousBlockValue() {
// We're being a bit cheeky and reusing the options value from the prior exec
- var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
+ var blockHelperMissing = this.aliasable('container.hooks.blockHelperMissing'),
params = [this.contextName(0)];
this.setupHelperArgs('', 0, params, true);
this.flushInline();
@@ -4174,22 +4200,37 @@
// and pushes the helper's return value onto the stack.
//
// If the helper is not found, `helperMissing` is called.
invokeHelper: function invokeHelper(paramSize, name, isSimple) {
var nonHelper = this.popStack(),
- helper = this.setupHelper(paramSize, name),
- simple = isSimple ? [helper.name, ' || '] : '';
+ helper = this.setupHelper(paramSize, name);
- var lookup = ['('].concat(simple, nonHelper);
+ var possibleFunctionCalls = [];
+
+ if (isSimple) {
+ // direct call to helper
+ possibleFunctionCalls.push(helper.name);
+ }
+ // call a function from the input object
+ possibleFunctionCalls.push(nonHelper);
if (!this.options.strict) {
- lookup.push(' || ', this.aliasable('helpers.helperMissing'));
+ possibleFunctionCalls.push(this.aliasable('container.hooks.helperMissing'));
}
- lookup.push(')');
- this.push(this.source.functionCall(lookup, 'call', helper.callParams));
+ var functionLookupCode = ['(', this.itemsSeparatedBy(possibleFunctionCalls, '||'), ')'];
+ var functionCall = this.source.functionCall(functionLookupCode, 'call', helper.callParams);
+ this.push(functionCall);
},
+ itemsSeparatedBy: function itemsSeparatedBy(items, separator) {
+ var result = [];
+ result.push(items[0]);
+ for (var i = 1; i < items.length; i++) {
+ result.push(separator, items[i]);
+ }
+ return result;
+ },
// [invokeKnownHelper]
//
// On stack, before: hash, inverse, program, params..., ...
// On stack, after: result of helper invocation
//
@@ -4223,10 +4264,10 @@
var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
var lookup = ['(', '(helper = ', helperName, ' || ', nonHelper, ')'];
if (!this.options.strict) {
lookup[0] = '(helper = ';
- lookup.push(' != null ? helper : ', this.aliasable('helpers.helperMissing'));
+ lookup.push(' != null ? helper : ', this.aliasable('container.hooks.helperMissing'));
}
this.push(['(', lookup, helper.paramsInit ? ['),(', helper.paramsInit] : [], '),', '(typeof helper === ', this.aliasable('"function"'), ' ? ', this.source.functionCall('helper', 'call', helper.callParams), ' : helper))']);
},