Skip to content

Commit 45b995d

Browse files
committed
Remove extensions doesnt need to depend on compiler options any more
1 parent a8eb76f commit 45b995d

9 files changed

Lines changed: 18 additions & 25 deletions

File tree

src/compiler/binder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ namespace ts {
7777
IsContainerWithLocals = IsContainer | HasLocals
7878
}
7979

80-
export function bindSourceFile(file: SourceFile, compilerOptions: CompilerOptions) {
80+
export function bindSourceFile(file: SourceFile) {
8181
let start = new Date().getTime();
82-
bindSourceFileWorker(file, compilerOptions);
82+
bindSourceFileWorker(file);
8383
bindTime += new Date().getTime() - start;
8484
}
8585

86-
function bindSourceFileWorker(file: SourceFile, compilerOptions: CompilerOptions) {
86+
function bindSourceFileWorker(file: SourceFile) {
8787
let parent: Node;
8888
let container: Node;
8989
let blockScopeContainer: Node;
@@ -949,7 +949,7 @@ namespace ts {
949949
function bindSourceFileIfExternalModule() {
950950
setExportContextFlag(file);
951951
if (isExternalModule(file)) {
952-
bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName, getSupportedExtensions(compilerOptions))}"`);
952+
bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName)}"`);
953953
}
954954
}
955955

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14871,7 +14871,7 @@ namespace ts {
1487114871
function initializeTypeChecker() {
1487214872
// Bind all source files and propagate errors
1487314873
forEach(host.getSourceFiles(), file => {
14874-
bindSourceFile(file, compilerOptions);
14874+
bindSourceFile(file);
1487514875
});
1487614876

1487714877
// Initialize global symbol table

src/compiler/core.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,8 @@ namespace ts {
747747
return false;
748748
}
749749

750-
export function removeFileExtension(path: string, supportedExtensions: string[]): string {
751-
// Sort the extensions in descending order of their length
752-
let extensionsToRemove = supportedExtensions.slice(0, supportedExtensions.length) // Get duplicate array
753-
.sort((ext1, ext2) => compareValues(ext2.length, ext1.length)); // Sort in descending order of extension length
750+
export const extensionsToRemove = ["d.ts", "ts", "js", "tsx", "jsx"];
751+
export function removeFileExtension(path: string): string {
754752
for (let ext of extensionsToRemove) {
755753
if (fileExtensionIs(path, ext)) {
756754
return path.substr(0, path.length - ext.length - 1);

src/compiler/utilities.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,19 +1759,14 @@ namespace ts {
17591759
};
17601760
}
17611761

1762-
export function getExtensionsToRemoveForEmitPath(compilerOptons: CompilerOptions) {
1763-
return getSupportedExtensions(compilerOptons).concat("jsx", "js");
1764-
}
1765-
17661762
export function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string) {
17671763
let compilerOptions = host.getCompilerOptions();
17681764
let emitOutputFilePathWithoutExtension: string;
17691765
if (compilerOptions.outDir) {
1770-
emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir),
1771-
getExtensionsToRemoveForEmitPath(compilerOptions));
1766+
emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
17721767
}
17731768
else {
1774-
emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName, getExtensionsToRemoveForEmitPath(compilerOptions));
1769+
emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName);
17751770
}
17761771

17771772
return emitOutputFilePathWithoutExtension + extension;
@@ -1816,7 +1811,7 @@ namespace ts {
18161811
}
18171812

18181813
function getDeclarationEmitFilePath(jsFilePath: string, options: CompilerOptions) {
1819-
return options.declaration ? removeFileExtension(jsFilePath, getExtensionsToRemoveForEmitPath(options)) + ".d.ts" : undefined;
1814+
return options.declaration ? removeFileExtension(jsFilePath) + ".d.ts" : undefined;
18201815
}
18211816

18221817
export function hasFile(sourceFiles: SourceFile[], fileName: string) {
@@ -2144,7 +2139,7 @@ namespace ts {
21442139

21452140
export function isJavaScript(fileName: string) {
21462141
// Treat file as typescript if the extension is not supportedTypeScript
2147-
return hasExtension(fileName) && !forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
2142+
return hasExtension(fileName) && forEach(supportedJavascriptExtensions, extension => fileExtensionIs(fileName, extension));
21482143
}
21492144

21502145
export function isTsx(fileName: string) {

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ namespace Harness {
11931193
sourceFileName = outFile;
11941194
}
11951195

1196-
let dTsFileName = ts.removeFileExtension(sourceFileName, ts.getExtensionsToRemoveForEmitPath(options)) + ".d.ts";
1196+
let dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts";
11971197

11981198
return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined);
11991199
}

src/harness/projectsRunner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,17 @@ class ProjectRunner extends RunnerBase {
354354
if (compilerOptions.outDir) {
355355
let sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, compilerResult.program.getCurrentDirectory());
356356
sourceFilePath = sourceFilePath.replace(compilerResult.program.getCommonSourceDirectory(), "");
357-
emitOutputFilePathWithoutExtension = ts.removeFileExtension(ts.combinePaths(compilerOptions.outDir, sourceFilePath), ts.getExtensionsToRemoveForEmitPath(compilerOptions));
357+
emitOutputFilePathWithoutExtension = ts.removeFileExtension(ts.combinePaths(compilerOptions.outDir, sourceFilePath));
358358
}
359359
else {
360-
emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName, ts.getExtensionsToRemoveForEmitPath(compilerOptions));
360+
emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName);
361361
}
362362

363363
let outputDtsFileName = emitOutputFilePathWithoutExtension + ".d.ts";
364364
allInputFiles.unshift(findOutpuDtsFile(outputDtsFileName));
365365
}
366366
else {
367-
let outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out, ts.getExtensionsToRemoveForEmitPath(compilerOptions)) + ".d.ts";
367+
let outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts";
368368
let outputDtsFile = findOutpuDtsFile(outputDtsFileName);
369369
if (!ts.contains(allInputFiles, outputDtsFile)) {
370370
allInputFiles.unshift(outputDtsFile);

src/harness/test262Runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Test262BaselineRunner extends RunnerBase {
3737

3838
before(() => {
3939
let content = Harness.IO.readFile(filePath);
40-
let testFilename = ts.removeFileExtension(filePath, ["js"]).replace(/\//g, "_") + ".test";
40+
let testFilename = ts.removeFileExtension(filePath).replace(/\//g, "_") + ".test";
4141
let testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, testFilename);
4242

4343
let inputFiles = testCaseContent.testUnitData.map(unit => {

src/services/navigationBar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ namespace ts.NavigationBar {
442442

443443
hasGlobalNode = true;
444444
let rootName = isExternalModule(node)
445-
? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName), getSupportedExtensions(compilerOptions)))) + "\""
445+
? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName)))) + "\""
446446
: "<global>"
447447

448448
return getNavigationBarItem(rootName,

tests/cases/unittests/transpile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module ts {
6464
let transpileModuleResultWithSourceMap = transpileModule(input, transpileOptions);
6565
assert.isTrue(transpileModuleResultWithSourceMap.sourceMapText !== undefined);
6666

67-
let expectedSourceMapFileName = removeFileExtension(getBaseFileName(normalizeSlashes(transpileOptions.fileName)), ts.getExtensionsToRemoveForEmitPath(transpileOptions.compilerOptions)) + ".js.map";
67+
let expectedSourceMapFileName = removeFileExtension(getBaseFileName(normalizeSlashes(transpileOptions.fileName))) + ".js.map";
6868
let expectedSourceMappingUrlLine = `//# sourceMappingURL=${expectedSourceMapFileName}`;
6969

7070
if (testSettings.expectedOutput !== undefined) {

0 commit comments

Comments
 (0)