Add getEmitOutput and update call to getCurrentDirectory
This commit is contained in:
parent
da1becccf7
commit
d52fe20df3
|
@ -383,11 +383,12 @@ module ts {
|
||||||
return [path.substr(0, rootLength)].concat(normalizedParts);
|
return [path.substr(0, rootLength)].concat(normalizedParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNormalizedPathComponents(path: string, currentDirectory: string) {
|
export function getNormalizedPathComponents(path: string, getCurrentDirectory: ()=>string) {
|
||||||
var path = normalizeSlashes(path);
|
var path = normalizeSlashes(path);
|
||||||
var rootLength = getRootLength(path);
|
var rootLength = getRootLength(path);
|
||||||
if (rootLength == 0) {
|
if (rootLength == 0) {
|
||||||
// If the path is not rooted it is relative to current directory
|
// If the path is not rooted it is relative to current directory
|
||||||
|
var currentDirectory = getCurrentDirectory();
|
||||||
path = combinePaths(normalizeSlashes(currentDirectory), path);
|
path = combinePaths(normalizeSlashes(currentDirectory), path);
|
||||||
rootLength = getRootLength(path);
|
rootLength = getRootLength(path);
|
||||||
}
|
}
|
||||||
|
@ -443,18 +444,18 @@ module ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNormalizedPathOrUrlComponents(pathOrUrl: string, currentDirectory: string) {
|
function getNormalizedPathOrUrlComponents(pathOrUrl: string, getCurrentDirectory: ()=>string) {
|
||||||
if (isUrl(pathOrUrl)) {
|
if (isUrl(pathOrUrl)) {
|
||||||
return getNormalizedPathComponentsOfUrl(pathOrUrl);
|
return getNormalizedPathComponentsOfUrl(pathOrUrl);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return getNormalizedPathComponents(pathOrUrl, currentDirectory);
|
return getNormalizedPathComponents(pathOrUrl, getCurrentDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, isAbsolutePathAnUrl: boolean) {
|
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, getCurrentDirectory: () => string, isAbsolutePathAnUrl: boolean) {
|
||||||
var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
|
var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, getCurrentDirectory);
|
||||||
var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
|
var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, getCurrentDirectory);
|
||||||
if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") {
|
if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") {
|
||||||
// If the directory path given was of type test/cases/ then we really need components of directry to be only till its name
|
// If the directory path given was of type test/cases/ then we really need components of directry to be only till its name
|
||||||
// that is ["test", "cases", ""] needs to be actually ["test", "cases"]
|
// that is ["test", "cases", ""] needs to be actually ["test", "cases"]
|
||||||
|
|
|
@ -34,7 +34,7 @@ module ts {
|
||||||
var newLine = program.getCompilerHost().getNewLine();
|
var newLine = program.getCompilerHost().getNewLine();
|
||||||
|
|
||||||
function getSourceFilePathInNewDir(newDirPath: string, sourceFile: SourceFile) {
|
function getSourceFilePathInNewDir(newDirPath: string, sourceFile: SourceFile) {
|
||||||
var sourceFilePath = getNormalizedPathFromPathCompoments(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory()));
|
var sourceFilePath = getNormalizedPathFromPathCompoments(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory));
|
||||||
sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
|
sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
|
||||||
return combinePaths(newDirPath, sourceFilePath);
|
return combinePaths(newDirPath, sourceFilePath);
|
||||||
}
|
}
|
||||||
|
@ -523,7 +523,7 @@ module ts {
|
||||||
|
|
||||||
sourceMapData.sourceMapSources.push(getRelativePathToDirectoryOrUrl(sourcesDirectoryPath,
|
sourceMapData.sourceMapSources.push(getRelativePathToDirectoryOrUrl(sourcesDirectoryPath,
|
||||||
node.filename,
|
node.filename,
|
||||||
compilerHost.getCurrentDirectory(),
|
compilerHost.getCurrentDirectory,
|
||||||
/*isAbsolutePathAnUrl*/ true));
|
/*isAbsolutePathAnUrl*/ true));
|
||||||
sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
|
sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
|
||||||
|
|
||||||
|
@ -640,7 +640,7 @@ module ts {
|
||||||
sourceMapData.jsSourceMappingURL = getRelativePathToDirectoryOrUrl(
|
sourceMapData.jsSourceMappingURL = getRelativePathToDirectoryOrUrl(
|
||||||
getDirectoryPath(normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath
|
getDirectoryPath(normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath
|
||||||
combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap
|
combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap
|
||||||
compilerHost.getCurrentDirectory(),
|
compilerHost.getCurrentDirectory,
|
||||||
/*isAbsolutePathAnUrl*/ true);
|
/*isAbsolutePathAnUrl*/ true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3089,7 +3089,7 @@ module ts {
|
||||||
declFileName = getRelativePathToDirectoryOrUrl(
|
declFileName = getRelativePathToDirectoryOrUrl(
|
||||||
getDirectoryPath(normalizeSlashes(jsFilePath)),
|
getDirectoryPath(normalizeSlashes(jsFilePath)),
|
||||||
declFileName,
|
declFileName,
|
||||||
compilerHost.getCurrentDirectory(),
|
compilerHost.getCurrentDirectory,
|
||||||
/*isAbsolutePathAnUrl*/ false);
|
/*isAbsolutePathAnUrl*/ false);
|
||||||
|
|
||||||
referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
|
referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
|
||||||
|
|
|
@ -3817,7 +3817,7 @@ module ts {
|
||||||
// Each file contributes into common source file path
|
// Each file contributes into common source file path
|
||||||
if (!(sourceFile.flags & NodeFlags.DeclarationFile)
|
if (!(sourceFile.flags & NodeFlags.DeclarationFile)
|
||||||
&& !fileExtensionIs(sourceFile.filename, ".js")) {
|
&& !fileExtensionIs(sourceFile.filename, ".js")) {
|
||||||
var sourcePathCompoments = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory());
|
var sourcePathCompoments = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory);
|
||||||
sourcePathCompoments.pop(); // FileName is not part of directory
|
sourcePathCompoments.pop(); // FileName is not part of directory
|
||||||
if (commonPathComponents) {
|
if (commonPathComponents) {
|
||||||
for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathCompoments.length); i++) {
|
for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathCompoments.length); i++) {
|
||||||
|
|
|
@ -2852,7 +2852,7 @@ module ts {
|
||||||
var emitDeclaration = program.getCompilerOptions().declaration;
|
var emitDeclaration = program.getCompilerOptions().declaration;
|
||||||
var emitResult: EmitOutput = {
|
var emitResult: EmitOutput = {
|
||||||
outputFiles: [],
|
outputFiles: [],
|
||||||
emitOutputResult: null,
|
emitOutputResult: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize writter for CompilerHost.writeFile
|
// Initialize writter for CompilerHost.writeFile
|
||||||
|
@ -2862,37 +2862,40 @@ module ts {
|
||||||
writeByteOrderMark: writeByteOrderMark,
|
writeByteOrderMark: writeByteOrderMark,
|
||||||
text: data
|
text: data
|
||||||
}
|
}
|
||||||
|
|
||||||
emitResult.outputFiles.push(outputFile);
|
emitResult.outputFiles.push(outputFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get syntactic diagnostics
|
|
||||||
var syntacticDiagnostics = emitToSingleFile
|
var syntacticDiagnostics = emitToSingleFile
|
||||||
? program.getDiagnostics(getSourceFile(filename).getSourceFile())
|
? program.getDiagnostics(getSourceFile(filename).getSourceFile())
|
||||||
: program.getDiagnostics();
|
: program.getDiagnostics();
|
||||||
program.getGlobalDiagnostics();
|
program.getGlobalDiagnostics();
|
||||||
|
|
||||||
|
// If there is any syntactic error, terminate the process
|
||||||
if (containErrors(syntacticDiagnostics)) {
|
if (containErrors(syntacticDiagnostics)) {
|
||||||
emitResult.emitOutputResult = EmitOutputResult.FailedBecauseOfSyntaxErrors;
|
emitResult.emitOutputResult = EmitOutputResult.FailedBecauseOfSyntaxErrors;
|
||||||
return emitResult;
|
return emitResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform semantic and forace a type check before emit to ensure that all symbols are updated
|
// Perform semantic and force a type check before emit to ensure that all symbols are updated
|
||||||
var semanticDiagnostics = emitToSingleFile
|
var semanticDiagnostics = emitToSingleFile
|
||||||
? getFullTypeCheckChecker().getDiagnostics(getSourceFile(filename).getSourceFile())
|
? getFullTypeCheckChecker().getDiagnostics(getSourceFile(filename).getSourceFile())
|
||||||
: getFullTypeCheckChecker().getDiagnostics();
|
: getFullTypeCheckChecker().getDiagnostics();
|
||||||
getFullTypeCheckChecker().getGlobalDiagnostics();
|
getFullTypeCheckChecker().getGlobalDiagnostics();
|
||||||
getFullTypeCheckChecker().emitFiles();
|
var emitOutput = getFullTypeCheckChecker().emitFiles();
|
||||||
|
|
||||||
if (emitDeclaration && containErrors(semanticDiagnostics)) {
|
if (emitDeclaration && containErrors(semanticDiagnostics)) {
|
||||||
emitResult.emitOutputResult = EmitOutputResult.FailedToGenerateDeclarationsBecauseOfSemanticErrors;
|
emitResult.emitOutputResult = EmitOutputResult.FailedToGenerateDeclarationsBecauseOfSemanticErrors;
|
||||||
}
|
}
|
||||||
|
else if (emitDeclaration && containErrors(emitOutput.errors)) {
|
||||||
|
emitResult.emitOutputResult = EmitOutputResult.FailedToGenerateDeclarationsBecauseOfSemanticErrors;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
emitResult.emitOutputResult = EmitOutputResult.Succeeded;
|
emitResult.emitOutputResult = EmitOutputResult.Succeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset writter back to underfined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in an emitting stage
|
// Reset writter back to underfined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in an emitting stage
|
||||||
return null;
|
this.writter = undefined;
|
||||||
|
return emitResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Syntactic features
|
/// Syntactic features
|
||||||
|
|
Loading…
Reference in a new issue