From 4d92a3dda123590d5847446fc62cf46cbcd7102f Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Fri, 1 Mar 2019 21:45:23 -0800 Subject: [PATCH] [BUGFIX] Ensure tagForProperty works on class constructors `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. --- packages/@ember/-internals/metal/lib/tags.ts | 2 +- .../@ember/-internals/metal/tests/computed_test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/@ember/-internals/metal/lib/tags.ts b/packages/@ember/-internals/metal/lib/tags.ts index 845e2abc1b9..04103f52f7b 100644 --- a/packages/@ember/-internals/metal/lib/tags.ts +++ b/packages/@ember/-internals/metal/lib/tags.ts @@ -22,7 +22,7 @@ function makeTag(): TagWrapper { } 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; diff --git a/packages/@ember/-internals/metal/tests/computed_test.js b/packages/@ember/-internals/metal/tests/computed_test.js index 7f9ed038c8c..b0ef67325be 100644 --- a/packages/@ember/-internals/metal/tests/computed_test.js +++ b/packages/@ember/-internals/metal/tests/computed_test.js @@ -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 = {};