Skip to content

Commit 6a60a6a

Browse files
authored
Merge pull request #15 from takikawa/update-submod-2024-10-02
Update to latest source-map-tests submodule
2 parents 296d9ae + a2853df commit 6a60a6a

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

source-map-tests

Submodule source-map-tests updated 68 files

src/util/collectSourceFiles.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import type { SourceMap } from "./sourceMap.js";
44

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

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

1516
return filesMap;

src/validators/SourceFilesValidator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import type { ValidationContext } from "../util/ValidationContext.js";
77
export class SourceFilesValidator extends Validator {
88
validate(context: ValidationContext): ValidationResult {
99
const errors: Error[] = [];
10-
const { sources, sourcesContent = [] } = context.sourceMap
10+
const { sources, sourceRoot, sourcesContent = [] } = context.sourceMap
1111

1212
function check(sources : any) {
1313
sources.forEach((sourceFileName: string | null, index: number) => {
14-
const fullPath = sourceFileName === null ? null : path.join(context.originalFolderPath, sourceFileName);
14+
const fullPath = sourceFileName === null ? null : path.join(context.originalFolderPath, sourceRoot || "", sourceFileName);
1515
// If the path is null, we won't use the source in subsequent passes so
1616
// it can be ignored. Otherwise ensure the source makes sense.
1717
if (fullPath !== null) {

src/validators/SourceMapFormatValidator.ts

+23-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ function validateSourceMap(sourceMap : any) : Error[] {
1111
errors.push(new Error(`Source map version is not 3, got ${sourceMap.version}.`));
1212
}
1313

14+
if ('file' in sourceMap) {
15+
if (typeof sourceMap.file !== "string")
16+
errors.push(new Error('Source map "file" field is not a string.'));
17+
}
18+
1419
if ("sections" in sourceMap) {
1520
if ("mappings" in sourceMap) {
1621
errors.push(new Error('Source map cannot have both "mappings" and "sections" fields.'));
@@ -31,6 +36,11 @@ function validateSourceMap(sourceMap : any) : Error[] {
3136
});
3237
}
3338
} else {
39+
if ('sourceRoot' in sourceMap) {
40+
if (typeof sourceMap.sourceRoot !== "string")
41+
errors.push(new Error('Source map "sourceRoot" field is not a string.'));
42+
}
43+
3444
if (!sourceMap.sources || !Array.isArray(sourceMap.sources)) {
3545
errors.push(new Error('Source map "sources" field is invalid or missing.'));
3646
} else {
@@ -39,12 +49,14 @@ function validateSourceMap(sourceMap : any) : Error[] {
3949
})
4050
}
4151

42-
if (!sourceMap.names || !Array.isArray(sourceMap.names)) {
43-
errors.push(new Error('Source map "names" field is missing.'));
44-
} else {
45-
sourceMap.names.forEach((x: unknown, i: number) => {
46-
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`))
47-
})
52+
if ("names" in sourceMap) {
53+
if (!Array.isArray(sourceMap.names)) {
54+
errors.push(new Error('Source map "names" field is invalid.'));
55+
} else {
56+
sourceMap.names.forEach((x: unknown, i: number) => {
57+
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`))
58+
})
59+
}
4860
}
4961

5062
if (!("mappings" in sourceMap)) {
@@ -56,9 +68,11 @@ function validateSourceMap(sourceMap : any) : Error[] {
5668
if ('sourcesContent' in sourceMap) {
5769
if (!Array.isArray(sourceMap.sourcesContent))
5870
errors.push(new Error('Source map "sourcesContent" field is invalid.'));
59-
sourceMap.sourcesContent.forEach((x: unknown, i: number) => {
60-
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`))
61-
})
71+
else {
72+
sourceMap.sourcesContent.forEach((x: unknown, i: number) => {
73+
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`))
74+
})
75+
}
6276
}
6377

6478
if ("ignoreList" in sourceMap) {

0 commit comments

Comments
 (0)