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

If syntax error message #16326

Merged

Conversation

AlexTraher
Copy link
Contributor

This (hopefully) resolves issue 16322 regarding an unclear error message when passing an incorrect number of arguments to an if helper.

@AlexTraher AlexTraher changed the title Alextraher/if syntax error message If syntax error message Mar 6, 2018
Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks for picking this up!

I left some inline comments (mostly just moving from assert.throws to expectAssertion which should fix an issue with the production build), but would also like to see some tests added confirming a few additional scenarios work:

  • {{some-thing foo=(if)}} should error
  • {{some-thing foo=(if foo bar baz)}} should not error
  • {{if foo bar baz}} should not error


moduleFor('ember-template-compiler: assert-if-helper-without-argument', class extends AbstractTestCase {
[`@test block if helper expects one argument`](assert) {
assert.throws(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be expectAssertion

});
}, `#if requires a single argument. ('baz/foo-bar' @ L1:C0) `);

assert.throws(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectAssertion

}

[`@test inline if helper expects between one and three arguments`](assert) {
assert.throws(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectAssertion

}

function isInvalidInlineIf(node) {
return node.path.original === 'if' && (!node.params || node.params.length < 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the minimum length be 2? I'm not sure how something like {{if something}} is useful (e.g. if there is no truthy or falsey argument, what is even happening?)...

What do you think @AlexTraher?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue Yeah agreed - I like the idea it fails loudly.

@rwjblue
Copy link
Member

rwjblue commented Mar 8, 2018

Looks great! Can you squash down to a single commit?

@AlexTraher AlexTraher force-pushed the alextraher/if-syntax-error-message branch from db83e0e to 2add803 Compare March 8, 2018 13:08
Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job here, thank you very much!

@rwjblue rwjblue merged commit a28755d into emberjs:master Mar 8, 2018
@AlexTraher
Copy link
Contributor Author

Thanks for making the time to give feedback! 👍

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.

Unhelpful syntax error message
2 participants