Skip to content

Commit d8373c3

Browse files
authored
Merge pull request #19314 from Microsoft/fix-tsc-instrumented
Fix four tsc-instrumented bugs
2 parents 8fc6518 + 79c6724 commit d8373c3

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/compiler/sys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ namespace ts {
573573

574574
function recursiveCreateDirectory(directoryPath: string, sys: System) {
575575
const basePath = getDirectoryPath(directoryPath);
576-
const shouldCreateParent = directoryPath !== basePath && !sys.directoryExists(basePath);
576+
const shouldCreateParent = basePath !== "" && directoryPath !== basePath && !sys.directoryExists(basePath);
577577
if (shouldCreateParent) {
578578
recursiveCreateDirectory(basePath, sys);
579579
}

src/harness/loggedIO.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,20 @@ namespace Playback {
157157
return log;
158158
}
159159

160+
const canonicalizeForHarness = ts.createGetCanonicalFileName(/*caseSensitive*/ false); // This is done so tests work on windows _and_ linux
161+
function sanitizeTestFilePath(name: string) {
162+
const path = ts.toPath(ts.normalizeSlashes(name.replace(/[\^<>:"|?*%]/g, "_")).replace(/\.\.\//g, "__dotdot/"), "", canonicalizeForHarness);
163+
if (ts.startsWith(path, "/")) {
164+
return path.substring(1);
165+
}
166+
return path;
167+
}
168+
160169
export function oldStyleLogIntoNewStyleLog(log: IOLog, writeFile: typeof Harness.IO.writeFile, baseTestName: string) {
161170
if (log.filesAppended) {
162171
for (const file of log.filesAppended) {
163172
if (file.contents !== undefined) {
164-
file.contentsPath = ts.combinePaths("appended", Harness.Compiler.sanitizeTestFilePath(file.path));
173+
file.contentsPath = ts.combinePaths("appended", sanitizeTestFilePath(file.path));
165174
writeFile(ts.combinePaths(baseTestName, file.contentsPath), file.contents);
166175
delete file.contents;
167176
}
@@ -170,7 +179,7 @@ namespace Playback {
170179
if (log.filesWritten) {
171180
for (const file of log.filesWritten) {
172181
if (file.contents !== undefined) {
173-
file.contentsPath = ts.combinePaths("written", Harness.Compiler.sanitizeTestFilePath(file.path));
182+
file.contentsPath = ts.combinePaths("written", sanitizeTestFilePath(file.path));
174183
writeFile(ts.combinePaths(baseTestName, file.contentsPath), file.contents);
175184
delete file.contents;
176185
}
@@ -180,7 +189,7 @@ namespace Playback {
180189
for (const file of log.filesRead) {
181190
const { contents } = file.result;
182191
if (contents !== undefined) {
183-
file.result.contentsPath = ts.combinePaths("read", Harness.Compiler.sanitizeTestFilePath(file.path));
192+
file.result.contentsPath = ts.combinePaths("read", sanitizeTestFilePath(file.path));
184193
writeFile(ts.combinePaths(baseTestName, file.result.contentsPath), contents);
185194
const len = contents.length;
186195
if (len >= 2 && contents.charCodeAt(0) === 0xfeff) {
@@ -235,8 +244,8 @@ namespace Playback {
235244
if (recordLog !== undefined) {
236245
let i = 0;
237246
const fn = () => recordLogFileNameBase + i;
238-
while (underlying.fileExists(fn() + ".json")) i++;
239-
underlying.writeFile(ts.combinePaths(fn(), "test.json"), JSON.stringify(oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(ts.combinePaths(fn(), path), string), fn()), null, 4)); // tslint:disable-line:no-null-keyword
247+
while (underlying.fileExists(ts.combinePaths(fn(), "test.json"))) i++;
248+
underlying.writeFile(ts.combinePaths(fn(), "test.json"), JSON.stringify(oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), fn()), null, 4)); // tslint:disable-line:no-null-keyword
240249
recordLog = undefined;
241250
}
242251
};
@@ -415,4 +424,4 @@ namespace Playback {
415424
initWrapper(wrapper, underlying);
416425
return wrapper;
417426
}
418-
}
427+
}

0 commit comments

Comments
 (0)