FIX: Correctly process {{each}} in raw handlebars templates for themes

FIX: Correctly process {{each}} in raw handlebars templates for themes

diff --git a/lib/theme_javascript_compiler.rb b/lib/theme_javascript_compiler.rb
index d5a11ca..e01d7a6 100644
--- a/lib/theme_javascript_compiler.rb
+++ b/lib/theme_javascript_compiler.rb
@@ -54,7 +54,7 @@ class ThemeJavascriptCompiler
 
       function manipulatePath(path) {
         // Override old themeSetting syntax when it's a param inside another node
-        if(path.parts[0] == "themeSettings"){
+        if(path.parts && path.parts[0] == "themeSettings"){
           const settingParts = path.parts.slice(1);
           path.type = "SubExpression";
           Object.assign(path, generateHelper(settingParts))
@@ -63,7 +63,7 @@ class ThemeJavascriptCompiler
 
       function manipulateNode(node) {
         // Magically add theme id as the first param for each of these helpers
-        if (["theme-i18n", "theme-prefix", "theme-setting"].includes(node.path.parts[0])) {
+        if (node.path.parts && ["theme-i18n", "theme-prefix", "theme-setting"].includes(node.path.parts[0])) {
           node.params.unshift({
             type: "NumberLiteral",
             value: #{@theme_id},
@@ -72,7 +72,7 @@ class ThemeJavascriptCompiler
         }
 
         // Override old themeSetting syntax when it's in its own node
-        if (node.path.parts[0] == "themeSettings") {
+        if (node.path.parts && node.path.parts[0] == "themeSettings") {
           Object.assign(node, generateHelper(node.path.parts.slice(1)))
         }
       }
@@ -100,6 +100,7 @@ class ThemeJavascriptCompiler
             if(node.path.original == 'get'
               && node.params
               && node.params[0]
+              && node.params[0].parts
               && node.params[0].parts[0] == 'themeSettings'){
                 node.path.parts = node.params[0].parts
                 node.params = []

GitHub sha: b88aa4a5

1 Like

Is this worth #cherry-pick ing for 2.1 ?

Yes we can do - I wasn’t too sure what the threshold is for backporting, we’ve had quite a few FIX: commits since the release

2 Likes