Skip to content

Commit 2d3a345

Browse files
committed
Since there arent any user given extensions, have extensions start with "." like before
1 parent 45b995d commit 2d3a345

16 files changed

Lines changed: 36 additions & 36 deletions

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ namespace ts {
515515
if (!hasConflictingExtension) {
516516
// Add the file only if there is no higher priority extension file already included
517517
// eg. when a.d.ts and a.js are present in the folder, include only a.d.ts not a.js
518-
const baseName = fileName.substr(0, fileName.length - currentExtension.length - 1);
518+
const baseName = fileName.substr(0, fileName.length - currentExtension.length);
519519
if (!hasProperty(filesSeen, baseName)) {
520520
filesSeen[baseName] = true;
521521
fileNames.push(fileName);

src/compiler/core.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,15 +721,15 @@ namespace ts {
721721

722722
export function fileExtensionIs(path: string, extension: string): boolean {
723723
let pathLen = path.length;
724-
let extLen = extension.length + 1;
725-
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === "." + extension;
724+
let extLen = extension.length;
725+
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
726726
}
727727

728728
/**
729729
* List of supported extensions in order of file resolution precedence.
730730
*/
731-
export const supportedTypeScriptExtensions = ["ts", "tsx", "d.ts"];
732-
export const supportedJavascriptExtensions = ["js", "jsx"];
731+
export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"];
732+
export const supportedJavascriptExtensions = [".js", ".jsx"];
733733
export const supportedExtensionsWhenAllowedJs = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);
734734

735735
export function getSupportedExtensions(options?: CompilerOptions): string[] {
@@ -747,11 +747,11 @@ namespace ts {
747747
return false;
748748
}
749749

750-
export const extensionsToRemove = ["d.ts", "ts", "js", "tsx", "jsx"];
750+
export const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
751751
export function removeFileExtension(path: string): string {
752752
for (let ext of extensionsToRemove) {
753753
if (fileExtensionIs(path, ext)) {
754-
return path.substr(0, path.length - ext.length - 1);
754+
return path.substr(0, path.length - ext.length);
755755
}
756756
}
757757
return path;

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ namespace ts {
669669
sourceFile.bindDiagnostics = [];
670670
sourceFile.languageVersion = languageVersion;
671671
sourceFile.fileName = normalizePath(fileName);
672-
sourceFile.flags = fileExtensionIs(sourceFile.fileName, "d.ts") ? NodeFlags.DeclarationFile : 0;
672+
sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0;
673673
sourceFile.languageVariant = getLanguageVariant(sourceFile.fileName);
674674

675675
return sourceFile;

src/compiler/program.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace ts {
7373
return forEach(supportedExtensions, tryLoad);
7474

7575
function tryLoad(ext: string): string {
76-
let fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + "." + ext;
76+
let fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext;
7777
if (host.fileExists(fileName)) {
7878
return fileName;
7979
}
@@ -165,13 +165,13 @@ namespace ts {
165165
while (true) {
166166
searchName = normalizePath(combinePaths(searchPath, moduleName));
167167
referencedSourceFile = forEach(getSupportedExtensions(compilerOptions), extension => {
168-
if (extension === "tsx" && !compilerOptions.jsx) {
168+
if (extension === ".tsx" && !compilerOptions.jsx) {
169169
// resolve .tsx files only if jsx support is enabled
170170
// 'logical not' handles both undefined and None cases
171171
return undefined;
172172
}
173173

174-
let candidate = searchName + "." + extension;
174+
let candidate = searchName + extension;
175175
if (host.fileExists(candidate)) {
176176
return candidate;
177177
}
@@ -964,7 +964,7 @@ namespace ts {
964964
diagnostic = Diagnostics.File_0_not_found;
965965
diagnosticArgument = [fileName];
966966
}
967-
else if (!forEach(getSupportedExtensions(options), extension => findSourceFile(fileName + "." + extension, isDefaultLib, supportedExtensions, refFile, refPos, refEnd))) {
967+
else if (!forEach(getSupportedExtensions(options), extension => findSourceFile(fileName + extension, isDefaultLib, supportedExtensions, refFile, refPos, refEnd))) {
968968
// (TODO: shkamat) Should this message be different given we support multiple extensions
969969
diagnostic = Diagnostics.File_0_not_found;
970970
fileName += ".ts";
@@ -1077,7 +1077,7 @@ namespace ts {
10771077
let start = getTokenPosOfNode(file.imports[i], file);
10781078
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));
10791079
}
1080-
else if (!fileExtensionIs(importedFile.fileName, "d.ts")) {
1080+
else if (!fileExtensionIs(importedFile.fileName, ".d.ts")) {
10811081
let start = getTokenPosOfNode(file.imports[i], file);
10821082
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));
10831083
}

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ namespace ts {
21432143
}
21442144

21452145
export function isTsx(fileName: string) {
2146-
return fileExtensionIs(fileName, "tsx");
2146+
return fileExtensionIs(fileName, ".tsx");
21472147
}
21482148

21492149
/**

src/harness/compilerRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class CompilerBaselineRunner extends RunnerBase {
151151
});
152152

153153
it("Correct JS output for " + fileName, () => {
154-
if (!(units.length === 1 && ts.fileExtensionIs(lastUnit.name, "d.ts")) && this.emit) {
154+
if (!(units.length === 1 && ts.fileExtensionIs(lastUnit.name, ".d.ts")) && this.emit) {
155155
if (result.files.length === 0 && result.errors.length === 0) {
156156
throw new Error("Expected at least one js file to be emitted or at least one error to be created.");
157157
}

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ namespace ts {
18751875
let compilerHost: CompilerHost = {
18761876
getSourceFile: (fileName, target) => fileName === normalizeSlashes(inputFileName) ? sourceFile : undefined,
18771877
writeFile: (name, text, writeByteOrderMark) => {
1878-
if (fileExtensionIs(name, "map")) {
1878+
if (fileExtensionIs(name, ".map")) {
18791879
Debug.assert(sourceMapText === undefined, `Unexpected multiple source map outputs for the file '${name}'`);
18801880
sourceMapText = text;
18811881
}

tests/baselines/reference/jsFileCompilationWithMapFileAsJs.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/b.js' which is one of the input files.
2-
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts', 'js', 'jsx'.
2+
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
33

44

55
!!! error TS5055: Cannot write file 'tests/cases/compiler/b.js' which is one of the input files.
6-
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts', 'js', 'jsx'.
6+
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
77
==== tests/cases/compiler/a.ts (0 errors) ====
88

99
class c {

tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithInlineSourceMap.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error TS5055: Cannot write file 'tests/cases/compiler/b.js' which is one of the input files.
2-
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts', 'js', 'jsx'.
2+
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
33

44

55
!!! error TS5055: Cannot write file 'tests/cases/compiler/b.js' which is one of the input files.
6-
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts', 'js', 'jsx'.
6+
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts', '.js', '.jsx'.
77
==== tests/cases/compiler/a.ts (0 errors) ====
88

99
class c {

tests/baselines/reference/jsFileCompilationWithMapFileAsJsWithOutDir.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
error TS6054: File 'tests/cases/compiler/b.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'.
2-
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'.
1+
error TS6054: File 'tests/cases/compiler/b.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
2+
error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
33

44

5-
!!! error TS6054: File 'tests/cases/compiler/b.js' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'.
6-
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are 'ts', 'tsx', 'd.ts'.
5+
!!! error TS6054: File 'tests/cases/compiler/b.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
6+
!!! error TS6054: File 'tests/cases/compiler/b.js.map' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'.
77
==== tests/cases/compiler/a.ts (0 errors) ====
88

99
class c {

0 commit comments

Comments
 (0)