From 8300b72b52cf4ac059c7510ffa039700515fbf00 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Mon, 27 May 2024 17:14:02 -0700 Subject: [PATCH] Add ignoreList validation * Un-skip ignore list tests --- src/spec-tests.test.ts | 5 ----- src/validators/SourceMapFormatValidator.ts | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/spec-tests.test.ts b/src/spec-tests.test.ts index cd7dfa0..98b7be1 100644 --- a/src/spec-tests.test.ts +++ b/src/spec-tests.test.ts @@ -19,11 +19,6 @@ const skippedTests = [ "validMappingFieldsWith32BitMaxValues", // Source maps library errors on this. "validMappingLargeVLQ", - // Ignore list unsupported for now. - "ignoreListWrongType1", - "ignoreListWrongType2", - "ignoreListWrongType3", - "ignoreListOutOfBounds", ]; test.describe("runSourceMapSpecTests", () => { diff --git a/src/validators/SourceMapFormatValidator.ts b/src/validators/SourceMapFormatValidator.ts index f8080b2..a556144 100644 --- a/src/validators/SourceMapFormatValidator.ts +++ b/src/validators/SourceMapFormatValidator.ts @@ -60,6 +60,27 @@ function validateSourceMap(sourceMap : any) : Error[] { if (x !== null && typeof x !== "string") errors.push(new Error(`There is a source content with an invalid format on the index ${i}. Each content should be defined as a strings or null`)) }) } + + if ("ignoreList" in sourceMap) { + if (!Array.isArray(sourceMap.ignoreList)) + errors.push(new Error('Source map "ignoreList" field is invalid.')); + else { + sourceMap.ignoreList.forEach((x: unknown, i: number) => { + if (!Number.isInteger(x)) + errors.push( + new Error( + `There is an ignoreList entry with an invalid format at the index ${i}. Each content should be defined as a number`, + ), + ); + if ((x as number) >= sourceMap.sources.length || (x as number) < 0) + errors.push( + new Error( + `There is an ignoreList entry at index ${i} with an out-of-bounds value ${x}.`, + ), + ); + }); + } + } } return errors;