From 112cdb63f9fccdda8e6cd12966724175eefbe897 Mon Sep 17 00:00:00 2001 From: Taritsyn Date: Tue, 8 Oct 2019 21:28:52 +0300 Subject: [PATCH] In BundleTransformer.Handlebars added support of the Handlebars version 4.4.2 --- .../externs/handlebars/handlebars.runtime.js | 12 +- .../Scripts/handlebars/handlebars.runtime.js | 95 +++++++---- .../handlebars/handlebars.runtime.min.js | 4 +- .../BundleTransformer.Handlebars.csproj | 4 +- .../Resources/handlebars.js | 147 ++++++++++++------ src/BundleTransformer.Handlebars/readme.txt | 4 +- 6 files changed, 176 insertions(+), 90 deletions(-) diff --git a/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/externs/handlebars/handlebars.runtime.js b/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/externs/handlebars/handlebars.runtime.js index c08c0244b..86a135e42 100644 --- a/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/externs/handlebars/handlebars.runtime.js +++ b/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/externs/handlebars/handlebars.runtime.js @@ -13,9 +13,11 @@ "decorators": { "inline": function(){} }, + "__esModule": {}, "HandlebarsEnvironment": function(){}, "VERSION": {}, "COMPILER_REVISION": {}, + "LAST_COMPATIBLE_COMPILER_REVISION": {}, "REVISION_CHANGES": { "1": {}, "2": {}, @@ -23,7 +25,8 @@ "4": {}, "5": {}, "6": {}, - "7": {} + "7": {}, + "8": {} }, "log": function(){}, "createFrame": function(){}, @@ -41,6 +44,7 @@ "SafeString": function(){}, "Exception": function(){}, "Utils": { + "__esModule": {}, "extend": function(){}, "indexOf": function(){}, "escapeExpression": function(){}, @@ -53,6 +57,7 @@ }, "escapeExpression": function(){}, "VM": { + "__esModule": {}, "checkRevision": function(){}, "template": function(){}, "wrapProgram": function(){}, @@ -70,9 +75,4 @@ "unregisterPartial": function(){}, "registerDecorator": function(){}, "unregisterDecorator": function(){} -}; - -var container = { - program: function() {}, - noop: function() {} }; \ No newline at end of file diff --git a/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/handlebars/handlebars.runtime.js b/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/handlebars/handlebars.runtime.js index 69afa39a2..4fa4c546e 100644 --- a/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/handlebars/handlebars.runtime.js +++ b/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/handlebars/handlebars.runtime.js @@ -1,7 +1,7 @@ /**! @license - handlebars v4.2.0 + handlebars v4.4.2 Copyright (C) 2011-2017 by Yehuda Katz @@ -207,11 +207,13 @@ return /******/ (function(modules) { // webpackBootstrap var _logger2 = _interopRequireDefault(_logger); - var VERSION = '4.2.0'; + var VERSION = '4.4.2'; 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', @@ -219,7 +221,8 @@ return /******/ (function(modules) { // webpackBootstrap 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; @@ -303,6 +306,7 @@ return /******/ (function(modules) { // webpackBootstrap exports.createFrame = createFrame; exports.blockParams = blockParams; exports.appendContextPath = appendContextPath; + var escape = { '&': '&', '<': '<', @@ -520,6 +524,7 @@ return /******/ (function(modules) { // webpackBootstrap exports.__esModule = true; exports.registerDefaultHelpers = registerDefaultHelpers; + exports.moveHelperToHooks = moveHelperToHooks; var _helpersBlockHelperMissing = __webpack_require__(10); @@ -559,6 +564,15 @@ return /******/ (function(modules) { // webpackBootstrap _helpersWith2['default'](instance); } + function moveHelperToHooks(instance, helperName, keepHelper) { + if (instance.helpers[helperName]) { + instance.hooks[helperName] = instance.helpers[helperName]; + if (!keepHelper) { + delete instance.helpers[helperName]; + } + } + } + /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { @@ -606,7 +620,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 11 */ /***/ (function(module, exports, __webpack_require__) { - 'use strict'; + /* WEBPACK VAR INJECTION */(function(global) {'use strict'; var _interopRequireDefault = __webpack_require__(2)['default']; @@ -668,6 +682,16 @@ return /******/ (function(modules) { // webpackBootstrap execIteration(i, i, i === context.length - 1); } } + } else if (global.Symbol && context[global.Symbol.iterator]) { + var newContext = []; + var iterator = context[global.Symbol.iterator](); + for (var it = iterator.next(); !it.done; it = iterator.next()) { + newContext.push(it.value); + } + context = newContext; + for (var j = context.length; i < j; i++) { + execIteration(i, i, i === context.length - 1); + } } else { var priorKey = undefined; @@ -698,6 +722,7 @@ return /******/ (function(modules) { // webpackBootstrap }; module.exports = exports['default']; + /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) /***/ }), /* 12 */ @@ -1001,23 +1026,28 @@ return /******/ (function(modules) { // webpackBootstrap var _base = __webpack_require__(3); + var _helpers = __webpack_require__(9); + 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'); @@ -1029,9 +1059,12 @@ return /******/ (function(modules) { // webpackBootstrap 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); @@ -1039,13 +1072,15 @@ return /******/ (function(modules) { // webpackBootstrap 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) { @@ -1112,15 +1147,6 @@ return /******/ (function(modules) { // webpackBootstrap } 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({}), @@ -1157,18 +1183,25 @@ return /******/ (function(modules) { // webpackBootstrap 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; } }; diff --git a/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/handlebars/handlebars.runtime.min.js b/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/handlebars/handlebars.runtime.min.js index a4975e12c..7a414225a 100644 --- a/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/handlebars/handlebars.runtime.min.js +++ b/samples/BundleTransformer.Sample.AspNet4.Mvc4/Scripts/handlebars/handlebars.runtime.min.js @@ -1,7 +1,7 @@ /**! @license - handlebars v4.2.0 + handlebars v4.4.2 Copyright (C) 2011-2017 by Yehuda Katz @@ -24,4 +24,4 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b():"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?exports.Handlebars=b():a.Handlebars=b()}(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){"use strict";function d(){var a=new h.HandlebarsEnvironment;return n.extend(a,h),a.SafeString=j["default"],a.Exception=l["default"],a.Utils=n,a.escapeExpression=n.escapeExpression,a.VM=p,a.template=function(b){return p.template(b,a)},a}var e=c(1)["default"],f=c(2)["default"];b.__esModule=!0;var g=c(3),h=e(g),i=c(20),j=f(i),k=c(5),l=f(k),m=c(4),n=e(m),o=c(21),p=e(o),q=c(33),r=f(q),s=d();s.create=d,r["default"](s),s["default"]=s,b["default"]=s,a.exports=b["default"]},function(a,b){"use strict";b["default"]=function(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b["default"]=a,b},b.__esModule=!0},function(a,b){"use strict";b["default"]=function(a){return a&&a.__esModule?a:{"default":a}},b.__esModule=!0},function(a,b,c){"use strict";function d(a,b,c){this.helpers=a||{},this.partials=b||{},this.decorators=c||{},i.registerDefaultHelpers(this),j.registerDefaultDecorators(this)}var e=c(2)["default"];b.__esModule=!0,b.HandlebarsEnvironment=d;var f=c(4),g=c(5),h=e(g),i=c(9),j=c(17),k=c(19),l=e(k),m="4.2.0";b.VERSION=m;var n=7;b.COMPILER_REVISION=n;var o={1:"<= 1.0.rc.2",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"};b.REVISION_CHANGES=o;var p="[object Object]";d.prototype={constructor:d,logger:l["default"],log:l["default"].log,registerHelper:function(a,b){if(f.toString.call(a)===p){if(b)throw new h["default"]("Arg not supported with multiple helpers");f.extend(this.helpers,a)}else this.helpers[a]=b},unregisterHelper:function(a){delete this.helpers[a]},registerPartial:function(a,b){if(f.toString.call(a)===p)f.extend(this.partials,a);else{if("undefined"==typeof b)throw new h["default"]('Attempting to register a partial called "'+a+'" as undefined');this.partials[a]=b}},unregisterPartial:function(a){delete this.partials[a]},registerDecorator:function(a,b){if(f.toString.call(a)===p){if(b)throw new h["default"]("Arg not supported with multiple decorators");f.extend(this.decorators,a)}else this.decorators[a]=b},unregisterDecorator:function(a){delete this.decorators[a]}};var q=l["default"].log;b.log=q,b.createFrame=f.createFrame,b.logger=l["default"]},function(a,b){"use strict";function c(a){return k[a]}function d(a){for(var b=1;b":">",'"':""","'":"'","`":"`","=":"="},l=/[&<>"'`=]/g,m=/[&<>"'`=]/,n=Object.prototype.toString;b.toString=n;var o=function(a){return"function"==typeof a};o(/x/)&&(b.isFunction=o=function(a){return"function"==typeof a&&"[object Function]"===n.call(a)}),b.isFunction=o;var p=Array.isArray||function(a){return!(!a||"object"!=typeof a)&&"[object Array]"===n.call(a)};b.isArray=p},function(a,b,c){"use strict";function d(a,b){var c=b&&b.loc,g=void 0,h=void 0;c&&(g=c.start.line,h=c.start.column,a+=" - "+g+":"+h);for(var i=Error.prototype.constructor.call(this,a),j=0;j0?(c.ids&&(c.ids=[c.name]),a.helpers.each(b,c)):e(this);if(c.data&&c.ids){var g=d.createFrame(c.data);g.contextPath=d.appendContextPath(c.data.contextPath,c.name),c={data:g}}return f(b,c)})},a.exports=b["default"]},function(a,b,c){"use strict";var d=c(2)["default"];b.__esModule=!0;var e=c(4),f=c(5),g=d(f);b["default"]=function(a){a.registerHelper("each",function(a,b){function c(b,c,f){j&&(j.key=b,j.index=c,j.first=0===c,j.last=!!f,k&&(j.contextPath=k+b)),i+=d(a[b],{data:j,blockParams:e.blockParams([a[b],b],[k+b,null])})}if(!b)throw new g["default"]("Must pass iterator to #each");var d=b.fn,f=b.inverse,h=0,i="",j=void 0,k=void 0;if(b.data&&b.ids&&(k=e.appendContextPath(b.data.contextPath,b.ids[0])+"."),e.isFunction(a)&&(a=a.call(this)),b.data&&(j=e.createFrame(b.data)),a&&"object"==typeof a)if(e.isArray(a))for(var l=a.length;h=0?b:parseInt(a,10)}return a},log:function(a){if(a=e.lookupLevel(a),"undefined"!=typeof console&&e.lookupLevel(e.level)<=a){var b=e.methodMap[a];console[b]||(b="log");for(var c=arguments.length,d=Array(c>1?c-1:0),f=1;f= 2.0.0-beta.1",7:">= 4.0.0 <4.3.0",8:">= 4.3.0"};b.REVISION_CHANGES=p;var q="[object Object]";d.prototype={constructor:d,logger:l["default"],log:l["default"].log,registerHelper:function(a,b){if(f.toString.call(a)===q){if(b)throw new h["default"]("Arg not supported with multiple helpers");f.extend(this.helpers,a)}else this.helpers[a]=b},unregisterHelper:function(a){delete this.helpers[a]},registerPartial:function(a,b){if(f.toString.call(a)===q)f.extend(this.partials,a);else{if("undefined"==typeof b)throw new h["default"]('Attempting to register a partial called "'+a+'" as undefined');this.partials[a]=b}},unregisterPartial:function(a){delete this.partials[a]},registerDecorator:function(a,b){if(f.toString.call(a)===q){if(b)throw new h["default"]("Arg not supported with multiple decorators");f.extend(this.decorators,a)}else this.decorators[a]=b},unregisterDecorator:function(a){delete this.decorators[a]}};var r=l["default"].log;b.log=r,b.createFrame=f.createFrame,b.logger=l["default"]},function(a,b){"use strict";function c(a){return k[a]}function d(a){for(var b=1;b":">",'"':""","'":"'","`":"`","=":"="},l=/[&<>"'`=]/g,m=/[&<>"'`=]/,n=Object.prototype.toString;b.toString=n;var o=function(a){return"function"==typeof a};o(/x/)&&(b.isFunction=o=function(a){return"function"==typeof a&&"[object Function]"===n.call(a)}),b.isFunction=o;var p=Array.isArray||function(a){return!(!a||"object"!=typeof a)&&"[object Array]"===n.call(a)};b.isArray=p},function(a,b,c){"use strict";function d(a,b){var c=b&&b.loc,g=void 0,h=void 0;c&&(g=c.start.line,h=c.start.column,a+=" - "+g+":"+h);for(var i=Error.prototype.constructor.call(this,a),j=0;j0?(c.ids&&(c.ids=[c.name]),a.helpers.each(b,c)):e(this);if(c.data&&c.ids){var g=d.createFrame(c.data);g.contextPath=d.appendContextPath(c.data.contextPath,c.name),c={data:g}}return f(b,c)})},a.exports=b["default"]},function(a,b,c){(function(d){"use strict";var e=c(2)["default"];b.__esModule=!0;var f=c(4),g=c(5),h=e(g);b["default"]=function(a){a.registerHelper("each",function(a,b){function c(b,c,d){k&&(k.key=b,k.index=c,k.first=0===c,k.last=!!d,l&&(k.contextPath=l+b)),j+=e(a[b],{data:k,blockParams:f.blockParams([a[b],b],[l+b,null])})}if(!b)throw new h["default"]("Must pass iterator to #each");var e=b.fn,g=b.inverse,i=0,j="",k=void 0,l=void 0;if(b.data&&b.ids&&(l=f.appendContextPath(b.data.contextPath,b.ids[0])+"."),f.isFunction(a)&&(a=a.call(this)),b.data&&(k=f.createFrame(b.data)),a&&"object"==typeof a)if(f.isArray(a))for(var m=a.length;i=0?b:parseInt(a,10)}return a},log:function(a){if(a=e.lookupLevel(a),"undefined"!=typeof console&&e.lookupLevel(e.level)<=a){var b=e.methodMap[a];console[b]||(b="log");for(var c=arguments.length,d=Array(c>1?c-1:0),f=1;f=s.LAST_COMPATIBLE_COMPILER_REVISION&&b<=s.COMPILER_REVISION)){if(btrue $(NoWarn);CS1591;NU5125 true - BundleTransformer.Handlebars contains one translator-adapter - `HandlebarsTranslator` (supports the Handlebars (http://handlebarsjs.com) version 4.2.0). This adapter makes translation of Handlebars templates to JS code. Also contains the `HandlebarsAssetHandler` debugging HTTP handler, which is responsible for text output of translated Handlebars asset. + BundleTransformer.Handlebars contains one translator-adapter - `HandlebarsTranslator` (supports the Handlebars (http://handlebarsjs.com) version 4.4.2). This adapter makes translation of Handlebars templates to JS code. Also contains the `HandlebarsAssetHandler` debugging HTTP handler, which is responsible for text output of translated Handlebars asset. As a JS engine is used the JavaScript Engine Switcher library (https://github.com/Taritsyn/JavaScriptEngineSwitcher). For correct working of this module, you need to install one of the following NuGet packages: JavaScriptEngineSwitcher.Msie, JavaScriptEngineSwitcher.V8 or JavaScriptEngineSwitcher.ChakraCore. https://raw.githubusercontent.com/Taritsyn/BundleTransformer/master/images/icons/128/BundleTransformer_Handlebars_Logo_128x128.png BundleTransformer;System.Web.Optimization;IBundleTransform;ASP.NET;JavaScript;JS;Bundling;Handlebars;Translation;Translator;Compilation;Compiler - Added support of Handlebars version 4.2.0. + Added support of the Handlebars version 4.4.2. diff --git a/src/BundleTransformer.Handlebars/Resources/handlebars.js b/src/BundleTransformer.Handlebars/Resources/handlebars.js index f40984c98..7575fe079 100644 --- a/src/BundleTransformer.Handlebars/Resources/handlebars.js +++ b/src/BundleTransformer.Handlebars/Resources/handlebars.js @@ -1,7 +1,7 @@ /**! @license - handlebars v4.2.0 + handlebars v4.4.2 Copyright (C) 2011-2017 by Yehuda Katz @@ -275,11 +275,13 @@ return /******/ (function(modules) { // webpackBootstrap var _logger2 = _interopRequireDefault(_logger); - var VERSION = '4.2.0'; + var VERSION = '4.4.2'; 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', @@ -287,7 +289,8 @@ return /******/ (function(modules) { // webpackBootstrap 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; @@ -371,6 +374,7 @@ return /******/ (function(modules) { // webpackBootstrap exports.createFrame = createFrame; exports.blockParams = blockParams; exports.appendContextPath = appendContextPath; + var escape = { '&': '&', '<': '<', @@ -588,6 +592,7 @@ return /******/ (function(modules) { // webpackBootstrap exports.__esModule = true; exports.registerDefaultHelpers = registerDefaultHelpers; + exports.moveHelperToHooks = moveHelperToHooks; var _helpersBlockHelperMissing = __webpack_require__(11); @@ -627,6 +632,15 @@ return /******/ (function(modules) { // webpackBootstrap _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__) { @@ -674,7 +688,7 @@ return /******/ (function(modules) { // webpackBootstrap /* 12 */ /***/ (function(module, exports, __webpack_require__) { - 'use strict'; + /* WEBPACK VAR INJECTION */(function(global) {'use strict'; var _interopRequireDefault = __webpack_require__(1)['default']; @@ -736,6 +750,16 @@ return /******/ (function(modules) { // webpackBootstrap execIteration(i, i, i === context.length - 1); } } + } else if (global.Symbol && context[global.Symbol.iterator]) { + var newContext = []; + var iterator = context[global.Symbol.iterator](); + for (var it = iterator.next(); !it.done; it = iterator.next()) { + newContext.push(it.value); + } + context = newContext; + for (var j = context.length; i < j; i++) { + execIteration(i, i, i === context.length - 1); + } } else { var priorKey = undefined; @@ -766,6 +790,7 @@ return /******/ (function(modules) { // webpackBootstrap }; module.exports = exports['default']; + /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) /***/ }), /* 13 */ @@ -1069,23 +1094,28 @@ return /******/ (function(modules) { // webpackBootstrap 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'); @@ -1097,9 +1127,12 @@ return /******/ (function(modules) { // webpackBootstrap 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); @@ -1107,13 +1140,15 @@ return /******/ (function(modules) { // webpackBootstrap 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) { @@ -1180,15 +1215,6 @@ return /******/ (function(modules) { // webpackBootstrap } 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({}), @@ -1225,18 +1251,25 @@ return /******/ (function(modules) { // webpackBootstrap 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; } }; @@ -2579,7 +2612,7 @@ return /******/ (function(modules) { // webpackBootstrap 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; @@ -3571,13 +3604,19 @@ return /******/ (function(modules) { // webpackBootstrap // PUBLIC API: You can override these methods in a subclass to provide // alternative compiled forms for name lookup and buffering semantics nameLookup: function nameLookup(parent, name /* , type*/) { + var isEnumerable = [this.aliasable('container.propertyIsEnumerable'), '.call(', parent, ',"constructor")']; + if (name === 'constructor') { - return ['(', parent, '.propertyIsEnumerable(\'constructor\') ? ', parent, '.constructor : undefined', ')']; + return ['(', isEnumerable, '?', _actualLookup(), ' : undefined)']; } - if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) { - return [parent, '.', name]; - } else { - return [parent, '[', JSON.stringify(name), ']']; + return _actualLookup(); + + function _actualLookup() { + if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) { + return [parent, '.', name]; + } else { + return [parent, '[', JSON.stringify(name), ']']; + } } }, depthedLookup: function depthedLookup(name) { @@ -3776,7 +3815,6 @@ return /******/ (function(modules) { // webpackBootstrap for (var alias in this.aliases) { // eslint-disable-line guard-for-in var node = this.aliases[alias]; - if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) { varDeclarations += ', alias' + ++aliasCount + '=' + alias; node.children[0] = 'alias' + aliasCount; @@ -3871,7 +3909,7 @@ return /******/ (function(modules) { // webpackBootstrap // 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); @@ -3889,7 +3927,7 @@ return /******/ (function(modules) { // webpackBootstrap // 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); @@ -4180,18 +4218,33 @@ return /******/ (function(modules) { // webpackBootstrap // 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 possibleFunctionCalls = []; - var lookup = ['('].concat(simple, nonHelper); + 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..., ... @@ -4229,7 +4282,7 @@ return /******/ (function(modules) { // webpackBootstrap 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))']); diff --git a/src/BundleTransformer.Handlebars/readme.txt b/src/BundleTransformer.Handlebars/readme.txt index fc99b4474..c13cab874 100644 --- a/src/BundleTransformer.Handlebars/readme.txt +++ b/src/BundleTransformer.Handlebars/readme.txt @@ -13,7 +13,7 @@ =========== BundleTransformer.Handlebars contains one translator-adapter - `HandlebarsTranslator` (supports the Handlebars (http://handlebarsjs.com) - version 4.2.0). This adapter makes translation of Handlebars templates to JS + version 4.4.2). This adapter makes translation of Handlebars templates to JS code. Also contains the `HandlebarsAssetHandler` debugging HTTP handler, which is responsible for text output of translated Handlebars asset. @@ -23,7 +23,7 @@ ============= RELEASE NOTES ============= - Added support of Handlebars version 4.2.0. + Added support of the Handlebars version 4.4.2. ==================== POST-INSTALL ACTIONS