Skip to content

Commit

Permalink
Merge pull request #12445 from rwjblue/fix-rest-style-positional-params
Browse files Browse the repository at this point in the history
[BUGFIX release] Ensure rest arg positionalParams can be omitted.
  • Loading branch information
rwjblue committed Oct 6, 2015
2 parents 23258c1 + d34aa11 commit e7ba39a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ function processNamedPositionalParameters(renderNode, positionalParams, params,
}

function processRestPositionalParameters(renderNode, positionalParamsName, params, attrs) {
let nameInAttrs = positionalParamsName in attrs;

// when no params are used, do not override the specified `attrs.stringParamName` value
if (params.length === 0 && nameInAttrs) {
return;
}

// If there is already an attribute for that variable, do nothing
assert(`You cannot specify positional parameters and the hash argument \`${positionalParamsName}\`.`,
!(positionalParamsName in attrs));
!nameInAttrs);

let paramsStream = new Stream(() => {
return readArray(params.slice(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,57 @@ QUnit.test('arbitrary positional parameter conflict with hash parameter is repor
}, `You cannot specify positional parameters and the hash argument \`names\`.`);
});

QUnit.test('can use hash parameter instead of arbitrary positional param [GH #12444]', function() {
var SampleComponent = Component.extend();
SampleComponent.reopenClass({
positionalParams: 'names'
});

registry.register('template:components/sample-component', compile('{{#each attrs.names as |name|}}{{name}}{{/each}}'));
registry.register('component:sample-component', SampleComponent);

view = EmberView.extend({
layout: compile('{{sample-component names=things id="args-3"}}'),
container: container,
context: {
things: ['Foo', 4, 'Bar']
}
}).create();

runAppend(view);

equal(view.$('#args-3').text(), 'Foo4Bar');
});

QUnit.test('can use hash parameter instead of positional param', function() {
var SampleComponent = Component.extend();
SampleComponent.reopenClass({
positionalParams: ['first', 'second']
});

registry.register('template:components/sample-component', compile('{{attrs.first}} - {{attrs.second}}'));
registry.register('component:sample-component', SampleComponent);

view = EmberView.extend({
layout: compile(`
{{sample-component "one" "two" id="two-positional"}}
{{sample-component "one" second="two" id="one-positional"}}
{{sample-component first="one" second="two" id="no-positional"}}
`),
container: container,
context: {
things: ['Foo', 4, 'Bar']
}
}).create();

runAppend(view);

equal(view.$('#two-positional').text(), 'one - two');
equal(view.$('#one-positional').text(), 'one - two');
equal(view.$('#no-positional').text(), 'one - two');
});

QUnit.test('dynamic arbitrary number of positional parameters', function() {
var SampleComponent = Component.extend();
SampleComponent.reopenClass({
Expand Down

0 comments on commit e7ba39a

Please sign in to comment.