Skip to content

Commit

Permalink
Component and their templates should be normalized the same.
Browse files Browse the repository at this point in the history
The changes that landed in 35890e0 ensured that a component itself is not
normalized, but it did not account for components templates. The result was
that a given `{{fooBar}}` in a template would not find a `foo-bar` components
JS file, but it would find its template.
  • Loading branch information
rwjblue committed Aug 9, 2019
1 parent 6f9793b commit 422b1c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions addon/resolvers/classic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,26 @@ const Resolver = EmberObject.extend({

_normalize(fullName) {
// A) Convert underscores to dashes
// B) Convert camelCase to dash-case, except for components and helpers where we want to avoid shadowing camelCase expressions
// B) Convert camelCase to dash-case, except for components (their
// templates) and helpers where we want to avoid shadowing camelCase
// expressions
// C) replace `.` with `/` in order to make nested controllers work in the following cases
// 1. `needs: ['posts/post']`
// 2. `{{render "posts/post"}}`
// 3. `this.render('posts/post')` from Route

let split = fullName.split(':');
if (split.length > 1) {
if (split[0] === 'component' || split[0] === 'helper') {
return split[0] + ':' + split[1].replace(/_/g, '-');
let type = split[0];

if (
type === 'component' ||
type === 'helper' ||
(type === 'template' && split[1].indexOf('components/') === 0)
) {
return type + ':' + split[1].replace(/_/g, '-');
} else {
return split[0] + ':' + dasherize(split[1].replace(/\./g, '/'));
return type + ':' + dasherize(split[1].replace(/\./g, '/'));
}
} else {
return fullName;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/resolvers/classic/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ test('normalization', function(assert) {
// The same applies to components
assert.equal(resolver.normalize('component:fabulous-component'), 'component:fabulous-component');
assert.equal(resolver.normalize('component:fabulousComponent'), 'component:fabulousComponent');
assert.equal(resolver.normalize('template:components/fabulousComponent'), 'template:components/fabulousComponent');
});

test('normalization is idempotent', function(assert) {
Expand Down

0 comments on commit 422b1c7

Please sign in to comment.