mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-16 15:44:16 -06:00
Remove extensions doesnt need to depend on compiler options any more
This commit is contained in:
parent
a8eb76fde1
commit
45b995d030
@ -77,13 +77,13 @@ namespace ts {
|
||||
IsContainerWithLocals = IsContainer | HasLocals
|
||||
}
|
||||
|
||||
export function bindSourceFile(file: SourceFile, compilerOptions: CompilerOptions) {
|
||||
export function bindSourceFile(file: SourceFile) {
|
||||
let start = new Date().getTime();
|
||||
bindSourceFileWorker(file, compilerOptions);
|
||||
bindSourceFileWorker(file);
|
||||
bindTime += new Date().getTime() - start;
|
||||
}
|
||||
|
||||
function bindSourceFileWorker(file: SourceFile, compilerOptions: CompilerOptions) {
|
||||
function bindSourceFileWorker(file: SourceFile) {
|
||||
let parent: Node;
|
||||
let container: Node;
|
||||
let blockScopeContainer: Node;
|
||||
@ -949,7 +949,7 @@ namespace ts {
|
||||
function bindSourceFileIfExternalModule() {
|
||||
setExportContextFlag(file);
|
||||
if (isExternalModule(file)) {
|
||||
bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName, getSupportedExtensions(compilerOptions))}"`);
|
||||
bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName)}"`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14871,7 +14871,7 @@ namespace ts {
|
||||
function initializeTypeChecker() {
|
||||
// Bind all source files and propagate errors
|
||||
forEach(host.getSourceFiles(), file => {
|
||||
bindSourceFile(file, compilerOptions);
|
||||
bindSourceFile(file);
|
||||
});
|
||||
|
||||
// Initialize global symbol table
|
||||
|
||||
@ -747,10 +747,8 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function removeFileExtension(path: string, supportedExtensions: string[]): string {
|
||||
// Sort the extensions in descending order of their length
|
||||
let extensionsToRemove = supportedExtensions.slice(0, supportedExtensions.length) // Get duplicate array
|
||||
.sort((ext1, ext2) => compareValues(ext2.length, ext1.length)); // Sort in descending order of extension length
|
||||
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);
|
||||
|
||||
@ -1759,19 +1759,14 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
export function getExtensionsToRemoveForEmitPath(compilerOptons: CompilerOptions) {
|
||||
return getSupportedExtensions(compilerOptons).concat("jsx", "js");
|
||||
}
|
||||
|
||||
export function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string) {
|
||||
let compilerOptions = host.getCompilerOptions();
|
||||
let emitOutputFilePathWithoutExtension: string;
|
||||
if (compilerOptions.outDir) {
|
||||
emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir),
|
||||
getExtensionsToRemoveForEmitPath(compilerOptions));
|
||||
emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir));
|
||||
}
|
||||
else {
|
||||
emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName, getExtensionsToRemoveForEmitPath(compilerOptions));
|
||||
emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName);
|
||||
}
|
||||
|
||||
return emitOutputFilePathWithoutExtension + extension;
|
||||
@ -1816,7 +1811,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getDeclarationEmitFilePath(jsFilePath: string, options: CompilerOptions) {
|
||||
return options.declaration ? removeFileExtension(jsFilePath, getExtensionsToRemoveForEmitPath(options)) + ".d.ts" : undefined;
|
||||
return options.declaration ? removeFileExtension(jsFilePath) + ".d.ts" : undefined;
|
||||
}
|
||||
|
||||
export function hasFile(sourceFiles: SourceFile[], fileName: string) {
|
||||
@ -2144,7 +2139,7 @@ namespace ts {
|
||||
|
||||
export function isJavaScript(fileName: string) {
|
||||
// Treat file as typescript if the extension is not supportedTypeScript
|
||||
return hasExtension(fileName) && !forEach(supportedTypeScriptExtensions, extension => fileExtensionIs(fileName, extension));
|
||||
return hasExtension(fileName) && forEach(supportedJavascriptExtensions, extension => fileExtensionIs(fileName, extension));
|
||||
}
|
||||
|
||||
export function isTsx(fileName: string) {
|
||||
|
||||
@ -1193,7 +1193,7 @@ namespace Harness {
|
||||
sourceFileName = outFile;
|
||||
}
|
||||
|
||||
let dTsFileName = ts.removeFileExtension(sourceFileName, ts.getExtensionsToRemoveForEmitPath(options)) + ".d.ts";
|
||||
let dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts";
|
||||
|
||||
return ts.forEach(result.declFilesCode, declFile => declFile.fileName === dTsFileName ? declFile : undefined);
|
||||
}
|
||||
|
||||
@ -354,17 +354,17 @@ class ProjectRunner extends RunnerBase {
|
||||
if (compilerOptions.outDir) {
|
||||
let sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, compilerResult.program.getCurrentDirectory());
|
||||
sourceFilePath = sourceFilePath.replace(compilerResult.program.getCommonSourceDirectory(), "");
|
||||
emitOutputFilePathWithoutExtension = ts.removeFileExtension(ts.combinePaths(compilerOptions.outDir, sourceFilePath), ts.getExtensionsToRemoveForEmitPath(compilerOptions));
|
||||
emitOutputFilePathWithoutExtension = ts.removeFileExtension(ts.combinePaths(compilerOptions.outDir, sourceFilePath));
|
||||
}
|
||||
else {
|
||||
emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName, ts.getExtensionsToRemoveForEmitPath(compilerOptions));
|
||||
emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.fileName);
|
||||
}
|
||||
|
||||
let outputDtsFileName = emitOutputFilePathWithoutExtension + ".d.ts";
|
||||
allInputFiles.unshift(findOutpuDtsFile(outputDtsFileName));
|
||||
}
|
||||
else {
|
||||
let outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out, ts.getExtensionsToRemoveForEmitPath(compilerOptions)) + ".d.ts";
|
||||
let outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts";
|
||||
let outputDtsFile = findOutpuDtsFile(outputDtsFileName);
|
||||
if (!ts.contains(allInputFiles, outputDtsFile)) {
|
||||
allInputFiles.unshift(outputDtsFile);
|
||||
|
||||
@ -37,7 +37,7 @@ class Test262BaselineRunner extends RunnerBase {
|
||||
|
||||
before(() => {
|
||||
let content = Harness.IO.readFile(filePath);
|
||||
let testFilename = ts.removeFileExtension(filePath, ["js"]).replace(/\//g, "_") + ".test";
|
||||
let testFilename = ts.removeFileExtension(filePath).replace(/\//g, "_") + ".test";
|
||||
let testCaseContent = Harness.TestCaseParser.makeUnitsFromTest(content, testFilename);
|
||||
|
||||
let inputFiles = testCaseContent.testUnitData.map(unit => {
|
||||
|
||||
@ -442,7 +442,7 @@ namespace ts.NavigationBar {
|
||||
|
||||
hasGlobalNode = true;
|
||||
let rootName = isExternalModule(node)
|
||||
? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName), getSupportedExtensions(compilerOptions)))) + "\""
|
||||
? "\"" + escapeString(getBaseFileName(removeFileExtension(normalizePath(node.fileName)))) + "\""
|
||||
: "<global>"
|
||||
|
||||
return getNavigationBarItem(rootName,
|
||||
|
||||
@ -64,7 +64,7 @@ module ts {
|
||||
let transpileModuleResultWithSourceMap = transpileModule(input, transpileOptions);
|
||||
assert.isTrue(transpileModuleResultWithSourceMap.sourceMapText !== undefined);
|
||||
|
||||
let expectedSourceMapFileName = removeFileExtension(getBaseFileName(normalizeSlashes(transpileOptions.fileName)), ts.getExtensionsToRemoveForEmitPath(transpileOptions.compilerOptions)) + ".js.map";
|
||||
let expectedSourceMapFileName = removeFileExtension(getBaseFileName(normalizeSlashes(transpileOptions.fileName))) + ".js.map";
|
||||
let expectedSourceMappingUrlLine = `//# sourceMappingURL=${expectedSourceMapFileName}`;
|
||||
|
||||
if (testSettings.expectedOutput !== undefined) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user