Skip to content

Commit

Permalink
Add ignoreList validation
Browse files Browse the repository at this point in the history
  * Un-skip ignore list tests
  • Loading branch information
takikawa committed Jun 19, 2024
1 parent bc72ed9 commit 8300b72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/spec-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
21 changes: 21 additions & 0 deletions src/validators/SourceMapFormatValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8300b72

Please sign in to comment.