Skip to content

Commit

Permalink
Merge pull request #28921 from ajafff/no-set
Browse files Browse the repository at this point in the history
Avoid uses of ES6 Set, use Array instead
  • Loading branch information
DanielRosenwasser committed Dec 11, 2018
2 parents c77fcf2 + 67f037c commit b99c60a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/compiler/inspectValue.ts
Expand Up @@ -40,18 +40,18 @@ namespace ts {

type Recurser = <T>(obj: unknown, name: string, cbOk: () => T, cbFail: (isCircularReference: boolean, keyStack: ReadonlyArray<string>) => T) => T;
function getRecurser(): Recurser {
const seen = new Set<unknown>();
const seen: unknown[] = [];
const nameStack: string[] = [];
return (obj, name, cbOk, cbFail) => {
if (seen.has(obj) || nameStack.length > 4) {
return cbFail(seen.has(obj), nameStack);
if (seen.indexOf(obj) !== -1 || nameStack.length > 4) {
return cbFail(seen.indexOf(obj) !== -1, nameStack);
}

seen.add(obj);
seen.push(obj);
nameStack.push(name);
const res = cbOk();
nameStack.pop();
seen.delete(obj);
seen.pop();
return res;
};
}
Expand Down Expand Up @@ -104,8 +104,8 @@ namespace ts {
key === "constructor" ? undefined : getValueInfo(key, value, recurser));
}

const ignoredProperties: ReadonlySet<string> = new Set(["arguments", "caller", "constructor", "eval", "super_"]);
const reservedFunctionProperties: ReadonlySet<string> = new Set(Object.getOwnPropertyNames(noop));
const ignoredProperties: ReadonlyArray<string> = ["arguments", "caller", "constructor", "eval", "super_"];
const reservedFunctionProperties: ReadonlyArray<string> = Object.getOwnPropertyNames(noop);
interface ObjectEntry { readonly key: string; readonly value: unknown; }
function getEntriesOfObject(obj: object): ReadonlyArray<ObjectEntry> {
const seen = createMap<true>();
Expand All @@ -114,8 +114,8 @@ namespace ts {
while (!isNullOrUndefined(chain) && chain !== Object.prototype && chain !== Function.prototype) {
for (const key of Object.getOwnPropertyNames(chain)) {
if (!isJsPrivate(key) &&
!ignoredProperties.has(key) &&
(typeof obj !== "function" || !reservedFunctionProperties.has(key)) &&
ignoredProperties.indexOf(key) === -1 &&
(typeof obj !== "function" || reservedFunctionProperties.indexOf(key) === -1) &&
// Don't add property from a higher prototype if it already exists in a lower one
addToSeen(seen, key)) {
const value = safeGetPropertyOfObject(chain, key);
Expand Down

0 comments on commit b99c60a

Please sign in to comment.