From eb941a1211b7f707c60e2177772e6ce74020516b Mon Sep 17 00:00:00 2001 From: biodiscus Date: Sun, 8 Dec 2024 23:27:30 +0100 Subject: [PATCH] test: add test for habdlebars helpers used in comple mode --- .../js-tmpl-hbs-compile-helpers/expected/app.js | 2 +- .../js-tmpl-hbs-compile-helpers/src/app.hbs | 3 ++- .../src/helpers-esm/html-helpers.js | 10 ++++++++++ .../js-tmpl-hbs-compile-helpers/webpack.config.js | 9 +++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/helpers-esm/html-helpers.js diff --git a/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/expected/app.js b/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/expected/app.js index cf42a5a2..41b241e1 100644 --- a/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/expected/app.js +++ b/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/expected/app.js @@ -1 +1 @@ -(()=>{var e={916:(e,t,r)=>{"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function n(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}t.__esModule=!0;var a=n(r(387)),l=o(r(16)),i=o(r(564)),s=n(r(456)),u=n(r(433)),c=o(r(157));function p(){var e=new a.HandlebarsEnvironment;return s.extend(e,a),e.SafeString=l.default,e.Exception=i.default,e.Utils=s,e.escapeExpression=s.escapeExpression,e.VM=u,e.template=function(t){return u.template(t,e)},e}var d=p();d.create=p,c.default(d),d.default=d,t.default=d,e.exports=t.default},387:(e,t,r)=>{"use strict";function o(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.HandlebarsEnvironment=p;var n=r(456),a=o(r(564)),l=r(880),i=r(103),s=o(r(677)),u=r(352);t.VERSION="4.7.8",t.COMPILER_REVISION=8,t.LAST_COMPATIBLE_COMPILER_REVISION=7,t.REVISION_CHANGES={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 <4.3.0",8:">= 4.3.0"};var c="[object Object]";function p(e,t,r){this.helpers=e||{},this.partials=t||{},this.decorators=r||{},l.registerDefaultHelpers(this),i.registerDefaultDecorators(this)}p.prototype={constructor:p,logger:s.default,log:s.default.log,registerHelper:function(e,t){if(n.toString.call(e)===c){if(t)throw new a.default("Arg not supported with multiple helpers");n.extend(this.helpers,e)}else this.helpers[e]=t},unregisterHelper:function(e){delete this.helpers[e]},registerPartial:function(e,t){if(n.toString.call(e)===c)n.extend(this.partials,e);else{if(void 0===t)throw new a.default('Attempting to register a partial called "'+e+'" as undefined');this.partials[e]=t}},unregisterPartial:function(e){delete this.partials[e]},registerDecorator:function(e,t){if(n.toString.call(e)===c){if(t)throw new a.default("Arg not supported with multiple decorators");n.extend(this.decorators,e)}else this.decorators[e]=t},unregisterDecorator:function(e){delete this.decorators[e]},resetLoggedPropertyAccesses:function(){u.resetLoggedProperties()}};var d=s.default.log;t.log=d,t.createFrame=n.createFrame,t.logger=s.default},103:(e,t,r)=>{"use strict";t.__esModule=!0,t.registerDefaultDecorators=function(e){n.default(e)};var o,n=(o=r(731))&&o.__esModule?o:{default:o}},731:(e,t,r)=>{"use strict";t.__esModule=!0;var o=r(456);t.default=function(e){e.registerDecorator("inline",(function(e,t,r,n){var a=e;return t.partials||(t.partials={},a=function(n,a){var l=r.partials;r.partials=o.extend({},l,t.partials);var i=e(n,a);return r.partials=l,i}),t.partials[n.args[0]]=n.fn,a}))},e.exports=t.default},564:(e,t)=>{"use strict";t.__esModule=!0;var r=["description","fileName","lineNumber","endLineNumber","message","name","number","stack"];function o(e,t){var n=t&&t.loc,a=void 0,l=void 0,i=void 0,s=void 0;n&&(a=n.start.line,l=n.end.line,i=n.start.column,s=n.end.column,e+=" - "+a+":"+i);for(var u=Error.prototype.constructor.call(this,e),c=0;c{"use strict";function o(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.registerDefaultHelpers=function(e){n.default(e),a.default(e),l.default(e),i.default(e),s.default(e),u.default(e),c.default(e)},t.moveHelperToHooks=function(e,t,r){e.helpers[t]&&(e.hooks[t]=e.helpers[t],r||delete e.helpers[t])};var n=o(r(582)),a=o(r(646)),l=o(r(170)),i=o(r(264)),s=o(r(233)),u=o(r(205)),c=o(r(331))},582:(e,t,r)=>{"use strict";t.__esModule=!0;var o=r(456);t.default=function(e){e.registerHelper("blockHelperMissing",(function(t,r){var n=r.inverse,a=r.fn;if(!0===t)return a(this);if(!1===t||null==t)return n(this);if(o.isArray(t))return t.length>0?(r.ids&&(r.ids=[r.name]),e.helpers.each(t,r)):n(this);if(r.data&&r.ids){var l=o.createFrame(r.data);l.contextPath=o.appendContextPath(r.data.contextPath,r.name),r={data:l}}return a(t,r)}))},e.exports=t.default},646:(e,t,r)=>{"use strict";t.__esModule=!0;var o,n=r(456),a=(o=r(564))&&o.__esModule?o:{default:o};t.default=function(e){e.registerHelper("each",(function(e,t){if(!t)throw new a.default("Must pass iterator to #each");var r,o=t.fn,l=t.inverse,i=0,s="",u=void 0,c=void 0;function p(t,r,a){u&&(u.key=t,u.index=r,u.first=0===r,u.last=!!a,c&&(u.contextPath=c+t)),s+=o(e[t],{data:u,blockParams:n.blockParams([e[t],t],[c+t,null])})}if(t.data&&t.ids&&(c=n.appendContextPath(t.data.contextPath,t.ids[0])+"."),n.isFunction(e)&&(e=e.call(this)),t.data&&(u=n.createFrame(t.data)),e&&"object"==typeof e)if(n.isArray(e))for(var d=e.length;i{"use strict";t.__esModule=!0;var o,n=(o=r(564))&&o.__esModule?o:{default:o};t.default=function(e){e.registerHelper("helperMissing",(function(){if(1!==arguments.length)throw new n.default('Missing helper: "'+arguments[arguments.length-1].name+'"')}))},e.exports=t.default},264:(e,t,r)=>{"use strict";t.__esModule=!0;var o,n=r(456),a=(o=r(564))&&o.__esModule?o:{default:o};t.default=function(e){e.registerHelper("if",(function(e,t){if(2!=arguments.length)throw new a.default("#if requires exactly one argument");return n.isFunction(e)&&(e=e.call(this)),!t.hash.includeZero&&!e||n.isEmpty(e)?t.inverse(this):t.fn(this)})),e.registerHelper("unless",(function(t,r){if(2!=arguments.length)throw new a.default("#unless requires exactly one argument");return e.helpers.if.call(this,t,{fn:r.inverse,inverse:r.fn,hash:r.hash})}))},e.exports=t.default},233:(e,t)=>{"use strict";t.__esModule=!0,t.default=function(e){e.registerHelper("log",(function(){for(var t=[void 0],r=arguments[arguments.length-1],o=0;o{"use strict";t.__esModule=!0,t.default=function(e){e.registerHelper("lookup",(function(e,t,r){return e?r.lookupProperty(e,t):e}))},e.exports=t.default},331:(e,t,r)=>{"use strict";t.__esModule=!0;var o,n=r(456),a=(o=r(564))&&o.__esModule?o:{default:o};t.default=function(e){e.registerHelper("with",(function(e,t){if(2!=arguments.length)throw new a.default("#with requires exactly one argument");n.isFunction(e)&&(e=e.call(this));var r=t.fn;if(n.isEmpty(e))return t.inverse(this);var o=t.data;return t.data&&t.ids&&((o=n.createFrame(t.data)).contextPath=n.appendContextPath(t.data.contextPath,t.ids[0])),r(e,{data:o,blockParams:n.blockParams([e],[o&&o.contextPath])})}))},e.exports=t.default},955:(e,t,r)=>{"use strict";t.__esModule=!0,t.createNewLookupObject=function(){for(var e=arguments.length,t=Array(e),r=0;r{"use strict";t.__esModule=!0,t.createProtoAccessControl=function(e){var t=Object.create(null);t.constructor=!1,t.__defineGetter__=!1,t.__defineSetter__=!1,t.__lookupGetter__=!1;var r=Object.create(null);return r.__proto__=!1,{properties:{whitelist:n.createNewLookupObject(r,e.allowedProtoProperties),defaultValue:e.allowProtoPropertiesByDefault},methods:{whitelist:n.createNewLookupObject(t,e.allowedProtoMethods),defaultValue:e.allowProtoMethodsByDefault}}},t.resultIsAllowed=function(e,t,r){return function(e,t){return void 0!==e.whitelist[t]?!0===e.whitelist[t]:void 0!==e.defaultValue?e.defaultValue:(function(e){!0!==l[e]&&(l[e]=!0,a.default.log("error",'Handlebars: Access has been denied to resolve the property "'+e+'" because it is not an "own property" of its parent.\nYou can add a runtime option to disable the check or this warning:\nSee https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details'))}(t),!1)}("function"==typeof e?t.methods:t.properties,r)},t.resetLoggedProperties=function(){Object.keys(l).forEach((function(e){delete l[e]}))};var o,n=r(955),a=(o=r(677))&&o.__esModule?o:{default:o},l=Object.create(null)},423:(e,t)=>{"use strict";t.__esModule=!0,t.wrapHelper=function(e,t){return"function"!=typeof e?e:function(){return arguments[arguments.length-1]=t(arguments[arguments.length-1]),e.apply(this,arguments)}}},677:(e,t,r)=>{"use strict";t.__esModule=!0;var o=r(456),n={methodMap:["debug","info","warn","error"],level:"info",lookupLevel:function(e){if("string"==typeof e){var t=o.indexOf(n.methodMap,e.toLowerCase());e=t>=0?t:parseInt(e,10)}return e},log:function(e){if(e=n.lookupLevel(e),"undefined"!=typeof console&&n.lookupLevel(n.level)<=e){var t=n.methodMap[e];console[t]||(t="log");for(var r=arguments.length,o=Array(r>1?r-1:0),a=1;a{"use strict";t.__esModule=!0,t.default=function(e){"object"!=typeof globalThis&&(Object.prototype.__defineGetter__("__magic__",(function(){return this})),__magic__.globalThis=__magic__,delete Object.prototype.__magic__);var t=globalThis.Handlebars;e.noConflict=function(){return globalThis.Handlebars===e&&(globalThis.Handlebars=t),e}},e.exports=t.default},433:(e,t,r)=>{"use strict";t.__esModule=!0,t.checkRevision=function(e){var t=e&&e[0]||1,r=l.COMPILER_REVISION;if(!(t>=l.LAST_COMPATIBLE_COMPILER_REVISION&&t<=l.COMPILER_REVISION)){if(t{"use strict";function r(e){this.string=e}t.__esModule=!0,r.prototype.toString=r.prototype.toHTML=function(){return""+this.string},t.default=r,e.exports=t.default},456:(e,t)=>{"use strict";t.__esModule=!0,t.extend=l,t.indexOf=function(e,t){for(var r=0,o=e.length;r":">",'"':""","'":"'","`":"`","=":"="},o=/[&<>"'`=]/g,n=/[&<>"'`=]/;function a(e){return r[e]}function l(e){for(var t=1;t{e.exports=r(916).default},768:(e,t,r)=>{var o=r(128),n={};o.registerHelper("bold",(function(e){return new o.SafeString(`${e.fn(this)}`)})),o.partials.footer=o.template({compiler:[8,">= 4.3.0"],main:function(e,t,r,o,n){return"
-= FOOTER =-
\n"},useData:!0});var a={1:function(e,t,r,o,n){var a,l=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.escapeExpression("function"==typeof(a=null!=(a=l(r,"helloName")||(null!=t?l(t,"helloName"):t))?a:e.hooks.helperMissing)?a.call(null!=t?t:e.nullContext||{},{name:"helloName",hash:{},data:n,loc:{start:{line:1,column:18},end:{line:1,column:31}}}):a)},compiler:[8,">= 4.3.0"],main:function(e,t,r,o,n){var a,l,i,s=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]},u="

Hello ";return l=null!=(l=s(r,"bold")||(null!=t?s(t,"bold"):t))?l:e.hooks.helperMissing,i={name:"bold",hash:{},fn:e.program(1,n,0),inverse:e.noop,data:n,loc:{start:{line:1,column:9},end:{line:1,column:40}}},a="function"==typeof l?l.call(null!=t?t:e.nullContext||{},i):l,s(r,"bold")||(a=e.hooks.blockHelperMissing.call(t,a,i)),null!=a&&(u+=a),u+"!

\n"+(null!=(a=e.invokePartial(s(o,"footer"),t,{name:"footer",data:n,helpers:r,partials:o,decorators:e.decorators}))?a:"")},usePartial:!0,useData:!0};e.exports=e=>(o.default||o).template(a)(Object.assign({},n,e))}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=r(768),t=r.n(e);document.getElementById("app").innerHTML=t()({helloName:"World"}),console.log(">> app")})()})(); \ No newline at end of file +(()=>{var e={916:(e,t,r)=>{"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function n(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}t.__esModule=!0;var a=n(r(387)),l=o(r(16)),i=o(r(564)),s=n(r(456)),u=n(r(433)),c=o(r(157));function p(){var e=new a.HandlebarsEnvironment;return s.extend(e,a),e.SafeString=l.default,e.Exception=i.default,e.Utils=s,e.escapeExpression=s.escapeExpression,e.VM=u,e.template=function(t){return u.template(t,e)},e}var f=p();f.create=p,c.default(f),f.default=f,t.default=f,e.exports=t.default},387:(e,t,r)=>{"use strict";function o(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.HandlebarsEnvironment=p;var n=r(456),a=o(r(564)),l=r(880),i=r(103),s=o(r(677)),u=r(352);t.VERSION="4.7.8",t.COMPILER_REVISION=8,t.LAST_COMPATIBLE_COMPILER_REVISION=7,t.REVISION_CHANGES={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 <4.3.0",8:">= 4.3.0"};var c="[object Object]";function p(e,t,r){this.helpers=e||{},this.partials=t||{},this.decorators=r||{},l.registerDefaultHelpers(this),i.registerDefaultDecorators(this)}p.prototype={constructor:p,logger:s.default,log:s.default.log,registerHelper:function(e,t){if(n.toString.call(e)===c){if(t)throw new a.default("Arg not supported with multiple helpers");n.extend(this.helpers,e)}else this.helpers[e]=t},unregisterHelper:function(e){delete this.helpers[e]},registerPartial:function(e,t){if(n.toString.call(e)===c)n.extend(this.partials,e);else{if(void 0===t)throw new a.default('Attempting to register a partial called "'+e+'" as undefined');this.partials[e]=t}},unregisterPartial:function(e){delete this.partials[e]},registerDecorator:function(e,t){if(n.toString.call(e)===c){if(t)throw new a.default("Arg not supported with multiple decorators");n.extend(this.decorators,e)}else this.decorators[e]=t},unregisterDecorator:function(e){delete this.decorators[e]},resetLoggedPropertyAccesses:function(){u.resetLoggedProperties()}};var f=s.default.log;t.log=f,t.createFrame=n.createFrame,t.logger=s.default},103:(e,t,r)=>{"use strict";t.__esModule=!0,t.registerDefaultDecorators=function(e){n.default(e)};var o,n=(o=r(731))&&o.__esModule?o:{default:o}},731:(e,t,r)=>{"use strict";t.__esModule=!0;var o=r(456);t.default=function(e){e.registerDecorator("inline",(function(e,t,r,n){var a=e;return t.partials||(t.partials={},a=function(n,a){var l=r.partials;r.partials=o.extend({},l,t.partials);var i=e(n,a);return r.partials=l,i}),t.partials[n.args[0]]=n.fn,a}))},e.exports=t.default},564:(e,t)=>{"use strict";t.__esModule=!0;var r=["description","fileName","lineNumber","endLineNumber","message","name","number","stack"];function o(e,t){var n=t&&t.loc,a=void 0,l=void 0,i=void 0,s=void 0;n&&(a=n.start.line,l=n.end.line,i=n.start.column,s=n.end.column,e+=" - "+a+":"+i);for(var u=Error.prototype.constructor.call(this,e),c=0;c{"use strict";function o(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.registerDefaultHelpers=function(e){n.default(e),a.default(e),l.default(e),i.default(e),s.default(e),u.default(e),c.default(e)},t.moveHelperToHooks=function(e,t,r){e.helpers[t]&&(e.hooks[t]=e.helpers[t],r||delete e.helpers[t])};var n=o(r(582)),a=o(r(646)),l=o(r(170)),i=o(r(264)),s=o(r(233)),u=o(r(205)),c=o(r(331))},582:(e,t,r)=>{"use strict";t.__esModule=!0;var o=r(456);t.default=function(e){e.registerHelper("blockHelperMissing",(function(t,r){var n=r.inverse,a=r.fn;if(!0===t)return a(this);if(!1===t||null==t)return n(this);if(o.isArray(t))return t.length>0?(r.ids&&(r.ids=[r.name]),e.helpers.each(t,r)):n(this);if(r.data&&r.ids){var l=o.createFrame(r.data);l.contextPath=o.appendContextPath(r.data.contextPath,r.name),r={data:l}}return a(t,r)}))},e.exports=t.default},646:(e,t,r)=>{"use strict";t.__esModule=!0;var o,n=r(456),a=(o=r(564))&&o.__esModule?o:{default:o};t.default=function(e){e.registerHelper("each",(function(e,t){if(!t)throw new a.default("Must pass iterator to #each");var r,o=t.fn,l=t.inverse,i=0,s="",u=void 0,c=void 0;function p(t,r,a){u&&(u.key=t,u.index=r,u.first=0===r,u.last=!!a,c&&(u.contextPath=c+t)),s+=o(e[t],{data:u,blockParams:n.blockParams([e[t],t],[c+t,null])})}if(t.data&&t.ids&&(c=n.appendContextPath(t.data.contextPath,t.ids[0])+"."),n.isFunction(e)&&(e=e.call(this)),t.data&&(u=n.createFrame(t.data)),e&&"object"==typeof e)if(n.isArray(e))for(var f=e.length;i{"use strict";t.__esModule=!0;var o,n=(o=r(564))&&o.__esModule?o:{default:o};t.default=function(e){e.registerHelper("helperMissing",(function(){if(1!==arguments.length)throw new n.default('Missing helper: "'+arguments[arguments.length-1].name+'"')}))},e.exports=t.default},264:(e,t,r)=>{"use strict";t.__esModule=!0;var o,n=r(456),a=(o=r(564))&&o.__esModule?o:{default:o};t.default=function(e){e.registerHelper("if",(function(e,t){if(2!=arguments.length)throw new a.default("#if requires exactly one argument");return n.isFunction(e)&&(e=e.call(this)),!t.hash.includeZero&&!e||n.isEmpty(e)?t.inverse(this):t.fn(this)})),e.registerHelper("unless",(function(t,r){if(2!=arguments.length)throw new a.default("#unless requires exactly one argument");return e.helpers.if.call(this,t,{fn:r.inverse,inverse:r.fn,hash:r.hash})}))},e.exports=t.default},233:(e,t)=>{"use strict";t.__esModule=!0,t.default=function(e){e.registerHelper("log",(function(){for(var t=[void 0],r=arguments[arguments.length-1],o=0;o{"use strict";t.__esModule=!0,t.default=function(e){e.registerHelper("lookup",(function(e,t,r){return e?r.lookupProperty(e,t):e}))},e.exports=t.default},331:(e,t,r)=>{"use strict";t.__esModule=!0;var o,n=r(456),a=(o=r(564))&&o.__esModule?o:{default:o};t.default=function(e){e.registerHelper("with",(function(e,t){if(2!=arguments.length)throw new a.default("#with requires exactly one argument");n.isFunction(e)&&(e=e.call(this));var r=t.fn;if(n.isEmpty(e))return t.inverse(this);var o=t.data;return t.data&&t.ids&&((o=n.createFrame(t.data)).contextPath=n.appendContextPath(t.data.contextPath,t.ids[0])),r(e,{data:o,blockParams:n.blockParams([e],[o&&o.contextPath])})}))},e.exports=t.default},955:(e,t,r)=>{"use strict";t.__esModule=!0,t.createNewLookupObject=function(){for(var e=arguments.length,t=Array(e),r=0;r{"use strict";t.__esModule=!0,t.createProtoAccessControl=function(e){var t=Object.create(null);t.constructor=!1,t.__defineGetter__=!1,t.__defineSetter__=!1,t.__lookupGetter__=!1;var r=Object.create(null);return r.__proto__=!1,{properties:{whitelist:n.createNewLookupObject(r,e.allowedProtoProperties),defaultValue:e.allowProtoPropertiesByDefault},methods:{whitelist:n.createNewLookupObject(t,e.allowedProtoMethods),defaultValue:e.allowProtoMethodsByDefault}}},t.resultIsAllowed=function(e,t,r){return function(e,t){return void 0!==e.whitelist[t]?!0===e.whitelist[t]:void 0!==e.defaultValue?e.defaultValue:(function(e){!0!==l[e]&&(l[e]=!0,a.default.log("error",'Handlebars: Access has been denied to resolve the property "'+e+'" because it is not an "own property" of its parent.\nYou can add a runtime option to disable the check or this warning:\nSee https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details'))}(t),!1)}("function"==typeof e?t.methods:t.properties,r)},t.resetLoggedProperties=function(){Object.keys(l).forEach((function(e){delete l[e]}))};var o,n=r(955),a=(o=r(677))&&o.__esModule?o:{default:o},l=Object.create(null)},423:(e,t)=>{"use strict";t.__esModule=!0,t.wrapHelper=function(e,t){return"function"!=typeof e?e:function(){return arguments[arguments.length-1]=t(arguments[arguments.length-1]),e.apply(this,arguments)}}},677:(e,t,r)=>{"use strict";t.__esModule=!0;var o=r(456),n={methodMap:["debug","info","warn","error"],level:"info",lookupLevel:function(e){if("string"==typeof e){var t=o.indexOf(n.methodMap,e.toLowerCase());e=t>=0?t:parseInt(e,10)}return e},log:function(e){if(e=n.lookupLevel(e),"undefined"!=typeof console&&n.lookupLevel(n.level)<=e){var t=n.methodMap[e];console[t]||(t="log");for(var r=arguments.length,o=Array(r>1?r-1:0),a=1;a{"use strict";t.__esModule=!0,t.default=function(e){"object"!=typeof globalThis&&(Object.prototype.__defineGetter__("__magic__",(function(){return this})),__magic__.globalThis=__magic__,delete Object.prototype.__magic__);var t=globalThis.Handlebars;e.noConflict=function(){return globalThis.Handlebars===e&&(globalThis.Handlebars=t),e}},e.exports=t.default},433:(e,t,r)=>{"use strict";t.__esModule=!0,t.checkRevision=function(e){var t=e&&e[0]||1,r=l.COMPILER_REVISION;if(!(t>=l.LAST_COMPATIBLE_COMPILER_REVISION&&t<=l.COMPILER_REVISION)){if(t{"use strict";function r(e){this.string=e}t.__esModule=!0,r.prototype.toString=r.prototype.toHTML=function(){return""+this.string},t.default=r,e.exports=t.default},456:(e,t)=>{"use strict";t.__esModule=!0,t.extend=l,t.indexOf=function(e,t){for(var r=0,o=e.length;r":">",'"':""","'":"'","`":"`","=":"="},o=/[&<>"'`=]/g,n=/[&<>"'`=]/;function a(e){return r[e]}function l(e){for(var t=1;t{e.exports=r(916).default},768:(e,t,r)=>{var o=r(128),n={};o.registerHelper("h1",(function(e){return new o.SafeString(`

${e.fn(this)}

`)})),o.registerHelper("italic",(function(e){return new o.SafeString(`${e.fn(this)}`)})),o.registerHelper("bold",(function(e){return new o.SafeString(`${e.fn(this)}`)})),o.partials.footer=o.template({compiler:[8,">= 4.3.0"],main:function(e,t,r,o,n){return"
-= FOOTER =-
\n"},useData:!0});var a={1:function(e,t,r,o,n){return"Header"},3:function(e,t,r,o,n){return"Hello"},5:function(e,t,r,o,n){var a,l=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]};return e.escapeExpression("function"==typeof(a=null!=(a=l(r,"helloName")||(null!=t?l(t,"helloName"):t))?a:e.hooks.helperMissing)?a.call(null!=t?t:e.nullContext||{},{name:"helloName",hash:{},data:n,loc:{start:{line:2,column:40},end:{line:2,column:53}}}):a)},compiler:[8,">= 4.3.0"],main:function(e,t,r,o,n){var a,l,i,s=null!=t?t:e.nullContext||{},u=e.hooks.helperMissing,c="function",p=e.hooks.blockHelperMissing,f=e.lookupProperty||function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]},d="";return l=null!=(l=f(r,"h1")||(null!=t?f(t,"h1"):t))?l:u,i={name:"h1",hash:{},fn:e.program(1,n,0),inverse:e.noop,data:n,loc:{start:{line:1,column:0},end:{line:1,column:20}}},a=typeof l===c?l.call(s,i):l,f(r,"h1")||(a=p.call(t,a,i)),null!=a&&(d+=a),d+="\n

",l=null!=(l=f(r,"italic")||(null!=t?f(t,"italic"):t))?l:u,i={name:"italic",hash:{},fn:e.program(3,n,0),inverse:e.noop,data:n,loc:{start:{line:2,column:3},end:{line:2,column:30}}},a=typeof l===c?l.call(s,i):l,f(r,"italic")||(a=p.call(t,a,i)),null!=a&&(d+=a),d+=" ",l=null!=(l=f(r,"bold")||(null!=t?f(t,"bold"):t))?l:u,i={name:"bold",hash:{},fn:e.program(5,n,0),inverse:e.noop,data:n,loc:{start:{line:2,column:31},end:{line:2,column:62}}},a=typeof l===c?l.call(s,i):l,f(r,"bold")||(a=p.call(t,a,i)),null!=a&&(d+=a),d+"!

\n"+(null!=(a=e.invokePartial(f(o,"footer"),t,{name:"footer",data:n,helpers:r,partials:o,decorators:e.decorators}))?a:"")},usePartial:!0,useData:!0};e.exports=e=>(o.default||o).template(a)(Object.assign({},n,e))}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=r(768),t=r.n(e);document.getElementById("app").innerHTML=t()({helloName:"World"}),console.log(">> app")})()})(); \ No newline at end of file diff --git a/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/app.hbs b/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/app.hbs index 0a4e5961..37bcf423 100644 --- a/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/app.hbs +++ b/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/app.hbs @@ -1,2 +1,3 @@ -

Hello {{#bold}}{{helloName}}{{/bold}}!

+{{#h1}}Header{{/h1}} +

{{#italic}}Hello{{/italic}} {{#bold}}{{helloName}}{{/bold}}!

{{> 'footer'}} diff --git a/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/helpers-esm/html-helpers.js b/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/helpers-esm/html-helpers.js new file mode 100644 index 00000000..99306a8f --- /dev/null +++ b/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/helpers-esm/html-helpers.js @@ -0,0 +1,10 @@ +//import Handlebars from 'handlebars'; // not works! +const Handlebars = require('handlebars'); + +export const h1 = function (options) { + return new Handlebars.SafeString(`

${options.fn(this)}

`); +}; + +export const italic = function (options) { + return new Handlebars.SafeString(`${options.fn(this)}`); +}; diff --git a/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/webpack.config.js b/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/webpack.config.js index f7f9f579..3577af50 100644 --- a/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/webpack.config.js +++ b/test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/webpack.config.js @@ -1,6 +1,7 @@ const path = require('path'); const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin'); const Handlebars = require('handlebars'); +import { h1, italic } from './src/helpers-esm/html-helpers'; module.exports = { mode: 'production', @@ -23,12 +24,16 @@ module.exports = { preprocessor: 'handlebars', preprocessorOptions: { - //knownHelpersOnly: false, - // define helpers manually + // define helpers as an object helpers: { // WARNING: don't use the arrow function with `this` otherwise webpack compile `this` into `void 0` //bold: (options) => new Handlebars.SafeString(`${options.fn(this)}`), + // imported helpers + h1, + italic, + + // helper defined as the function bold(options) { return new Handlebars.SafeString(`${options.fn(this)}`); },