Skip to content

Commit

Permalink
Add stricter checking for the name field
Browse files Browse the repository at this point in the history
This requires the name field to be present. The spec is not 100% clear on this,
so this may be worth revisiting but the names field is not listed as an
"optional" field.

Also checks if the names are strings.
  • Loading branch information
takikawa committed May 22, 2024
1 parent c829006 commit 48ffe5d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/validators/SourceMapFormatValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export class SourceMapFormatValidator extends Validator {
})
}

if (!sourceMap.names || !Array.isArray(sourceMap.names)) {
errors.push(new Error('Source map "names" field is missing.'));
} else {
sourceMap.names.forEach((x: unknown, i: number) => {
if (typeof x !== "string") errors.push(new Error(`There is a name with an invalid format on the index ${i}. Each name should be defined as a string`))
})
}

if (!("mappings" in sourceMap)) {
errors.push(new Error('Source map "mappings" field is missing.'));
} else if (typeof sourceMap.mappings !== "string") {
Expand Down

0 comments on commit 48ffe5d

Please sign in to comment.