canjs / can-stache

Live binding handlebars templates
https://canjs.com/doc/can-stache.html
MIT License
10 stars 13 forks source link

Passing a type boolean variable to an addHelper function causes errors #631

Open MarcGodard opened 5 years ago

MarcGodard commented 5 years ago

How often can you reproduce it?

Description:

Passing a variable of type boolean to an adHelper function causes errors.

Steps to reproduce:

Create a model with variable type boolean. Populate model. Create an addHelper function. Loop over model list while passing values to an addHelper (haven't tested without the loop).

{{#each(row)}}
     {{someHelper(booleanVariable)}}
{{/each}}

with

stache.addHelper('someHelper', (booleanVariable) => {
     if (booleanVariable) return 'true'
     else return 'false'
})

Error:

can-log.js:98 RangeError: Maximum call stack size exceeded
    at Object.hydrateAst (expression.js:1)
    at Object.hydrateAst (expression.js:315)
    at Object.hydrateAst (expression.js:263)
    at Object.hydrateAst (expression.js:315)
    at Object.hydrateAst (expression.js:263)
    at Object.hydrateAst (expression.js:315)
    at Object.hydrateAst (expression.js:263)
    at Object.hydrateAst (expression.js:315)
    at Object.hydrateAst (expression.js:263)
    at Object.hydrateAst (expression.js:315)

Expected results:

Should cast the type boolean and work :)

Actual results:

The error above.

Environment:

Software Version
can-stache version 5.16.5
Browser Chrome
Operating system Mac os
Node v8.12.0
chasenlehara commented 5 years ago

@MarcGodard Any chance you have a runnable code example or could make one (CodePen, etc.)?

MarcGodard commented 5 years ago

@chasenlehara I have never made a codePen for canjs. You have an example? I am a donejs user.

justinbmeyer commented 5 years ago

Much of the canjs site has been updated to run examples in codepen. I’d look here for a stache/component example you can start from: https://canjs.com/doc/guides/html.html

Can-stache’s docs also have codepens too

chasenlehara commented 5 years ago

The Setting Up CanJS page also has a starter CodePen (click on the Edit on CodePen button in the top right of the embedded pen): https://canjs.com/doc/guides/setup.html#OnlineCodeEditors