Skip to content

Commit

Permalink
Merge pull request #14106 from rwjblue/do-not-assert-on-id
Browse files Browse the repository at this point in the history
[BUGFIX beta] Avoid assertion when `id=` is provided to tagless components.
  • Loading branch information
mixonic authored Aug 21, 2016
2 parents ac66e53 + 64a6853 commit 3ce9336
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ember-glimmer/lib/syntax/curly-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class CurlyComponentManager {

assert('You cannot use `elementId` on a tag-less component: ' + component.toString(), (() => {
let { elementId, tagName } = component;
return tagName !== '' || (!elementId && elementId !== '');
return tagName !== '' || props.id === elementId || (!elementId && elementId !== '');
})());

assert('You cannot use `attributeBindings` on a tag-less component: ' + component.toString(), (() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,41 @@ moduleFor('Components test: fragment components', class extends RenderingTest {
}, /You cannot use `elementId` on a tag-less component/);
}

['@test throws an error if `tagName` is an empty string and `elementId` is specified via template']() {
let template = `hit dem folks`;
let FooBarComponent = Component.extend({
tagName: ''
});

this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template });
expectAssertion(() => {
this.render(`{{#foo-bar elementId='turntUp'}}{{/foo-bar}}`);
}, /You cannot use `elementId` on a tag-less component/);
}

['@test does not throw an error if `tagName` is an empty string and `id` is specified via JS']() {
let template = `{{id}}`;
let FooBarComponent = Component.extend({
tagName: '',
id: 'baz'
});

this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template });
this.render(`{{#foo-bar}}{{/foo-bar}}`);
this.assertText('baz');
}

['@test does not throw an error if `tagName` is an empty string and `id` is specified via template']() {
let template = `{{id}}`;
let FooBarComponent = Component.extend({
tagName: ''
});

this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template });
this.render(`{{#foo-bar id='baz'}}{{/foo-bar}}`);
this.assertText('baz');
}

['@test throws an error if when $() is accessed on component where `tagName` is an empty string']() {
let template = `hit dem folks`;
let FooBarComponent = Component.extend({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function buildComponentTemplate({ component, tagName, layout, out

assert('You cannot use `elementId` on a tag-less component: ' + component.toString(), (() => {
let { elementId } = component;
return tagName !== '' || (!elementId && elementId !== '');
return tagName !== '' || attrs.id === elementId || (!elementId && elementId !== '');
})());

assert('You cannot use `attributeBindings` on a tag-less component: ' + component.toString(), (() => {
Expand Down

0 comments on commit 3ce9336

Please sign in to comment.