Skip to content

Commit 62f1144

Browse files
committed
Consolidate normalizing slashes and use it from typescript core.ts
1 parent 6f5b20c commit 62f1144

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

src/harness/fourslashRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FourslashRunner extends RunnerBase {
2020
});
2121

2222
this.tests.forEach((fn: string) => {
23-
fn = Harness.Path.switchToForwardSlashes(fn);
23+
fn = ts.normalizeSlashes(fn);
2424
var justName = fn.replace(/^.*[\\\/]/, '');
2525

2626
// Convert to relative path

src/harness/harness.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,11 @@ module Harness.Path {
117117
}
118118

119119
export function filePath(fullPath: string) {
120-
fullPath = switchToForwardSlashes(fullPath);
120+
fullPath = ts.normalizeSlashes(fullPath);
121121
var components = fullPath.split("/");
122122
var path: string[] = components.slice(0, components.length - 1);
123123
return path.join("/") + "/";
124124
}
125-
126-
export function switchToForwardSlashes(path: string) {
127-
return path.replace(/\\/g, "/").replace(/\/\//g, '/');
128-
}
129125
}
130126

131127
module Harness {
@@ -564,7 +560,7 @@ module Harness {
564560
// Register input files
565561
function register(file: { unitName: string; content: string; }) {
566562
if (file.content !== undefined) {
567-
var filename = Path.switchToForwardSlashes(file.unitName);
563+
var filename = ts.normalizeSlashes(file.unitName);
568564
filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, scriptTarget, /*version:*/ "0");
569565
}
570566
};
@@ -782,7 +778,7 @@ module Harness {
782778
var filemap: { [name: string]: ts.SourceFile; } = {};
783779
var register = (file: { unitName: string; content: string; }) => {
784780
if (file.content !== undefined) {
785-
var filename = Path.switchToForwardSlashes(file.unitName);
781+
var filename = ts.normalizeSlashes(file.unitName);
786782
filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, options.target, /*version:*/ "0");
787783
}
788784
};

src/harness/loggedIO.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ module Playback {
175175
}
176176

177177
function findResultByPath<T>(wrapper: { resolvePath(s: string): string }, logArray: { path: string; result?: T }[], expectedPath: string, defaultValue?: T): T {
178-
var normalizedName = Harness.Path.switchToForwardSlashes(expectedPath).toLowerCase();
178+
var normalizedName = ts.normalizeSlashes(expectedPath).toLowerCase();
179179
// Try to find the result through normal filename
180180
for (var i = 0; i < logArray.length; i++) {
181-
if (Harness.Path.switchToForwardSlashes(logArray[i].path).toLowerCase() === normalizedName) {
181+
if (ts.normalizeSlashes(logArray[i].path).toLowerCase() === normalizedName) {
182182
return logArray[i].result;
183183
}
184184
}
@@ -203,7 +203,7 @@ module Playback {
203203
function pathsAreEquivalent(left: string, right: string, wrapper: { resolvePath(s: string): string }) {
204204
var key = left + '-~~-' + right;
205205
function areSame(a: string, b: string) {
206-
return Harness.Path.switchToForwardSlashes(a).toLowerCase() === Harness.Path.switchToForwardSlashes(b).toLowerCase();
206+
return ts.normalizeSlashes(a).toLowerCase() === ts.normalizeSlashes(b).toLowerCase();
207207
}
208208
function check() {
209209
if (Harness.Path.getFileName(left).toLowerCase() === Harness.Path.getFileName(right).toLowerCase()) {

src/harness/rwcRunner.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module RWC {
2323
function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) {
2424
// Collect, test, and sort the filenames
2525
function cleanName(fn: string) {
26-
var lastSlash = Harness.Path.switchToForwardSlashes(fn).lastIndexOf('/');
26+
var lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/');
2727
return fn.substr(lastSlash + 1).toLowerCase();
2828
}
2929
outputFiles.sort((a, b) => cleanName(a.fileName).localeCompare(cleanName(b.fileName)));
@@ -52,7 +52,7 @@ module RWC {
5252
var compilerResult: Harness.Compiler.CompilerResult;
5353
var compilerOptions: ts.CompilerOptions;
5454
var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' };
55-
var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2];
55+
var baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2];
5656
// Compile .d.ts files
5757
var declFileCompilationResult: {
5858
declInputFiles: { unitName: string; content: string }[];
@@ -99,7 +99,7 @@ module RWC {
9999
}
100100

101101
ts.forEach(ioLog.filesRead, fileRead => {
102-
var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path));
102+
var resolvedPath = ts.normalizeSlashes(sys.resolvePath(fileRead.path));
103103
var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath);
104104
if (!inInputList) {
105105
// Add the file to other files
@@ -117,7 +117,7 @@ module RWC {
117117
});
118118

119119
function getHarnessCompilerInputUnit(fileName: string) {
120-
var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName));
120+
var resolvedPath = ts.normalizeSlashes(sys.resolvePath(fileName));
121121
try {
122122
var content = sys.readFile(resolvedPath);
123123
}

0 commit comments

Comments
 (0)