Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested #if / #each generates TypeError #1221

Closed
davidkellerman opened this issue May 13, 2016 · 3 comments
Closed

Nested #if / #each generates TypeError #1221

davidkellerman opened this issue May 13, 2016 · 3 comments

Comments

@davidkellerman
Copy link

Here's a short example that generates the error:

var handlebars = require('handlebars');

var template = handlebars.compile(
    '{{#each files.primary as |file|}}\n\
    {{{file.oldFile}}} {{{file.newFile}}}\n\
    {{/each}}\n\
    {{#if files.secondary.length}}\n\
    {{#each files.secondary as |file|}}\n\
    {{{file.oldFile}}} {{{file.newFile}}}\n\
    {{/each}}\n\
    {{/if}}');

var config = {
    files: {
        primary: [ { oldFile: 'old.txt', newFile: 'new.txt' } ],
        secondary: [ { oldFile: 'old.txt', newFile: 'new.txt' } ] }
    };

var rslt = template(config);

console.log(rslt);

Run in node, it produces this console output:

undefined:6
    + ((stack1 = alias1(((stack1 = blockParams[0][0]) != null ? stack1.oldFile : stack1), depth0)) != null ? stack1 : "")
                                              ^

TypeError: Cannot read property '0' of undefined
    at eval (eval at createFunctionContext (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:6:47)
    at prog (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/runtime.js:219:12)
    at execIteration (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:51:19)
    at Object.<anonymous> (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:61:13)
    at eval (eval at createFunctionContext (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:5:34)
    at Object.prog [as fn] (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/runtime.js:219:12)
    at Object.<anonymous> (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/helpers/if.js:19:22)
    at Object.eval (eval at createFunctionContext (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:6:32)
    at main (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:32)
    at ret (/www.nls.com/nodejs/usr-share-nodejs/www/util/printkit-config/node_modules/handlebars/dist/cjs/handlebars/runtime.js:176:12)

Any of these changes cause the error to go away:

  1. Removing the first #each clause from the template
  2. Removing the #if clause from the template
  3. Removing the {{{file.oldFile}}} expansion from the second #each clause, or replacing it with {{oldFile}}

Here's a fiddle with essentially the same example. The console output reports a slightly different error (in Firefox: TypeError: blockParams is undefined).

@nikjuice
Copy link

Have the same issue, put a comment here -
#1250

@nknapp
Copy link
Collaborator

nknapp commented May 14, 2017

Does this issue still exist? If it had the same cause as #1250, it should have been fixed in the meantime (i.e. since 4.0.6). If it is related to #1300, it is probably still there. Could anybody check?

@davidkellerman
Copy link
Author

I ran the example again. Fails with 4.0.5; succeeds with 4.0.6. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants