sourcemap correctness

This commit is contained in:
Wesley Wigham 2015-10-01 19:23:12 -07:00
parent b6a57ea8af
commit 122753b50a
2 changed files with 39 additions and 29 deletions

View file

@ -473,12 +473,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitSourceFile(root);
}
else {
forEach(host.getSourceFiles(), emitEmitHelpers);
if (modulekind) {
forEach(host.getSourceFiles(), emitEmitHelpers);
}
forEach(host.getSourceFiles(), sourceFile => {
if (!isExternalModuleOrDeclarationFile(sourceFile)) {
emitSourceFile(sourceFile);
}
else if (isExternalModule(sourceFile)) {
else if (modulekind && isExternalModule(sourceFile)) {
emitConcatenatedModule(sourceFile);
}
});
@ -499,7 +501,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
exportFunctionForFile = undefined;
let canonicalName = resolveToSemiabsolutePath(sourceFile.fileName);
sourceFile.moduleName = sourceFile.moduleName || canonicalName;
bundleEmitDelegates[modulekind](sourceFile, 0, /*resolvePath*/true);
emit(sourceFile);
}
function resolveToSemiabsolutePath(path: string): string {
@ -7051,8 +7053,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false);
if (isExternalModule(node) || compilerOptions.isolatedModules) {
let emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[ModuleKind.CommonJS];
emitModule(node, startIndex);
if (root) {
let emitModule = moduleEmitDelegates[modulekind] || moduleEmitDelegates[ModuleKind.CommonJS];
emitModule(node, startIndex);
}
else {
bundleEmitDelegates[modulekind](node, startIndex, /*resolvePath*/true);
}
}
else {
externalImports = undefined;

View file

@ -377,6 +377,29 @@ namespace ts {
}
}
// there has to be common source directory if user specified --outdir || --sourceRoot
// if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted
if (options.outDir || // there is --outDir specified
options.sourceRoot || // there is --sourceRoot specified
options.mapRoot) { // there is --mapRoot specified
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
// If a rootDir is specified and is valid use it as the commonSourceDirectory
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory());
}
else {
// Compute the commonSourceDirectory from the input files
commonSourceDirectory = computeCommonSourceDirectory(files);
}
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {
// Make sure directory path ends with directory separator so this string can directly
// used to replace with "" to get the relative path of the source file and the relative path doesn't
// start with / making it rooted path
commonSourceDirectory += directorySeparator;
}
}
verifyCompilerOptions();
// unconditionally set oldProgram to undefined to prevent it from being captured in closure
@ -934,6 +957,10 @@ namespace ts {
}
});
if (!commonPathComponents) { // Can happen when all input files are .d.ts files
return currentDirectory;
}
return getNormalizedPathFromPathComponents(commonPathComponents);
}
@ -1036,30 +1063,6 @@ namespace ts {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_es6_when_targeting_ES5_or_lower));
}
// there has to be common source directory if user specified --outdir || --sourceRoot
// if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted
if (options.outDir || // there is --outDir specified
options.sourceRoot || // there is --sourceRoot specified
(options.mapRoot && // there is --mapRoot specified and there would be multiple js files generated
(!outFile || firstExternalModuleSourceFile !== undefined))) {
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
// If a rootDir is specified and is valid use it as the commonSourceDirectory
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory());
}
else {
// Compute the commonSourceDirectory from the input files
commonSourceDirectory = computeCommonSourceDirectory(files);
}
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {
// Make sure directory path ends with directory separator so this string can directly
// used to replace with "" to get the relative path of the source file and the relative path doesn't
// start with / making it rooted path
commonSourceDirectory += directorySeparator;
}
}
if (options.noEmit) {
if (options.out) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out"));