From 6f5b20c09f3cf7727ce10b0303278f89f1c4cec4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 10 Nov 2014 14:24:08 -0800 Subject: [PATCH 1/3] Updating the gitignore file now that we build debug version of js files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 21d79becb15..fb84462083c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ build.json tests/webhost/*.d.ts tests/webhost/webtsc.js tests/*.js +tests/*.js.map tests/*.d.ts *.config scripts/debug.bat From 62f1144518281d20f094a21ede8bd0d5886075e8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 10 Nov 2014 14:18:43 -0800 Subject: [PATCH 2/3] Consolidate normalizing slashes and use it from typescript core.ts --- src/harness/fourslashRunner.ts | 2 +- src/harness/harness.ts | 10 +++------- src/harness/loggedIO.ts | 6 +++--- src/harness/rwcRunner.ts | 8 ++++---- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts index 102d4433b10..b7e59437456 100644 --- a/src/harness/fourslashRunner.ts +++ b/src/harness/fourslashRunner.ts @@ -20,7 +20,7 @@ class FourslashRunner extends RunnerBase { }); this.tests.forEach((fn: string) => { - fn = Harness.Path.switchToForwardSlashes(fn); + fn = ts.normalizeSlashes(fn); var justName = fn.replace(/^.*[\\\/]/, ''); // Convert to relative path diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 8203fa3c23f..d385dd2afc7 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -117,15 +117,11 @@ module Harness.Path { } export function filePath(fullPath: string) { - fullPath = switchToForwardSlashes(fullPath); + fullPath = ts.normalizeSlashes(fullPath); var components = fullPath.split("/"); var path: string[] = components.slice(0, components.length - 1); return path.join("/") + "/"; } - - export function switchToForwardSlashes(path: string) { - return path.replace(/\\/g, "/").replace(/\/\//g, '/'); - } } module Harness { @@ -564,7 +560,7 @@ module Harness { // Register input files function register(file: { unitName: string; content: string; }) { if (file.content !== undefined) { - var filename = Path.switchToForwardSlashes(file.unitName); + var filename = ts.normalizeSlashes(file.unitName); filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, scriptTarget, /*version:*/ "0"); } }; @@ -782,7 +778,7 @@ module Harness { var filemap: { [name: string]: ts.SourceFile; } = {}; var register = (file: { unitName: string; content: string; }) => { if (file.content !== undefined) { - var filename = Path.switchToForwardSlashes(file.unitName); + var filename = ts.normalizeSlashes(file.unitName); filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, options.target, /*version:*/ "0"); } }; diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index fc33d08b334..c6305c50c10 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -175,10 +175,10 @@ module Playback { } function findResultByPath(wrapper: { resolvePath(s: string): string }, logArray: { path: string; result?: T }[], expectedPath: string, defaultValue?: T): T { - var normalizedName = Harness.Path.switchToForwardSlashes(expectedPath).toLowerCase(); + var normalizedName = ts.normalizeSlashes(expectedPath).toLowerCase(); // Try to find the result through normal filename for (var i = 0; i < logArray.length; i++) { - if (Harness.Path.switchToForwardSlashes(logArray[i].path).toLowerCase() === normalizedName) { + if (ts.normalizeSlashes(logArray[i].path).toLowerCase() === normalizedName) { return logArray[i].result; } } @@ -203,7 +203,7 @@ module Playback { function pathsAreEquivalent(left: string, right: string, wrapper: { resolvePath(s: string): string }) { var key = left + '-~~-' + right; function areSame(a: string, b: string) { - return Harness.Path.switchToForwardSlashes(a).toLowerCase() === Harness.Path.switchToForwardSlashes(b).toLowerCase(); + return ts.normalizeSlashes(a).toLowerCase() === ts.normalizeSlashes(b).toLowerCase(); } function check() { if (Harness.Path.getFileName(left).toLowerCase() === Harness.Path.getFileName(right).toLowerCase()) { diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index 6590344a8dd..bfb139fa719 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -23,7 +23,7 @@ module RWC { function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[], clean?: (s: string) => string) { // Collect, test, and sort the filenames function cleanName(fn: string) { - var lastSlash = Harness.Path.switchToForwardSlashes(fn).lastIndexOf('/'); + var lastSlash = ts.normalizeSlashes(fn).lastIndexOf('/'); return fn.substr(lastSlash + 1).toLowerCase(); } outputFiles.sort((a, b) => cleanName(a.fileName).localeCompare(cleanName(b.fileName))); @@ -52,7 +52,7 @@ module RWC { var compilerResult: Harness.Compiler.CompilerResult; var compilerOptions: ts.CompilerOptions; var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' }; - var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2]; + var baseName = /(.*)\/(.*).json/.exec(ts.normalizeSlashes(jsonPath))[2]; // Compile .d.ts files var declFileCompilationResult: { declInputFiles: { unitName: string; content: string }[]; @@ -99,7 +99,7 @@ module RWC { } ts.forEach(ioLog.filesRead, fileRead => { - var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path)); + var resolvedPath = ts.normalizeSlashes(sys.resolvePath(fileRead.path)); var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); if (!inInputList) { // Add the file to other files @@ -117,7 +117,7 @@ module RWC { }); function getHarnessCompilerInputUnit(fileName: string) { - var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName)); + var resolvedPath = ts.normalizeSlashes(sys.resolvePath(fileName)); try { var content = sys.readFile(resolvedPath); } From 45e4e16afc671bded44bc9a2581359f3436e4022 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 10 Nov 2014 16:09:00 -0800 Subject: [PATCH 3/3] Consolidated normalizing slashes to use from typescript core in services --- src/services/compiler/pathUtils.ts | 44 --------------------------- src/services/services.ts | 48 +++++++++++++++--------------- src/services/shims.ts | 4 +-- src/services/utilities.ts | 4 --- 4 files changed, 26 insertions(+), 74 deletions(-) diff --git a/src/services/compiler/pathUtils.ts b/src/services/compiler/pathUtils.ts index e6631374f47..88aa3e4f30c 100644 --- a/src/services/compiler/pathUtils.ts +++ b/src/services/compiler/pathUtils.ts @@ -16,20 +16,6 @@ /// module TypeScript { - export function stripStartAndEndQuotes(str: string) { - var firstCharCode = str && str.charCodeAt(0); - if (str && str.length >= 2 && firstCharCode === str.charCodeAt(str.length - 1) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { - return str.substring(1, str.length - 1); - } - - return str; - } - - var switchToForwardSlashesRegEx = /\\/g; - export function switchToForwardSlashes(path: string) { - return path.replace(switchToForwardSlashesRegEx, "/"); - } - function isFileOfExtension(fname: string, ext: string) { var invariantFname = fname.toLocaleUpperCase(); var invariantExt = ext.toLocaleUpperCase(); @@ -40,34 +26,4 @@ module TypeScript { export function isDTSFile(fname: string) { return isFileOfExtension(fname, ".d.ts"); } - - export function getPathComponents(path: string) { - return path.split("/"); - } - - var normalizePathRegEx = /^\\\\[^\\]/; - export function normalizePath(path: string): string { - // If it's a UNC style path (i.e. \\server\share), convert to a URI style (i.e. file://server/share) - if (normalizePathRegEx.test(path)) { - path = "file:" + path; - } - var parts = getPathComponents(switchToForwardSlashes(path)); - var normalizedParts: string[] = []; - - for (var i = 0; i < parts.length; i++) { - var part = parts[i]; - if (part === ".") { - continue; - } - - if (normalizedParts.length > 0 && ArrayUtilities.last(normalizedParts) !== ".." && part === "..") { - normalizedParts.pop(); - continue; - } - - normalizedParts.push(part); - } - - return normalizedParts.join("/"); - } } \ No newline at end of file diff --git a/src/services/services.ts b/src/services/services.ts index 4a92ec1985f..512089f1d0e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1529,7 +1529,7 @@ module ts { var filenames = host.getScriptFileNames(); for (var i = 0, n = filenames.length; i < n; i++) { var filename = filenames[i]; - this.filenameToEntry[switchToForwardSlashes(filename)] = { + this.filenameToEntry[normalizeSlashes(filename)] = { filename: filename, version: host.getScriptVersion(filename), isOpen: host.getScriptIsOpen(filename) @@ -1544,7 +1544,7 @@ module ts { } public getEntry(filename: string): HostFileInformation { - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); return lookUp(this.filenameToEntry, filename); } @@ -2322,7 +2322,7 @@ module ts { function getSyntacticDiagnostics(filename: string) { synchronizeHostData(); - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); return program.getDiagnostics(getSourceFile(filename).getSourceFile()); } @@ -2334,7 +2334,7 @@ module ts { function getSemanticDiagnostics(filename: string) { synchronizeHostData(); - filename = switchToForwardSlashes(filename) + filename = normalizeSlashes(filename) var compilerOptions = program.getCompilerOptions(); var checker = getFullTypeCheckChecker(); var targetSourceFile = getSourceFile(filename); @@ -2415,7 +2415,7 @@ module ts { function getCompletionsAtPosition(filename: string, position: number, isMemberCompletion: boolean) { synchronizeHostData(); - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var syntacticStart = new Date().getTime(); var sourceFile = getSourceFile(filename); @@ -2760,7 +2760,7 @@ module ts { function getCompletionEntryDetails(filename: string, position: number, entryName: string): CompletionEntryDetails { // Note: No need to call synchronizeHostData, as we have captured all the data we need // in the getCompletionsAtPosition earlier - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var sourceFile = getSourceFile(filename); @@ -3260,7 +3260,7 @@ module ts { function getQuickInfoAtPosition(fileName: string, position: number): QuickInfo { synchronizeHostData(); - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var sourceFile = getSourceFile(fileName); var node = getTouchingPropertyName(sourceFile, position); if (!node) { @@ -3362,7 +3362,7 @@ module ts { synchronizeHostData(); - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var sourceFile = getSourceFile(filename); var node = getTouchingPropertyName(sourceFile, position); @@ -3426,7 +3426,7 @@ module ts { function getOccurrencesAtPosition(filename: string, position: number): ReferenceEntry[] { synchronizeHostData(); - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var sourceFile = getSourceFile(filename); var node = getTouchingWord(sourceFile, position); @@ -3876,7 +3876,7 @@ module ts { function findReferences(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { synchronizeHostData(); - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var sourceFile = getSourceFile(fileName); var node = getTouchingPropertyName(sourceFile, position); @@ -4597,7 +4597,7 @@ module ts { function getEmitOutput(filename: string): EmitOutput { synchronizeHostData(); - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var compilerOptions = program.getCompilerOptions(); var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output // If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false. @@ -4771,7 +4771,7 @@ module ts { function getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems { synchronizeHostData(); - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var sourceFile = getSourceFile(fileName); return SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken); @@ -4841,12 +4841,12 @@ module ts { /// Syntactic features function getSyntaxTree(filename: string): TypeScript.SyntaxTree { - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); return syntaxTreeCache.getCurrentFileSyntaxTree(filename); } function getCurrentSourceFile(filename: string): SourceFile { - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var currentSourceFile = syntaxTreeCache.getCurrentSourceFile(filename); return currentSourceFile; } @@ -4913,14 +4913,14 @@ module ts { } function getNavigationBarItems(filename: string): NavigationBarItem[] { - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); return NavigationBar.getNavigationBarItems(getCurrentSourceFile(filename)); } function getSemanticClassifications(fileName: string, span: TypeScript.TextSpan): ClassifiedSpan[] { synchronizeHostData(); - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var sourceFile = getSourceFile(fileName); @@ -4991,7 +4991,7 @@ module ts { function getSyntacticClassifications(fileName: string, span: TypeScript.TextSpan): ClassifiedSpan[] { // doesn't use compiler - no need to synchronize with host - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var sourceFile = getCurrentSourceFile(fileName); var result: ClassifiedSpan[] = []; @@ -5121,7 +5121,7 @@ module ts { function getOutliningSpans(filename: string): OutliningSpan[] { // doesn't use compiler - no need to synchronize with host - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var sourceFile = getCurrentSourceFile(filename); return OutliningElementsCollector.collectElements(sourceFile); } @@ -5180,7 +5180,7 @@ module ts { } function getIndentationAtPosition(filename: string, position: number, editorOptions: EditorOptions) { - filename = switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var start = new Date().getTime(); var sourceFile = getCurrentSourceFile(filename); @@ -5217,21 +5217,21 @@ module ts { } function getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions): TextChange[] { - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var manager = getFormattingManager(fileName, options); return manager.formatSelection(start, end); } function getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[] { - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var manager = getFormattingManager(fileName, options); return manager.formatDocument(); } function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[] { - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var manager = getFormattingManager(fileName, options); @@ -5257,7 +5257,7 @@ module ts { // anything away. synchronizeHostData(); - filename = TypeScript.switchToForwardSlashes(filename); + filename = normalizeSlashes(filename); var sourceFile = getSourceFile(filename); @@ -5417,7 +5417,7 @@ module ts { function getRenameInfo(fileName: string, position: number): RenameInfo { synchronizeHostData(); - fileName = switchToForwardSlashes(fileName); + fileName = normalizeSlashes(fileName); var sourceFile = getSourceFile(fileName); var node = getTouchingWord(sourceFile, position); diff --git a/src/services/shims.ts b/src/services/shims.ts index 8c4da452b73..00acff3798a 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -858,7 +858,7 @@ module ts { forEach(result.referencedFiles, refFile => { convertResult.referencedFiles.push({ - path: switchToForwardSlashes(normalizePath(refFile.filename)), + path: normalizePath(refFile.filename), position: refFile.pos, length: refFile.end - refFile.pos }); @@ -866,7 +866,7 @@ module ts { forEach(result.importedFiles, importedFile => { convertResult.importedFiles.push({ - path: switchToForwardSlashes(importedFile.filename), + path: normalizeSlashes(importedFile.filename), position: importedFile.pos, length: importedFile.end - importedFile.pos }); diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 67ed16e7c85..88e3601b610 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -259,10 +259,6 @@ module ts { return n.kind === SyntaxKind.StringLiteral || n.kind === SyntaxKind.NumericLiteral || isWord(n); } - export var switchToForwardSlashesRegEx = /\\/g; - export function switchToForwardSlashes(path: string) { - return path.replace(switchToForwardSlashesRegEx, "/"); - } export function isComment(n: Node): boolean { return n.kind === SyntaxKind.SingleLineCommentTrivia || n.kind === SyntaxKind.MultiLineCommentTrivia; }