Skip to content

Commit

Permalink
Update to latest source-map-tests submodule
Browse files Browse the repository at this point in the history
Also adds validation logic to pass additional tests

  * Account for sourceRoot field when working with files
  * Check validation for file, sourceRoot
  * Make names field optional
  * Fix sourcesContent handling when wrong type
  • Loading branch information
takikawa committed Oct 3, 2024
1 parent 296d9ae commit a2853df
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion source-map-tests
Submodule source-map-tests updated 68 files
+17 −138 README.md
+2,036 −239 chrome/0001-Add-source-map-specification-tests.patch
+46 −0 chrome/0002-Add-reverse-mapping-code-to-test.patch
+0 −59 chrome/0002-add-test-for-valid-sourcemaps.patch
+0 −108 chrome/0003-add-more-tests-cases.patch
+0 −1,409 chrome/0004-intermediete-mappings-cases.patch
+0 −337 firefox/0001-WIP-Firefox-source-map-spec-tests.patch
+0 −71 firefox/browser_spec-source-map.js
+1 −0 resources/basic-mapping-as-index-map.js.map
+1 −0 resources/file-not-a-string-1.js
+8 −0 resources/file-not-a-string-1.js.map
+1 −0 resources/file-not-a-string-2.js
+8 −0 resources/file-not-a-string-2.js.map
+1 −0 resources/ignore-list-out-of-bounds-1.js
+0 −0 resources/ignore-list-out-of-bounds-1.js.map
+1 −0 resources/ignore-list-out-of-bounds-2.js
+8 −0 resources/ignore-list-out-of-bounds-2.js.map
+0 −1 resources/ignore-list-out-of-bounds.js
+1 −0 resources/ignore-list-wrong-type-4.js
+8 −0 resources/ignore-list-wrong-type-4.js.map
+1 −0 resources/index-map-empty-sections.js
+4 −0 resources/index-map-empty-sections.js.map
+2 −0 resources/index-map-file-wrong-type-1.js
+15 −0 resources/index-map-file-wrong-type-1.js.map
+2 −0 resources/index-map-file-wrong-type-2.js
+15 −0 resources/index-map-file-wrong-type-2.js.map
+1 −0 resources/index-map-invalid-sub-map.js
+13 −0 resources/index-map-invalid-sub-map.js.map
+2 −0 resources/index-map-missing-file.js
+14 −0 resources/index-map-missing-file.js.map
+1 −0 resources/index-map-two-concatenated-sources.js.map
+1 −0 resources/invalid-vlq-non-base64-char-padding.js
+7 −0 resources/invalid-vlq-non-base64-char-padding.js.map
+3 −0 resources/mapping-semantics-column-reset.js
+7 −0 resources/mapping-semantics-column-reset.js.map
+2 −0 resources/mapping-semantics-five-field-segment.js
+7 −0 resources/mapping-semantics-five-field-segment.js.map
+2 −0 resources/mapping-semantics-four-field-segment.js
+7 −0 resources/mapping-semantics-four-field-segment.js.map
+2 −0 resources/mapping-semantics-relative-1.js
+7 −0 resources/mapping-semantics-relative-1.js.map
+3 −0 resources/mapping-semantics-relative-2.js
+7 −0 resources/mapping-semantics-relative-2.js.map
+2 −0 resources/mapping-semantics-single-field-segment.js
+7 −0 resources/mapping-semantics-single-field-segment.js.map
+1 −0 resources/names-missing.js.map
+2 −0 resources/source-resolution-absolute-url.js
+8 −0 resources/source-resolution-absolute-url.js.map
+1 −0 resources/source-root-not-a-string-1.js
+8 −0 resources/source-root-not-a-string-1.js.map
+1 −0 resources/source-root-not-a-string-2.js
+8 −0 resources/source-root-not-a-string-2.js.map
+2 −0 resources/source-root-resolution.js
+9 −0 resources/source-root-resolution.js.map
+1 −0 resources/valid-mapping-empty-string.js
+8 −0 resources/valid-mapping-empty-string.js.map
+2 −0 resources/vlq-valid-continuation-bit-present-1.js
+7 −0 resources/vlq-valid-continuation-bit-present-1.js.map
+4 −0 resources/vlq-valid-continuation-bit-present-2.js
+7 −0 resources/vlq-valid-continuation-bit-present-2.js.map
+4 −0 resources/vlq-valid-negative-digit.js
+7 −0 resources/vlq-valid-negative-digit.js.map
+2 −0 resources/vlq-valid-single-digit.js
+7 −0 resources/vlq-valid-single-digit.js.map
+486 −6 source-map-spec-tests.json
+0 −1,649 webkit/0001-Add-harness-for-source-maps-spec-tests.patch
+11,542 −0 webkit/0001-Add-test-runner-for-the-source-map-spec-tests.patch
+0 −83 webkit/source-map-spec.html
3 changes: 2 additions & 1 deletion src/util/collectSourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import type { SourceMap } from "./sourceMap.js";

export function collectSourceFiles(sourceMap: SourceMap, originalFolderPath: string) {
const filesMap = new Map<string, TestingFile>();
const sourceRoot = sourceMap.sourceRoot || "";

sourceMap.sources.forEach((file: string | null, index: number) => {
// When the source is null, it might make sense to map to an anonymous source
// if a sourceContent is present, but for now just don't add it to the set.
if (file !== null)
filesMap.set(file, TestingFile.forTextFile(path.join(originalFolderPath, file), sourceMap.sourcesContent ? sourceMap.sourcesContent[index] : null))
filesMap.set(path.join(sourceRoot, file), TestingFile.forTextFile(path.join(originalFolderPath, sourceRoot, file), sourceMap.sourcesContent ? sourceMap.sourcesContent[index] : null))
});

return filesMap;
Expand Down
4 changes: 2 additions & 2 deletions src/validators/SourceFilesValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import type { ValidationContext } from "../util/ValidationContext.js";
export class SourceFilesValidator extends Validator {
validate(context: ValidationContext): ValidationResult {
const errors: Error[] = [];
const { sources, sourcesContent = [] } = context.sourceMap
const { sources, sourceRoot, sourcesContent = [] } = context.sourceMap

function check(sources : any) {
sources.forEach((sourceFileName: string | null, index: number) => {
const fullPath = sourceFileName === null ? null : path.join(context.originalFolderPath, sourceFileName);
const fullPath = sourceFileName === null ? null : path.join(context.originalFolderPath, sourceRoot || "", sourceFileName);
// If the path is null, we won't use the source in subsequent passes so
// it can be ignored. Otherwise ensure the source makes sense.
if (fullPath !== null) {
Expand Down
32 changes: 23 additions & 9 deletions src/validators/SourceMapFormatValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ function validateSourceMap(sourceMap : any) : Error[] {
errors.push(new Error(`Source map version is not 3, got ${sourceMap.version}.`));
}

if ('file' in sourceMap) {
if (typeof sourceMap.file !== "string")
errors.push(new Error('Source map "file" field is not a string.'));
}

if ("sections" in sourceMap) {
if ("mappings" in sourceMap) {
errors.push(new Error('Source map cannot have both "mappings" and "sections" fields.'));
Expand All @@ -31,6 +36,11 @@ function validateSourceMap(sourceMap : any) : Error[] {
});
}
} else {
if ('sourceRoot' in sourceMap) {
if (typeof sourceMap.sourceRoot !== "string")
errors.push(new Error('Source map "sourceRoot" field is not a string.'));
}

if (!sourceMap.sources || !Array.isArray(sourceMap.sources)) {
errors.push(new Error('Source map "sources" field is invalid or missing.'));
} else {
Expand All @@ -39,12 +49,14 @@ function validateSourceMap(sourceMap : any) : Error[] {
})
}

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 ("names" in sourceMap) {
if (!Array.isArray(sourceMap.names)) {
errors.push(new Error('Source map "names" field is invalid.'));
} 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)) {
Expand All @@ -56,9 +68,11 @@ function validateSourceMap(sourceMap : any) : Error[] {
if ('sourcesContent' in sourceMap) {
if (!Array.isArray(sourceMap.sourcesContent))
errors.push(new Error('Source map "sourcesContent" field is invalid.'));
sourceMap.sourcesContent.forEach((x: unknown, i: number) => {
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`))
})
else {
sourceMap.sourcesContent.forEach((x: unknown, i: number) => {
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) {
Expand Down

0 comments on commit a2853df

Please sign in to comment.