Skip to content

Commit

Permalink
add suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Garrett committed Feb 27, 2020
1 parent 5e836e1 commit 6d17631
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/@ember/-internals/utils/lib/mandatory-setter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ export let setWithMandatorySetter:

type PropertyDescriptorWithMeta = PropertyDescriptor & { hadOwnProperty?: boolean };

function isElementKey(key: string | number | symbol) {
return typeof key === 'number' ? isPositiveInt(key) : isStringInt(key as string);
}

function isStringInt(str: string) {
let num = parseInt(str, 10);
return isPositiveInt(num) && str === String(num);
}

function isPositiveInt(num: number) {
return num >= 0 && num % 1 === 0;
}

if (DEBUG) {
let SEEN_TAGS = new WeakSet();

Expand All @@ -34,9 +47,8 @@ if (DEBUG) {

SEEN_TAGS!.add(tag);

if (Array.isArray(obj) && !isNaN(Number(keyName))) {
// don't setup mandatory setter, arrays can remove property descriptors
// themselves and we can't control them correctly.
if (Array.isArray(obj) && !isElementKey(keyName)) {
// this would replace the conditional
return;
}

Expand Down

0 comments on commit 6d17631

Please sign in to comment.