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 3, 2019
1 parent 6a25167 commit 800dab3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/@ember/-internals/metal/lib/tags.ts
Expand Up @@ -22,7 +22,8 @@ function makeTag(): TagWrapper<DirtyableTag> {
}

export function tagForProperty(object: any, propertyKey: string | symbol, _meta?: Meta): Tag {
if (typeof object !== 'object' || object === null) {
let objectType = typeof object;
if (objectType !== 'function' && (objectType !== 'object' || object === null)) {
return CONSTANT_TAG;
}
let meta = _meta === undefined ? metaFor(object) : _meta;
Expand Down
19 changes: 19 additions & 0 deletions packages/@ember/-internals/metal/tests/computed_decorator_test.js
Expand Up @@ -70,6 +70,25 @@ if (EMBER_NATIVE_DECORATOR_SUPPORT) {
get(obj, 'fullName');
}

['@test computed property can be defined and accessed on a class constructor'](assert) {
let count = 0;

class Obj {
static bar = 123;

@computed
static get foo() {
count++;
return this.bar;
}
}

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

assert.equal(count, 1, 'should only call getter once');
}

['@test it works with computed desc'](assert) {
assert.expect(4);

Expand Down
19 changes: 19 additions & 0 deletions packages/@ember/-internals/metal/tests/computed_test.js
Expand Up @@ -82,6 +82,25 @@ moduleFor(
assert.equal(count, 1, 'should have invoked computed property');
}

['@test computed property can be defined and accessed on a class constructor'](assert) {
let count = 0;

let Obj = EmberObject.extend();
Obj.reopenClass({
bar: 123,

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

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

assert.equal(count, 1, 'should only call getter once');
}

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

Expand Down

0 comments on commit 800dab3

Please sign in to comment.