diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d1a6e56d818..fb58384c469 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -515,7 +515,7 @@ namespace ts { if (!hasConflictingExtension) { // Add the file only if there is no higher priority extension file already included // eg. when a.d.ts and a.js are present in the folder, include only a.d.ts not a.js - const baseName = fileName.substr(0, fileName.length - currentExtension.length - 1); + const baseName = fileName.substr(0, fileName.length - currentExtension.length); if (!hasProperty(filesSeen, baseName)) { filesSeen[baseName] = true; fileNames.push(fileName); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 26e53aebab1..018f3022191 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -721,15 +721,15 @@ namespace ts { export function fileExtensionIs(path: string, extension: string): boolean { let pathLen = path.length; - let extLen = extension.length + 1; - return pathLen > extLen && path.substr(pathLen - extLen, extLen) === "." + extension; + let extLen = extension.length; + return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; } /** * List of supported extensions in order of file resolution precedence. */ - export const supportedTypeScriptExtensions = ["ts", "tsx", "d.ts"]; - export const supportedJavascriptExtensions = ["js", "jsx"]; + export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"]; + export const supportedJavascriptExtensions = [".js", ".jsx"]; export const supportedExtensionsWhenAllowedJs = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions); export function getSupportedExtensions(options?: CompilerOptions): string[] { @@ -747,11 +747,11 @@ namespace ts { return false; } - export const extensionsToRemove = ["d.ts", "ts", "js", "tsx", "jsx"]; + export const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"]; export function removeFileExtension(path: string): string { for (let ext of extensionsToRemove) { if (fileExtensionIs(path, ext)) { - return path.substr(0, path.length - ext.length - 1); + return path.substr(0, path.length - ext.length); } } return path; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d8d2b2fdb26..a1076464bbd 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -669,7 +669,7 @@ namespace ts { sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = normalizePath(fileName); - sourceFile.flags = fileExtensionIs(sourceFile.fileName, "d.ts") ? NodeFlags.DeclarationFile : 0; + sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0; sourceFile.languageVariant = getLanguageVariant(sourceFile.fileName); return sourceFile; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ccb2d2c346e..db56f86e93b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -73,7 +73,7 @@ namespace ts { return forEach(supportedExtensions, tryLoad); function tryLoad(ext: string): string { - let fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + "." + ext; + let fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext; if (host.fileExists(fileName)) { return fileName; } @@ -165,13 +165,13 @@ namespace ts { while (true) { searchName = normalizePath(combinePaths(searchPath, moduleName)); referencedSourceFile = forEach(getSupportedExtensions(compilerOptions), extension => { - if (extension === "tsx" && !compilerOptions.jsx) { + if (extension === ".tsx" && !compilerOptions.jsx) { // resolve .tsx files only if jsx support is enabled // 'logical not' handles both undefined and None cases return undefined; } - let candidate = searchName + "." + extension; + let candidate = searchName + extension; if (host.fileExists(candidate)) { return candidate; } @@ -964,7 +964,7 @@ namespace ts { diagnostic = Diagnostics.File_0_not_found; diagnosticArgument = [fileName]; } - else if (!forEach(getSupportedExtensions(options), extension => findSourceFile(fileName + "." + extension, isDefaultLib, supportedExtensions, refFile, refPos, refEnd))) { + else if (!forEach(getSupportedExtensions(options), extension => findSourceFile(fileName + extension, isDefaultLib, supportedExtensions, refFile, refPos, refEnd))) { // (TODO: shkamat) Should this message be different given we support multiple extensions diagnostic = Diagnostics.File_0_not_found; fileName += ".ts"; @@ -1077,7 +1077,7 @@ namespace ts { let start = getTokenPosOfNode(file.imports[i], file); fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition, importedFile.fileName)); } - else if (!fileExtensionIs(importedFile.fileName, "d.ts")) { + else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) { let start = getTokenPosOfNode(file.imports[i], file); fileProcessingDiagnostics.add(createFileDiagnostic(file, start, file.imports[i].end - start, Diagnostics.Exported_external_package_typings_can_only_be_in_d_ts_files_Please_contact_the_package_author_to_update_the_package_definition)); } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 7c88e1a9417..885d529f69e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2143,7 +2143,7 @@ namespace ts { } export function isTsx(fileName: string) { - return fileExtensionIs(fileName, "tsx"); + return fileExtensionIs(fileName, ".tsx"); } /** diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index e3c48e33e5c..11c1b9a8029 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -151,7 +151,7 @@ class CompilerBaselineRunner extends RunnerBase { }); it("Correct JS output for " + fileName, () => { - if (!(units.length === 1 && ts.fileExtensionIs(lastUnit.name, "d.ts")) && this.emit) { + if (!(units.length === 1 && ts.fileExtensionIs(lastUnit.name, ".d.ts")) && this.emit) { if (result.files.length === 0 && result.errors.length === 0) { throw new Error("Expected at least one js file to be emitted or at least one error to be created."); } diff --git a/src/services/services.ts b/src/services/services.ts index dce341cc035..d80e60d171b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1875,7 +1875,7 @@ namespace ts { let compilerHost: CompilerHost = { getSourceFile: (fileName, target) => fileName === normalizeSlashes(inputFileName) ? sourceFile : undefined, writeFile: (name, text, writeByteOrderMark) => { - if (fileExtensionIs(name, "map")) { + if (fileExtensionIs(name, ".map")) { Debug.assert(sourceMapText === undefined, `Unexpected multiple source map outputs for the file '${name}'`); sourceMapText = text; } diff --git a/tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt b/tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt index aaeb023dbdb..a97dc2c3cd6 100644 --- a/tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt @@ -1,9 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/b.js' which is one of the input files. -error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts', 'js', 'jsx'. +error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'. !!! error TS5055: Cannot write file 'tests/cases/compiler/b.js' which is one of the input files. -!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts', 'js', 'jsx'. +!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'. ==== tests/cases/compiler/a.ts (0 errors) ==== class c { diff --git a/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt b/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt index aaeb023dbdb..a97dc2c3cd6 100644 --- a/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt @@ -1,9 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/b.js' which is one of the input files. -error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts', 'js', 'jsx'. +error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'. !!! error TS5055: Cannot write file 'tests/cases/compiler/b.js' which is one of the input files. -!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts', 'js', 'jsx'. +!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'. ==== tests/cases/compiler/a.ts (0 errors) ==== class c { diff --git a/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithOutDir.errors.txt b/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithOutDir.errors.txt index 81d9b67d334..c9a4408f423 100644 --- a/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithOutDir.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithOutDir.errors.txt @@ -1,9 +1,9 @@ -error TS6054: File 'tests/cases/compiler/b.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. -error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +error TS6054: File 'tests/cases/compiler/b.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. +error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. -!!! error TS6054: File 'tests/cases/compiler/b.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. -!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +!!! error TS6054: File 'tests/cases/compiler/b.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. +!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. ==== tests/cases/compiler/a.ts (0 errors) ==== class c { diff --git a/tests/baselines/reference/jsFileCompilationWithoutJsExtensions.errors.txt b/tests/baselines/reference/jsFileCompilationWithoutJsExtensions.errors.txt index 4276669ff76..0b1a757d4fd 100644 --- a/tests/baselines/reference/jsFileCompilationWithoutJsExtensions.errors.txt +++ b/tests/baselines/reference/jsFileCompilationWithoutJsExtensions.errors.txt @@ -1,6 +1,6 @@ -error TS6054: File 'tests/cases/compiler/a.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +error TS6054: File 'tests/cases/compiler/a.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. -!!! error TS6054: File 'tests/cases/compiler/a.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +!!! error TS6054: File 'tests/cases/compiler/a.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. ==== tests/cases/compiler/a.js (0 errors) ==== declare var v; \ No newline at end of file diff --git a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt index 76d5def7b5c..9cd0dd7b0cf 100644 --- a/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt +++ b/tests/baselines/reference/project/invalidRootFile/amd/invalidRootFile.errors.txt @@ -1,6 +1,6 @@ error TS6053: File 'a.ts' not found. -error TS6054: File 'a.t' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. !!! error TS6053: File 'a.ts' not found. -!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. \ No newline at end of file +!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. \ No newline at end of file diff --git a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt index 76d5def7b5c..9cd0dd7b0cf 100644 --- a/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt +++ b/tests/baselines/reference/project/invalidRootFile/node/invalidRootFile.errors.txt @@ -1,6 +1,6 @@ error TS6053: File 'a.ts' not found. -error TS6054: File 'a.t' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. !!! error TS6053: File 'a.ts' not found. -!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. \ No newline at end of file +!!! error TS6054: File 'a.t' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. \ No newline at end of file diff --git a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecified/amd/jsFileCompilationDifferentNamesSpecified.errors.txt b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecified/amd/jsFileCompilationDifferentNamesSpecified.errors.txt index a7fd60e03d5..5fa60d18af9 100644 --- a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecified/amd/jsFileCompilationDifferentNamesSpecified.errors.txt +++ b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecified/amd/jsFileCompilationDifferentNamesSpecified.errors.txt @@ -1,6 +1,6 @@ -error TS6054: File 'DifferentNamesSpecified/b.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +error TS6054: File 'DifferentNamesSpecified/b.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. -!!! error TS6054: File 'DifferentNamesSpecified/b.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +!!! error TS6054: File 'DifferentNamesSpecified/b.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. ==== DifferentNamesSpecified/a.ts (0 errors) ==== var test = 10; \ No newline at end of file diff --git a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecified/node/jsFileCompilationDifferentNamesSpecified.errors.txt b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecified/node/jsFileCompilationDifferentNamesSpecified.errors.txt index a7fd60e03d5..5fa60d18af9 100644 --- a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecified/node/jsFileCompilationDifferentNamesSpecified.errors.txt +++ b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecified/node/jsFileCompilationDifferentNamesSpecified.errors.txt @@ -1,6 +1,6 @@ -error TS6054: File 'DifferentNamesSpecified/b.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +error TS6054: File 'DifferentNamesSpecified/b.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. -!!! error TS6054: File 'DifferentNamesSpecified/b.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'. +!!! error TS6054: File 'DifferentNamesSpecified/b.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. ==== DifferentNamesSpecified/a.ts (0 errors) ==== var test = 10; \ No newline at end of file diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index 6f9497fde1d..a1767f58026 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -38,7 +38,7 @@ module ts { function testLoadAsFile(containingFileName: string, moduleFileNameNoExt: string, moduleName: string): void { for (let ext of supportedTypeScriptExtensions) { let containingFile = { name: containingFileName } - let moduleFile = { name: moduleFileNameNoExt + "." + ext } + let moduleFile = { name: moduleFileNameNoExt + ext } let resolution = nodeModuleNameResolver(moduleName, containingFile.name, supportedTypeScriptExtensions, createModuleResolutionHost(containingFile, moduleFile)); assert.equal(resolution.resolvedModule.resolvedFileName, moduleFile.name); assert.equal(!!resolution.resolvedModule.isExternalLibraryImport, false); @@ -50,7 +50,7 @@ module ts { break; } else { - failedLookupLocations.push(normalizePath(getRootLength(moduleName) === 0 ? combinePaths(dir, moduleName) : moduleName) + "." + e); + failedLookupLocations.push(normalizePath(getRootLength(moduleName) === 0 ? combinePaths(dir, moduleName) : moduleName) + e); } }