Skip to content

Commit 81dbb6c

Browse files
committed
all passing tests!
1 parent 03e53fb commit 81dbb6c

File tree

5 files changed

+39
-32
lines changed

5 files changed

+39
-32
lines changed

packages/@ember/-internals/metal/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export {
4747
ComputedDescriptor,
4848
type ElementDescriptor,
4949
isElementDescriptor,
50+
isDecoratorCall,
5051
nativeDescDecorator,
5152
descriptorForDecorator,
5253
descriptorForProperty,

packages/@ember/-internals/metal/lib/alias.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { ExtendedMethodDecorator } from './decorator';
1616
import {
1717
ComputedDescriptor,
1818
descriptorForDecorator,
19-
isElementDescriptor,
19+
isDecoratorCall,
2020
makeComputedDecorator,
2121
} from './decorator';
2222
import { defineProperty } from './properties';
@@ -28,7 +28,7 @@ export type AliasDecorator = ExtendedMethodDecorator & PropertyDecorator & Alias
2828
export default function alias(altKey: string): AliasDecorator {
2929
assert(
3030
'You attempted to use @alias as a decorator directly, but it requires a `altKey` parameter',
31-
!isElementDescriptor(Array.prototype.slice.call(arguments))
31+
!isDecoratorCall(Array.prototype.slice.call(arguments))
3232
);
3333

3434
// SAFETY: We passed in the impl for this class

packages/@ember/-internals/metal/lib/decorator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export function isElementDescriptor(args: unknown[]): args is ElementDescriptor
4242
);
4343
}
4444

45+
export function isDecoratorCall(
46+
args: unknown[]
47+
): args is ElementDescriptor | Parameters<Decorator> {
48+
return isElementDescriptor(args) || isModernDecoratorArgs(args);
49+
}
50+
4551
export function nativeDescDecorator(propertyDesc: PropertyDescriptor) {
4652
let decorator = function () {
4753
return propertyDesc;

packages/@ember/object/lib/computed/computed_macros.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computed, isElementDescriptor, alias, expandProperties } from '@ember/-internals/metal';
1+
import { computed, isDecoratorCall, alias, expandProperties } from '@ember/-internals/metal';
22
import { get, set } from '@ember/object';
33
import type { DeprecationOptions } from '@ember/debug';
44
import { assert, deprecate } from '@ember/debug';
@@ -33,7 +33,7 @@ function generateComputedWithPredicate(name: string, predicate: (value: unknown)
3333

3434
assert(
3535
`You attempted to use @${name} as a decorator directly, but it requires at least one dependent key parameter`,
36-
!isElementDescriptor(properties)
36+
!isDecoratorCall(properties)
3737
);
3838

3939
let dependentKeys = expandPropertiesToArray(name, properties);
@@ -98,7 +98,7 @@ function generateComputedWithPredicate(name: string, predicate: (value: unknown)
9898
export function empty(dependentKey: string) {
9999
assert(
100100
'You attempted to use @empty as a decorator directly, but it requires a `dependentKey` parameter',
101-
!isElementDescriptor(Array.prototype.slice.call(arguments))
101+
!isDecoratorCall(Array.prototype.slice.call(arguments))
102102
);
103103

104104
return computed(`${dependentKey}.length`, function () {
@@ -144,7 +144,7 @@ export function empty(dependentKey: string) {
144144
export function notEmpty(dependentKey: string) {
145145
assert(
146146
'You attempted to use @notEmpty as a decorator directly, but it requires a `dependentKey` parameter',
147-
!isElementDescriptor(Array.prototype.slice.call(arguments))
147+
!isDecoratorCall(Array.prototype.slice.call(arguments))
148148
);
149149

150150
return computed(`${dependentKey}.length`, function () {
@@ -187,7 +187,7 @@ export function notEmpty(dependentKey: string) {
187187
export function none(dependentKey: string) {
188188
assert(
189189
'You attempted to use @none as a decorator directly, but it requires a `dependentKey` parameter',
190-
!isElementDescriptor(Array.prototype.slice.call(arguments))
190+
!isDecoratorCall(Array.prototype.slice.call(arguments))
191191
);
192192

193193
return computed(dependentKey, function () {
@@ -229,7 +229,7 @@ export function none(dependentKey: string) {
229229
export function not(dependentKey: string) {
230230
assert(
231231
'You attempted to use @not as a decorator directly, but it requires a `dependentKey` parameter',
232-
!isElementDescriptor(Array.prototype.slice.call(arguments))
232+
!isDecoratorCall(Array.prototype.slice.call(arguments))
233233
);
234234

235235
return computed(dependentKey, function () {
@@ -277,7 +277,7 @@ export function not(dependentKey: string) {
277277
export function bool(dependentKey: string) {
278278
assert(
279279
'You attempted to use @bool as a decorator directly, but it requires a `dependentKey` parameter',
280-
!isElementDescriptor(Array.prototype.slice.call(arguments))
280+
!isDecoratorCall(Array.prototype.slice.call(arguments))
281281
);
282282

283283
return computed(dependentKey, function () {
@@ -323,7 +323,7 @@ export function bool(dependentKey: string) {
323323
export function match(dependentKey: string, regexp: RegExp) {
324324
assert(
325325
'You attempted to use @match as a decorator directly, but it requires `dependentKey` and `regexp` parameters',
326-
!isElementDescriptor(Array.prototype.slice.call(arguments))
326+
!isDecoratorCall(Array.prototype.slice.call(arguments))
327327
);
328328

329329
return computed(dependentKey, function () {
@@ -369,7 +369,7 @@ export function match(dependentKey: string, regexp: RegExp) {
369369
export function equal(dependentKey: string, value: unknown) {
370370
assert(
371371
'You attempted to use @equal as a decorator directly, but it requires `dependentKey` and `value` parameter',
372-
!isElementDescriptor(Array.prototype.slice.call(arguments))
372+
!isDecoratorCall(Array.prototype.slice.call(arguments))
373373
);
374374

375375
return computed(dependentKey, function () {
@@ -414,7 +414,7 @@ export function equal(dependentKey: string, value: unknown) {
414414
export function gt(dependentKey: string, value: number) {
415415
assert(
416416
'You attempted to use @gt as a decorator directly, but it requires `dependentKey` and `value` parameters',
417-
!isElementDescriptor(Array.prototype.slice.call(arguments))
417+
!isDecoratorCall(Array.prototype.slice.call(arguments))
418418
);
419419

420420
return computed(dependentKey, function () {
@@ -459,7 +459,7 @@ export function gt(dependentKey: string, value: number) {
459459
export function gte(dependentKey: string, value: number) {
460460
assert(
461461
'You attempted to use @gte as a decorator directly, but it requires `dependentKey` and `value` parameters',
462-
!isElementDescriptor(Array.prototype.slice.call(arguments))
462+
!isDecoratorCall(Array.prototype.slice.call(arguments))
463463
);
464464

465465
return computed(dependentKey, function () {
@@ -504,7 +504,7 @@ export function gte(dependentKey: string, value: number) {
504504
export function lt(dependentKey: string, value: number) {
505505
assert(
506506
'You attempted to use @lt as a decorator directly, but it requires `dependentKey` and `value` parameters',
507-
!isElementDescriptor(Array.prototype.slice.call(arguments))
507+
!isDecoratorCall(Array.prototype.slice.call(arguments))
508508
);
509509

510510
return computed(dependentKey, function () {
@@ -549,7 +549,7 @@ export function lt(dependentKey: string, value: number) {
549549
export function lte(dependentKey: string, value: number) {
550550
assert(
551551
'You attempted to use @lte as a decorator directly, but it requires `dependentKey` and `value` parameters',
552-
!isElementDescriptor(Array.prototype.slice.call(arguments))
552+
!isDecoratorCall(Array.prototype.slice.call(arguments))
553553
);
554554

555555
return computed(dependentKey, function () {
@@ -723,7 +723,7 @@ export const or = generateComputedWithPredicate('or', (value) => !value);
723723
export function oneWay(dependentKey: string) {
724724
assert(
725725
'You attempted to use @oneWay as a decorator directly, but it requires a `dependentKey` parameter',
726-
!isElementDescriptor(Array.prototype.slice.call(arguments))
726+
!isDecoratorCall(Array.prototype.slice.call(arguments))
727727
);
728728

729729
return alias(dependentKey).oneWay() as PropertyDecorator;
@@ -787,7 +787,7 @@ export function oneWay(dependentKey: string) {
787787
export function readOnly(dependentKey: string) {
788788
assert(
789789
'You attempted to use @readOnly as a decorator directly, but it requires a `dependentKey` parameter',
790-
!isElementDescriptor(Array.prototype.slice.call(arguments))
790+
!isDecoratorCall(Array.prototype.slice.call(arguments))
791791
);
792792

793793
return alias(dependentKey).readOnly() as PropertyDecorator;
@@ -831,7 +831,7 @@ export function readOnly(dependentKey: string) {
831831
export function deprecatingAlias(dependentKey: string, options: DeprecationOptions) {
832832
assert(
833833
'You attempted to use @deprecatingAlias as a decorator directly, but it requires `dependentKey` and `options` parameters',
834-
!isElementDescriptor(Array.prototype.slice.call(arguments))
834+
!isDecoratorCall(Array.prototype.slice.call(arguments))
835835
);
836836

837837
return computed(dependentKey, {

packages/@ember/object/lib/computed/reduce_computed_macros.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { DEBUG } from '@glimmer/env';
55
import { assert } from '@ember/debug';
6-
import { autoComputed, isElementDescriptor } from '@ember/-internals/metal';
6+
import { autoComputed, isDecoratorCall } from '@ember/-internals/metal';
77
import { computed, get } from '@ember/object';
88
import { compare } from '@ember/utils';
99
import EmberArray, { A as emberA, uniqBy as uniqByArray } from '@ember/array';
@@ -104,7 +104,7 @@ function multiArrayMacro(
104104
export function sum(dependentKey: string) {
105105
assert(
106106
'You attempted to use @sum as a decorator directly, but it requires a `dependentKey` parameter',
107-
!isElementDescriptor(Array.prototype.slice.call(arguments))
107+
!isDecoratorCall(Array.prototype.slice.call(arguments))
108108
);
109109

110110
return reduceMacro(dependentKey, (sum: number, item: number) => sum + item, 0, 'sum');
@@ -168,7 +168,7 @@ export function sum(dependentKey: string) {
168168
export function max(dependentKey: string) {
169169
assert(
170170
'You attempted to use @max as a decorator directly, but it requires a `dependentKey` parameter',
171-
!isElementDescriptor(Array.prototype.slice.call(arguments))
171+
!isDecoratorCall(Array.prototype.slice.call(arguments))
172172
);
173173

174174
return reduceMacro(dependentKey, (max, item) => Math.max(max, item), -Infinity, 'max');
@@ -231,7 +231,7 @@ export function max(dependentKey: string) {
231231
export function min(dependentKey: string) {
232232
assert(
233233
'You attempted to use @min as a decorator directly, but it requires a `dependentKey` parameter',
234-
!isElementDescriptor(Array.prototype.slice.call(arguments))
234+
!isDecoratorCall(Array.prototype.slice.call(arguments))
235235
);
236236

237237
return reduceMacro(dependentKey, (min, item) => Math.min(min, item), Infinity, 'min');
@@ -328,7 +328,7 @@ export function map(
328328
): PropertyDecorator {
329329
assert(
330330
'You attempted to use @map as a decorator directly, but it requires atleast `dependentKey` and `callback` parameters',
331-
!isElementDescriptor(Array.prototype.slice.call(arguments))
331+
!isDecoratorCall(Array.prototype.slice.call(arguments))
332332
);
333333

334334
assert(
@@ -412,7 +412,7 @@ export function map(
412412
export function mapBy(dependentKey: string, propertyKey: string) {
413413
assert(
414414
'You attempted to use @mapBy as a decorator directly, but it requires `dependentKey` and `propertyKey` parameters',
415-
!isElementDescriptor(Array.prototype.slice.call(arguments))
415+
!isDecoratorCall(Array.prototype.slice.call(arguments))
416416
);
417417

418418
assert(
@@ -554,7 +554,7 @@ export function filter(
554554
): PropertyDecorator {
555555
assert(
556556
'You attempted to use @filter as a decorator directly, but it requires atleast `dependentKey` and `callback` parameters',
557-
!isElementDescriptor(Array.prototype.slice.call(arguments))
557+
!isDecoratorCall(Array.prototype.slice.call(arguments))
558558
);
559559

560560
assert(
@@ -636,7 +636,7 @@ export function filter(
636636
export function filterBy(dependentKey: string, propertyKey: string, value?: unknown) {
637637
assert(
638638
'You attempted to use @filterBy as a decorator directly, but it requires atleast `dependentKey` and `propertyKey` parameters',
639-
!isElementDescriptor(Array.prototype.slice.call(arguments))
639+
!isDecoratorCall(Array.prototype.slice.call(arguments))
640640
);
641641

642642
assert(
@@ -696,7 +696,7 @@ export function uniq(
696696
): PropertyDecorator {
697697
assert(
698698
'You attempted to use @uniq/@union as a decorator directly, but it requires atleast one dependent key parameter',
699-
!isElementDescriptor(Array.prototype.slice.call(arguments))
699+
!isDecoratorCall(Array.prototype.slice.call(arguments))
700700
);
701701

702702
let args = [dependentKey, ...additionalDependentKeys];
@@ -765,7 +765,7 @@ export function uniq(
765765
export function uniqBy(dependentKey: string, propertyKey: string) {
766766
assert(
767767
'You attempted to use @uniqBy as a decorator directly, but it requires `dependentKey` and `propertyKey` parameters',
768-
!isElementDescriptor(Array.prototype.slice.call(arguments))
768+
!isDecoratorCall(Array.prototype.slice.call(arguments))
769769
);
770770

771771
assert(
@@ -864,7 +864,7 @@ export let union = uniq;
864864
export function intersect(dependentKey: string, ...additionalDependentKeys: string[]) {
865865
assert(
866866
'You attempted to use @intersect as a decorator directly, but it requires atleast one dependent key parameter',
867-
!isElementDescriptor(Array.prototype.slice.call(arguments))
867+
!isDecoratorCall(Array.prototype.slice.call(arguments))
868868
);
869869

870870
let args = [dependentKey, ...additionalDependentKeys];
@@ -953,7 +953,7 @@ export function intersect(dependentKey: string, ...additionalDependentKeys: stri
953953
export function setDiff(setAProperty: string, setBProperty: string) {
954954
assert(
955955
'You attempted to use @setDiff as a decorator directly, but it requires atleast one dependent key parameter',
956-
!isElementDescriptor(Array.prototype.slice.call(arguments))
956+
!isDecoratorCall(Array.prototype.slice.call(arguments))
957957
);
958958

959959
assert('`setDiff` computed macro requires exactly two dependent arrays.', arguments.length === 2);
@@ -1011,7 +1011,7 @@ export function setDiff(setAProperty: string, setBProperty: string) {
10111011
export function collect(dependentKey: string, ...additionalDependentKeys: string[]) {
10121012
assert(
10131013
'You attempted to use @collect as a decorator directly, but it requires atleast one dependent key parameter',
1014-
!isElementDescriptor(Array.prototype.slice.call(arguments))
1014+
!isDecoratorCall(Array.prototype.slice.call(arguments))
10151015
);
10161016

10171017
let dependentKeys = [dependentKey, ...additionalDependentKeys];
@@ -1188,7 +1188,7 @@ export function sort(
11881188
): PropertyDecorator {
11891189
assert(
11901190
'You attempted to use @sort as a decorator directly, but it requires atleast an `itemsKey` parameter',
1191-
!isElementDescriptor(Array.prototype.slice.call(arguments))
1191+
!isDecoratorCall(Array.prototype.slice.call(arguments))
11921192
);
11931193

11941194
if (DEBUG) {

0 commit comments

Comments
 (0)