-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX beta] - expanded syntax error for if handlebars helper to inc…
…lude source of error
- Loading branch information
1 parent
caca9d8
commit 2add803
Showing
4 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/ember-template-compiler/lib/plugins/assert-if-helper-without-arguments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { assert } from 'ember-debug'; | ||
import calculateLocationDisplay from '../system/calculate-location-display'; | ||
|
||
export default function assertIfHelperWithoutArguments(env) { | ||
let { moduleName } = env.meta; | ||
|
||
return { | ||
name: 'assert-if-helper-without-arguments', | ||
|
||
visitor: { | ||
BlockStatement(node) { | ||
if (isInvalidBlockIf(node)) { | ||
assert(`${blockAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`); | ||
} | ||
}, | ||
|
||
MustacheStatement(node) { | ||
if (isInvalidInlineIf(node)) { | ||
assert(`${inlineAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`); | ||
} | ||
}, | ||
|
||
SubExpression(node) { | ||
if (isInvalidInlineIf(node)) { | ||
assert(`${inlineAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`); | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
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 < 2 || node.params.length > 3); | ||
} | ||
|
||
function isInvalidBlockIf(node) { | ||
return node.path.original === 'if' && (!node.params || node.params.length !== 1); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/ember-template-compiler/tests/plugins/assert-if-helper-without-arguments-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { compile } from '../../index'; | ||
import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; | ||
|
||
moduleFor('ember-template-compiler: assert-if-helper-without-argument', class extends AbstractTestCase { | ||
[`@test block if helper expects one argument`]() { | ||
expectAssertion(() => { | ||
compile(`{{#if}}aVal{{/if}}`, { | ||
moduleName: 'baz/foo-bar' | ||
}); | ||
}, `#if requires a single argument. ('baz/foo-bar' @ L1:C0) `); | ||
|
||
expectAssertion(() => { | ||
compile(`{{#if val1 val2}}aVal{{/if}}`, { | ||
moduleName: 'baz/foo-bar' | ||
}); | ||
}, `#if requires a single argument. ('baz/foo-bar' @ L1:C0) `); | ||
|
||
expectAssertion(() => { | ||
compile(`{{#if}}aVal{{/if}}`, { | ||
moduleName: 'baz/foo-bar' | ||
}); | ||
}, `#if requires a single argument. ('baz/foo-bar' @ L1:C0) `); | ||
} | ||
|
||
[`@test inline if helper expects between one and three arguments`]() { | ||
expectAssertion(() => { | ||
compile(`{{if}}`, { | ||
moduleName: 'baz/foo-bar' | ||
}); | ||
}, `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' | ||
}); | ||
} | ||
|
||
['@test subexpression if helper expects between one and three arguments']() { | ||
expectAssertion(() => { | ||
compile(`{{input foo=(if)}}`, { | ||
moduleName: 'baz/foo-bar' | ||
}); | ||
}, `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' | ||
}); | ||
} | ||
|
||
}); | ||
|