diff --git a/src/languageservice/services/yamlSchemaService.ts b/src/languageservice/services/yamlSchemaService.ts index 08c03229..61953f16 100644 --- a/src/languageservice/services/yamlSchemaService.ts +++ b/src/languageservice/services/yamlSchemaService.ts @@ -242,7 +242,7 @@ export class YAMLSchemaService extends JSONSchemaService { } const toWalk: JSONSchema[] = [node]; - const seen: JSONSchema[] = []; + const seen: Set = new Set(); // eslint-disable-next-line @typescript-eslint/no-explicit-any const openPromises: Promise[] = []; @@ -278,7 +278,7 @@ export class YAMLSchemaService extends JSONSchemaService { } }; const handleRef = (next: JSONSchema): void => { - const seenRefs = []; + const seenRefs = new Set(); while (next.$ref) { const ref = next.$ref; const segments = ref.split('#', 2); @@ -289,9 +289,9 @@ export class YAMLSchemaService extends JSONSchemaService { openPromises.push(resolveExternalLink(next, segments[0], segments[1], parentSchemaURL, parentSchemaDependencies)); return; } else { - if (seenRefs.indexOf(ref) === -1) { + if (!seenRefs.has(ref)) { merge(next, parentSchema, parentSchemaURL, segments[1]); // can set next.$ref again, use seenRefs to avoid circle - seenRefs.push(ref); + seenRefs.add(ref); } } } @@ -330,10 +330,10 @@ export class YAMLSchemaService extends JSONSchemaService { while (toWalk.length) { const next = toWalk.pop(); - if (seen.indexOf(next) >= 0) { + if (seen.has(next)) { continue; } - seen.push(next); + seen.add(next); handleRef(next); } return Promise.all(openPromises);