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

Update HelperExpression to be able to evaluate nodes without params a… #1055

Closed

Conversation

chrisrink
Copy link

Update HelperExpression to be able to evaluate nodes without params attribute.

I want to be able to traverse the entire AST and check if each node/param/hash is a helper or not. This currently blows up on literals that don't have params.

@chrisrink
Copy link
Author

Actually, this is not right either as a Helper could be a MustacheStatement or BlockStatement. I did notice that the path object of the statement seems to only exist for helper statements. So I modified it as such:

 return !!((statement.path && (statement.type === 'SubExpression' || statement.params && statement.params.length) || statement.hash));

Seems a little hacky though so there might be a more concise way to handle this.

@kpdecker
Copy link
Collaborator

Please update the PR with what you'd like to see and include test cases. I'm all for bulletproofing the code where it's making unsafe assumptions.

@kpdecker
Copy link
Collaborator

(Comment here when you've updated as otherwise we might not see the changes)

@kpdecker kpdecker added this to the Next milestone Aug 3, 2015
@kpdecker kpdecker closed this in 93b0760 Aug 4, 2015
@kpdecker
Copy link
Collaborator

kpdecker commented Aug 4, 2015

@chrisrink thanks for the initial work here. Just landed a patch the fixes this in master.

flenter pushed a commit to flenter/handlebars.js that referenced this pull request Aug 27, 2015
Avoid undefined values and potential false positives from other type values such as partials.

Fixes handlebars-lang#1055
@chrisrink
Copy link
Author

Great news! I think this should work. One last thing to check. I have actually been using the below statement.

        return !!((statement.path && statement.path.original) && (statement.type === 'SubExpression' || (statement.params && statement.params.length) || statement.hash));

And this seems to be working for me. So I just wanted to double check that the statement.path and statement.path.original parts would be caught in Mustache and Block statement calls.

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

Successfully merging this pull request may close these issues.

3 participants