Skip to content

Commit

Permalink
[BUGFIX] Ensure tagForProperty works on class constructors
Browse files Browse the repository at this point in the history
`tagForProperty` was returning the constant tag for functions, which
meant it would return the constant tag for properties on class
constructors. If a computed property was defined on the class
constructor it would fail because of this.
  • Loading branch information
Chris Garrett committed Mar 2, 2019
1 parent 6a25167 commit 4d92a3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@ember/-internals/metal/lib/tags.ts
Expand Up @@ -22,7 +22,7 @@ function makeTag(): TagWrapper<DirtyableTag> {
}

export function tagForProperty(object: any, propertyKey: string | symbol, _meta?: Meta): Tag {
if (typeof object !== 'object' || object === null) {
if (typeof object !== 'function' && (typeof object !== 'object' || object === null)) {
return CONSTANT_TAG;
}
let meta = _meta === undefined ? metaFor(object) : _meta;
Expand Down
13 changes: 13 additions & 0 deletions packages/@ember/-internals/metal/tests/computed_test.js
Expand Up @@ -82,6 +82,19 @@ moduleFor(
assert.equal(count, 1, 'should have invoked computed property');
}

['@test computed property can be defined and accessed on a class constructor'](assert) {
let Obj = EmberObject.extend();
Obj.reopenClass({
bar: 123,

foo: computed(function() {
return this.bar;
}),
});

assert.equal(Obj.foo, '123', 'should return value');
}

['@test can override volatile computed property'](assert) {
let obj = {};

Expand Down

0 comments on commit 4d92a3d

Please sign in to comment.