Skip to content

Commit

Permalink
[BUGFIX beta] Made sure inline if fails without two or three arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTraher committed Mar 8, 2018
1 parent 5720135 commit db83e0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ moduleFor('Helpers test: inline {{if}}', class extends IfUnlessHelperTest {
['@test it raises when there are more than three arguments']() {
expectAssertion(() => {
this.render(`{{if condition 'a' 'b' 'c'}}`, { condition: true });
}, /The inline form of the `if` helper expects two or three arguments/);
}, `The inline form of the 'if' helper expects two or three arguments. ('-top-level' @ L1:C0) `);
}

['@test it raises when there are less than two arguments']() {
expectAssertion(() => {
this.render(`{{if condition}}`, { condition: true });
}, /The inline form of the `if` helper expects two or three arguments/);
}, `The inline form of the 'if' helper expects two or three arguments. ('-top-level' @ L1:C0) `);
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,35 @@ export default function assertIfHelperWithoutArguments(env) {
visitor: {
BlockStatement(node) {
if (isInvalidBlockIf(node)) {
assert(`#${assertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
assert(`${blockAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
}
},

MustacheStatement(node) {
if (isInvalidInlineIf(node)) {
assert(`#${assertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
assert(`${inlineAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
}
},

SubExpression(node) {
if (isInvalidInlineIf(node)) {
assert(`#${assertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
assert(`${inlineAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
}
}
}
};
}

function assertMessage(original) {
return `${original} requires a single argument.`;
function blockAssertMessage(original) {
return `#${original} requires a single argument.`;
}

function inlineAssertMessage(original) {
return `The inline form of the '${original}' helper expects two or three arguments.`;
}

function isInvalidInlineIf(node) {
return node.path.original === 'if' && (!node.params || node.params.length < 1);
return node.path.original === 'if' && (!node.params || node.params.length < 2 || node.params.length > 3);
}

function isInvalidBlockIf(node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ moduleFor('ember-template-compiler: assert-if-helper-without-argument', class ex
compile(`{{if}}`, {
moduleName: 'baz/foo-bar'
});
}, `#if requires a single argument. ('baz/foo-bar' @ L1:C0) `);
}, `The inline form of the 'if' helper expects two or three arguments. ('baz/foo-bar' @ L1:C0) `);

compile(`{{if foo bar baz}}`, {
moduleName: 'baz/foo-bar'
Expand All @@ -39,7 +39,7 @@ moduleFor('ember-template-compiler: assert-if-helper-without-argument', class ex
compile(`{{input foo=(if)}}`, {
moduleName: 'baz/foo-bar'
});
}, `#if requires a single argument. ('baz/foo-bar' @ L1:C12) `);
}, `The inline form of the 'if' helper expects two or three arguments. ('baz/foo-bar' @ L1:C12) `);

compile(`{{some-thing foo=(if foo bar baz)}}`, {
moduleName: 'baz/foo-bar'
Expand Down

0 comments on commit db83e0e

Please sign in to comment.