From 2eca0af91b0e4d28c4cb7fbe6a6a6c3da72d8ae4 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 2 Nov 2016 07:05:54 -0700 Subject: [PATCH 1/4] Leave files from `node_modules` out when calculating `getCommonSourceDirectory` --- src/compiler/program.ts | 13 ++++--- src/compiler/utilities.ts | 20 ++++++++--- src/harness/harness.ts | 36 +++++++------------ src/harness/runnerbase.ts | 2 +- .../reference/commonSourceDirectory.js | 16 +++++++++ .../reference/commonSourceDirectory.symbols | 13 +++++++ .../reference/commonSourceDirectory.types | 16 +++++++++ tests/cases/compiler/commonSourceDirectory.ts | 18 ++++++++++ 8 files changed, 102 insertions(+), 32 deletions(-) create mode 100644 tests/baselines/reference/commonSourceDirectory.js create mode 100644 tests/baselines/reference/commonSourceDirectory.symbols create mode 100644 tests/baselines/reference/commonSourceDirectory.types create mode 100644 tests/cases/compiler/commonSourceDirectory.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 82d274e0487df..35c6818fea839 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -430,13 +430,14 @@ namespace ts { return program; function getCommonSourceDirectory() { - if (typeof commonSourceDirectory === "undefined") { - if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { + if (commonSourceDirectory === undefined) { + const emittedFiles = filterSourceFilesInDirectory(files, isSourceFileFromExternalLibrary); + if (options.rootDir && checkSourceFilesBelongToPath(emittedFiles, options.rootDir)) { // If a rootDir is specified and is valid use it as the commonSourceDirectory commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory); } else { - commonSourceDirectory = computeCommonSourceDirectory(files); + commonSourceDirectory = computeCommonSourceDirectory(emittedFiles); } if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) { // Make sure directory path ends with directory separator so this string can directly @@ -448,6 +449,10 @@ namespace ts { return commonSourceDirectory; } + function isSourceFileFromExternalLibrary(file: SourceFile): boolean { + return !!sourceFilesFoundSearchingNodeModules[file.path]; + } + function getClassifiableNames() { if (!classifiableNames) { // Initialize a checker so that all our files are bound. @@ -722,7 +727,7 @@ namespace ts { getSourceFile: program.getSourceFile, getSourceFileByPath: program.getSourceFileByPath, getSourceFiles: program.getSourceFiles, - isSourceFileFromExternalLibrary: (file: SourceFile) => !!sourceFilesFoundSearchingNodeModules[file.path], + isSourceFileFromExternalLibrary, writeFile: writeFileCallback || ( (fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)), isEmitBlocked, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 299f91be6625c..a2fe7a2d3c6a2 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2556,16 +2556,29 @@ namespace ts { } else { const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile]; - return filter(sourceFiles, isNonDeclarationFile); + return filterSourceFilesInDirectory(sourceFiles, file => host.isSourceFileFromExternalLibrary(file)); } } + /** Don't call this for `--outFile`, just for `--outDir` or plain emit. */ + export function filterSourceFilesInDirectory(sourceFiles: SourceFile[], isSourceFileFromExternalLibrary: (file: SourceFile) => boolean): SourceFile[] { + return filter(sourceFiles, file => shouldEmitInDirectory(file, isSourceFileFromExternalLibrary)); + } + function isNonDeclarationFile(sourceFile: SourceFile) { return !isDeclarationFile(sourceFile); } + /** + * Whether a file should be emitted in a non-`--outFile` case. + * Don't emit if source file is a declaration file, or was located under node_modules + */ + function shouldEmitInDirectory(sourceFile: SourceFile, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean): boolean { + return isNonDeclarationFile(sourceFile) && !isSourceFileFromExternalLibrary(sourceFile); + } + function isBundleEmitNonExternalModule(sourceFile: SourceFile) { - return !isDeclarationFile(sourceFile) && !isExternalModule(sourceFile); + return isNonDeclarationFile(sourceFile) && !isExternalModule(sourceFile); } /** @@ -2653,8 +2666,7 @@ namespace ts { else { const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile]; for (const sourceFile of sourceFiles) { - // Don't emit if source file is a declaration file, or was located under node_modules - if (!isDeclarationFile(sourceFile) && !host.isSourceFileFromExternalLibrary(sourceFile)) { + if (shouldEmitInDirectory(sourceFile, file => host.isSourceFileFromExternalLibrary(file))) { onSingleFileEmit(host, sourceFile); } } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index a6e1ffad7f71e..57ee46299b566 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -470,19 +470,6 @@ namespace Utils { } } -namespace Harness.Path { - export function getFileName(fullPath: string) { - return fullPath.replace(/^.*[\\\/]/, ""); - } - - export function filePath(fullPath: string) { - fullPath = ts.normalizeSlashes(fullPath); - const components = fullPath.split("/"); - const path: string[] = components.slice(0, components.length - 1); - return path.join("/") + "/"; - } -} - namespace Harness { export interface IO { newLine(): string; @@ -1090,7 +1077,9 @@ namespace Harness { { name: "suppressOutputPathCheck", type: "boolean" }, { name: "noImplicitReferences", type: "boolean" }, { name: "currentDirectory", type: "string" }, - { name: "symlink", type: "string" } + { name: "symlink", type: "string" }, + // Emitted js baseline will print full paths for every output file + { name: "fullEmitPaths", type: "boolean" } ]; let optionsIndex: ts.Map; @@ -1588,7 +1577,7 @@ namespace Harness { let sourceMapCode = ""; for (let i = 0; i < result.sourceMaps.length; i++) { - sourceMapCode += "//// [" + Harness.Path.getFileName(result.sourceMaps[i].fileName) + "]\r\n"; + sourceMapCode += "//// [" + ts.getBaseFileName(result.sourceMaps[i].fileName) + "]\r\n"; sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]); sourceMapCode += result.sourceMaps[i].code; } @@ -1611,21 +1600,22 @@ namespace Harness { tsCode += "//// [" + header + "] ////\r\n\r\n"; } for (let i = 0; i < tsSources.length; i++) { - tsCode += "//// [" + Harness.Path.getFileName(tsSources[i].unitName) + "]\r\n"; + tsCode += "//// [" + ts.getBaseFileName(tsSources[i].unitName) + "]\r\n"; tsCode += tsSources[i].content + (i < (tsSources.length - 1) ? "\r\n" : ""); } let jsCode = ""; - for (let i = 0; i < result.files.length; i++) { - jsCode += "//// [" + Harness.Path.getFileName(result.files[i].fileName) + "]\r\n"; - jsCode += getByteOrderMarkText(result.files[i]); - jsCode += result.files[i].code; + for (const file of result.files) { + const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName); + jsCode += "//// [" + fileName + "]\r\n"; + jsCode += getByteOrderMarkText(file); + jsCode += file.code; } if (result.declFilesCode.length > 0) { jsCode += "\r\n\r\n"; for (let i = 0; i < result.declFilesCode.length; i++) { - jsCode += "//// [" + Harness.Path.getFileName(result.declFilesCode[i].fileName) + "]\r\n"; + jsCode += "//// [" + ts.getBaseFileName(result.declFilesCode[i].fileName) + "]\r\n"; jsCode += getByteOrderMarkText(result.declFilesCode[i]); jsCode += result.declFilesCode[i].code; } @@ -1848,7 +1838,7 @@ namespace Harness { } // normalize the fileName for the single file case - currentFileName = testUnitData.length > 0 || currentFileName ? currentFileName : Path.getFileName(fileName); + currentFileName = testUnitData.length > 0 || currentFileName ? currentFileName : ts.getBaseFileName(fileName); // EOF, push whatever remains const newTestFile2 = { @@ -2012,7 +2002,7 @@ namespace Harness { export function isDefaultLibraryFile(filePath: string): boolean { // We need to make sure that the filePath is prefixed with "lib." not just containing "lib." and end with ".d.ts" - const fileName = Path.getFileName(filePath); + const fileName = ts.getBaseFileName(filePath); return ts.startsWith(fileName, "lib.") && ts.endsWith(fileName, ".d.ts"); } diff --git a/src/harness/runnerbase.ts b/src/harness/runnerbase.ts index 346382b7a5721..d50604803edf1 100644 --- a/src/harness/runnerbase.ts +++ b/src/harness/runnerbase.ts @@ -32,7 +32,7 @@ abstract class RunnerBase { /** Replaces instances of full paths with fileNames only */ static removeFullPaths(path: string) { // If its a full path (starts with "C:" or "/") replace with just the filename - let fixedPath = /^(\w:|\/)/.test(path) ? Harness.Path.getFileName(path) : path; + let fixedPath = /^(\w:|\/)/.test(path) ? ts.getBaseFileName(path) : path; // when running in the browser the 'full path' is the host name, shows up in error baselines const localHost = /http:\/localhost:\d+/g; diff --git a/tests/baselines/reference/commonSourceDirectory.js b/tests/baselines/reference/commonSourceDirectory.js new file mode 100644 index 0000000000000..3babba98337ea --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/commonSourceDirectory.ts] //// + +//// [index.ts] +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +export const x = 0; + +//// [index.ts] +import { x } from "foo"; +x + 1; + + +//// [/app/bin/index.js] +"use strict"; +var foo_1 = require("foo"); +foo_1.x + 1; diff --git a/tests/baselines/reference/commonSourceDirectory.symbols b/tests/baselines/reference/commonSourceDirectory.symbols new file mode 100644 index 0000000000000..88ded4c8c878a --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.symbols @@ -0,0 +1,13 @@ +=== /app/index.ts === +import { x } from "foo"; +>x : Symbol(x, Decl(index.ts, 0, 8)) + +x + 1; +>x : Symbol(x, Decl(index.ts, 0, 8)) + +=== /node_modules/foo/index.ts === +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +export const x = 0; +>x : Symbol(x, Decl(index.ts, 2, 12)) + diff --git a/tests/baselines/reference/commonSourceDirectory.types b/tests/baselines/reference/commonSourceDirectory.types new file mode 100644 index 0000000000000..a0c66b86ae047 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.types @@ -0,0 +1,16 @@ +=== /app/index.ts === +import { x } from "foo"; +>x : 0 + +x + 1; +>x + 1 : number +>x : 0 +>1 : 1 + +=== /node_modules/foo/index.ts === +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +export const x = 0; +>x : 0 +>0 : 0 + diff --git a/tests/cases/compiler/commonSourceDirectory.ts b/tests/cases/compiler/commonSourceDirectory.ts new file mode 100644 index 0000000000000..6583da67c6a7f --- /dev/null +++ b/tests/cases/compiler/commonSourceDirectory.ts @@ -0,0 +1,18 @@ +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. +// @noImplicitReferences: true +// @moduleResolution: node +// @fullEmitPaths: true + +// @filename: /node_modules/foo/index.ts +export const x = 0; + +// @filename: /app/index.ts +import { x } from "foo"; +x + 1; + +// @filename: /app/tsconfig.json +{ + "compilerOptions": { + "outDir": "bin" + } +} From 0b71df50997de7e09ff91836b7190ba237ab235d Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 3 Nov 2016 12:28:19 -0700 Subject: [PATCH 2/4] Add a `.d.ts` file to the test to ensure it is excluded from the calculation too --- .../reference/commonSourceDirectory.js | 13 +++++++++++-- .../reference/commonSourceDirectory.symbols | 17 ++++++++++++++--- .../reference/commonSourceDirectory.types | 17 ++++++++++++++--- tests/cases/compiler/commonSourceDirectory.ts | 12 ++++++++++-- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/commonSourceDirectory.js b/tests/baselines/reference/commonSourceDirectory.js index 3babba98337ea..5299095ae742a 100644 --- a/tests/baselines/reference/commonSourceDirectory.js +++ b/tests/baselines/reference/commonSourceDirectory.js @@ -5,12 +5,21 @@ export const x = 0; +//// [bar.d.ts] +declare module "bar" { + export const y = 0; +} + //// [index.ts] +/// import { x } from "foo"; -x + 1; +import { y } from "bar"; +x + y; //// [/app/bin/index.js] "use strict"; +/// var foo_1 = require("foo"); -foo_1.x + 1; +var bar_1 = require("bar"); +foo_1.x + bar_1.y; diff --git a/tests/baselines/reference/commonSourceDirectory.symbols b/tests/baselines/reference/commonSourceDirectory.symbols index 88ded4c8c878a..5409286ede59e 100644 --- a/tests/baselines/reference/commonSourceDirectory.symbols +++ b/tests/baselines/reference/commonSourceDirectory.symbols @@ -1,9 +1,14 @@ === /app/index.ts === +/// import { x } from "foo"; ->x : Symbol(x, Decl(index.ts, 0, 8)) +>x : Symbol(x, Decl(index.ts, 1, 8)) -x + 1; ->x : Symbol(x, Decl(index.ts, 0, 8)) +import { y } from "bar"; +>y : Symbol(y, Decl(index.ts, 2, 8)) + +x + y; +>x : Symbol(x, Decl(index.ts, 1, 8)) +>y : Symbol(y, Decl(index.ts, 2, 8)) === /node_modules/foo/index.ts === // Test that importing a file from `node_modules` does not affect calculation of the common source directory. @@ -11,3 +16,9 @@ x + 1; export const x = 0; >x : Symbol(x, Decl(index.ts, 2, 12)) +=== /types/bar.d.ts === +declare module "bar" { + export const y = 0; +>y : Symbol(y, Decl(bar.d.ts, 1, 16)) +} + diff --git a/tests/baselines/reference/commonSourceDirectory.types b/tests/baselines/reference/commonSourceDirectory.types index a0c66b86ae047..ce0169582d784 100644 --- a/tests/baselines/reference/commonSourceDirectory.types +++ b/tests/baselines/reference/commonSourceDirectory.types @@ -1,11 +1,15 @@ === /app/index.ts === +/// import { x } from "foo"; >x : 0 -x + 1; ->x + 1 : number +import { y } from "bar"; +>y : 0 + +x + y; +>x + y : number >x : 0 ->1 : 1 +>y : 0 === /node_modules/foo/index.ts === // Test that importing a file from `node_modules` does not affect calculation of the common source directory. @@ -14,3 +18,10 @@ export const x = 0; >x : 0 >0 : 0 +=== /types/bar.d.ts === +declare module "bar" { + export const y = 0; +>y : 0 +>0 : 0 +} + diff --git a/tests/cases/compiler/commonSourceDirectory.ts b/tests/cases/compiler/commonSourceDirectory.ts index 6583da67c6a7f..930f922e10de8 100644 --- a/tests/cases/compiler/commonSourceDirectory.ts +++ b/tests/cases/compiler/commonSourceDirectory.ts @@ -6,13 +6,21 @@ // @filename: /node_modules/foo/index.ts export const x = 0; +// @filename: /types/bar.d.ts +declare module "bar" { + export const y = 0; +} + // @filename: /app/index.ts +/// import { x } from "foo"; -x + 1; +import { y } from "bar"; +x + y; // @filename: /app/tsconfig.json { "compilerOptions": { - "outDir": "bin" + "outDir": "bin", + "typeRoots": ["../types"] } } From 07630e95e00fe61d51fd92de1f019be4da9c813d Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 7 Nov 2016 07:14:47 -0800 Subject: [PATCH 3/4] Add source maps and declarations to test --- src/harness/compilerRunner.ts | 2 +- src/harness/harness.ts | 24 ++++---- .../reference/commonSourceDirectory.js | 4 ++ .../reference/commonSourceDirectory.js.map | 2 + .../commonSourceDirectory.sourcemap.txt | 58 +++++++++++++++++++ tests/cases/compiler/commonSourceDirectory.ts | 6 +- 6 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 tests/baselines/reference/commonSourceDirectory.js.map create mode 100644 tests/baselines/reference/commonSourceDirectory.sourcemap.txt diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 70c6fdac32984..327932f366703 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -170,7 +170,7 @@ class CompilerBaselineRunner extends RunnerBase { }); it("Correct Sourcemap output for " + fileName, () => { - Harness.Compiler.doSourcemapBaseline(justName, options, result); + Harness.Compiler.doSourcemapBaseline(justName, options, result, harnessSettings); }); it("Correct type/symbol baselines for " + fileName, () => { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 57ee46299b566..1173576f0c7a3 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1554,7 +1554,7 @@ namespace Harness { return file.writeByteOrderMark ? "\u00EF\u00BB\u00BF" : ""; } - export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult) { + export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult, harnessSettings: Harness.TestCaseParser.CompilerSettings) { if (options.inlineSourceMap) { if (result.sourceMaps.length > 0) { throw new Error("No sourcemap files should be generated if inlineSourceMaps was set."); @@ -1576,10 +1576,8 @@ namespace Harness { } let sourceMapCode = ""; - for (let i = 0; i < result.sourceMaps.length; i++) { - sourceMapCode += "//// [" + ts.getBaseFileName(result.sourceMaps[i].fileName) + "]\r\n"; - sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]); - sourceMapCode += result.sourceMaps[i].code; + for (const sourceMap of result.sourceMaps) { + sourceMapCode += fileOutput(sourceMap, harnessSettings); } return sourceMapCode; @@ -1606,18 +1604,13 @@ namespace Harness { let jsCode = ""; for (const file of result.files) { - const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName); - jsCode += "//// [" + fileName + "]\r\n"; - jsCode += getByteOrderMarkText(file); - jsCode += file.code; + jsCode += fileOutput(file, harnessSettings); } if (result.declFilesCode.length > 0) { jsCode += "\r\n\r\n"; - for (let i = 0; i < result.declFilesCode.length; i++) { - jsCode += "//// [" + ts.getBaseFileName(result.declFilesCode[i].fileName) + "]\r\n"; - jsCode += getByteOrderMarkText(result.declFilesCode[i]); - jsCode += result.declFilesCode[i].code; + for (const declFile of result.declFilesCode) { + jsCode += fileOutput(declFile, harnessSettings); } } @@ -1642,6 +1635,11 @@ namespace Harness { }); } + function fileOutput(file: GeneratedFile, harnessSettings: Harness.TestCaseParser.CompilerSettings): string { + const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName); + return "//// [" + fileName + "]\r\n" + getByteOrderMarkText(file) + file.code; + } + export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): string { // Collect, test, and sort the fileNames outputFiles.sort((a, b) => ts.compareStrings(cleanName(a.fileName), cleanName(b.fileName))); diff --git a/tests/baselines/reference/commonSourceDirectory.js b/tests/baselines/reference/commonSourceDirectory.js index 5299095ae742a..1a863dbecbdce 100644 --- a/tests/baselines/reference/commonSourceDirectory.js +++ b/tests/baselines/reference/commonSourceDirectory.js @@ -23,3 +23,7 @@ x + y; var foo_1 = require("foo"); var bar_1 = require("bar"); foo_1.x + bar_1.y; +//# sourceMappingURL=/app/myMapRoot/index.js.map + +//// [/app/bin/index.d.ts] +/// diff --git a/tests/baselines/reference/commonSourceDirectory.js.map b/tests/baselines/reference/commonSourceDirectory.js.map new file mode 100644 index 0000000000000..8e3f925eee953 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.js.map @@ -0,0 +1,2 @@ +//// [/app/bin/index.js.map] +{"version":3,"file":"index.js","sourceRoot":"/app/mySourceRoot/","sources":["index.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,2BAAwB;AACxB,2BAAwB;AACxB,OAAC,GAAG,OAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/commonSourceDirectory.sourcemap.txt b/tests/baselines/reference/commonSourceDirectory.sourcemap.txt new file mode 100644 index 0000000000000..ac198eaf02c9d --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.sourcemap.txt @@ -0,0 +1,58 @@ +=================================================================== +JsFile: index.js +mapUrl: /app/myMapRoot/index.js.map +sourceRoot: /app/mySourceRoot/ +sources: index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:/app/bin/index.js +sourceFile:index.ts +------------------------------------------------------------------- +>>>"use strict"; +>>>/// +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 >/// +1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(2, 42) Source(1, 42) + SourceIndex(0) +--- +>>>var foo_1 = require("foo"); +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^-> +1 > + > +2 >import { x } from "foo"; +1 >Emitted(3, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(3, 28) Source(2, 25) + SourceIndex(0) +--- +>>>var bar_1 = require("bar"); +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> + > +2 >import { y } from "bar"; +1->Emitted(4, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(4, 28) Source(3, 25) + SourceIndex(0) +--- +>>>foo_1.x + bar_1.y; +1 > +2 >^^^^^^^ +3 > ^^^ +4 > ^^^^^^^ +5 > ^ +6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >x +3 > + +4 > y +5 > ; +1 >Emitted(5, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(5, 8) Source(4, 2) + SourceIndex(0) +3 >Emitted(5, 11) Source(4, 5) + SourceIndex(0) +4 >Emitted(5, 18) Source(4, 6) + SourceIndex(0) +5 >Emitted(5, 19) Source(4, 7) + SourceIndex(0) +--- +>>>//# sourceMappingURL=/app/myMapRoot/index.js.map \ No newline at end of file diff --git a/tests/cases/compiler/commonSourceDirectory.ts b/tests/cases/compiler/commonSourceDirectory.ts index 930f922e10de8..9baa27431a393 100644 --- a/tests/cases/compiler/commonSourceDirectory.ts +++ b/tests/cases/compiler/commonSourceDirectory.ts @@ -21,6 +21,10 @@ x + y; { "compilerOptions": { "outDir": "bin", - "typeRoots": ["../types"] + "typeRoots": ["../types"], + "sourceMap": true, + "mapRoot": "myMapRoot", + "sourceRoot": "mySourceRoot", + "declaration": true } } From 0422a756d9d2d785bad1ef6d3fa2d6155b910f5e Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 10 Nov 2016 10:15:42 -0800 Subject: [PATCH 4/4] Add test with a referenced dts file --- .../reference/commonSourceDirectory_dts.js | 21 ++++++++++ .../commonSourceDirectory_dts.js.map | 2 + .../commonSourceDirectory_dts.sourcemap.txt | 42 +++++++++++++++++++ .../commonSourceDirectory_dts.symbols | 12 ++++++ .../reference/commonSourceDirectory_dts.types | 12 ++++++ .../compiler/commonSourceDirectory_dts.ts | 22 ++++++++++ 6 files changed, 111 insertions(+) create mode 100644 tests/baselines/reference/commonSourceDirectory_dts.js create mode 100644 tests/baselines/reference/commonSourceDirectory_dts.js.map create mode 100644 tests/baselines/reference/commonSourceDirectory_dts.sourcemap.txt create mode 100644 tests/baselines/reference/commonSourceDirectory_dts.symbols create mode 100644 tests/baselines/reference/commonSourceDirectory_dts.types create mode 100644 tests/cases/compiler/commonSourceDirectory_dts.ts diff --git a/tests/baselines/reference/commonSourceDirectory_dts.js b/tests/baselines/reference/commonSourceDirectory_dts.js new file mode 100644 index 0000000000000..8aa0bd04e11d7 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/commonSourceDirectory_dts.ts] //// + +//// [bar.d.ts] +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +declare const y: number; + +//// [index.ts] +/// +export const x = y; + + +//// [/app/bin/index.js] +"use strict"; +/// +exports.x = y; +//# sourceMappingURL=/app/myMapRoot/index.js.map + +//// [/app/bin/index.d.ts] +/// +export declare const x: number; diff --git a/tests/baselines/reference/commonSourceDirectory_dts.js.map b/tests/baselines/reference/commonSourceDirectory_dts.js.map new file mode 100644 index 0000000000000..b33518dd04cae --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.js.map @@ -0,0 +1,2 @@ +//// [/app/bin/index.js.map] +{"version":3,"file":"index.js","sourceRoot":"/app/mySourceRoot/","sources":["index.ts"],"names":[],"mappings":";AAAA,wCAAwC;AAC3B,QAAA,CAAC,GAAG,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/commonSourceDirectory_dts.sourcemap.txt b/tests/baselines/reference/commonSourceDirectory_dts.sourcemap.txt new file mode 100644 index 0000000000000..90603ae3652c8 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.sourcemap.txt @@ -0,0 +1,42 @@ +=================================================================== +JsFile: index.js +mapUrl: /app/myMapRoot/index.js.map +sourceRoot: /app/mySourceRoot/ +sources: index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:/app/bin/index.js +sourceFile:index.ts +------------------------------------------------------------------- +>>>"use strict"; +>>>/// +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 >/// +1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(2, 41) Source(1, 41) + SourceIndex(0) +--- +>>>exports.x = y; +1 > +2 >^^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >export const +2 > +3 > x +4 > = +5 > y +6 > ; +1 >Emitted(3, 1) Source(2, 14) + SourceIndex(0) +2 >Emitted(3, 9) Source(2, 14) + SourceIndex(0) +3 >Emitted(3, 10) Source(2, 15) + SourceIndex(0) +4 >Emitted(3, 13) Source(2, 18) + SourceIndex(0) +5 >Emitted(3, 14) Source(2, 19) + SourceIndex(0) +6 >Emitted(3, 15) Source(2, 20) + SourceIndex(0) +--- +>>>//# sourceMappingURL=/app/myMapRoot/index.js.map \ No newline at end of file diff --git a/tests/baselines/reference/commonSourceDirectory_dts.symbols b/tests/baselines/reference/commonSourceDirectory_dts.symbols new file mode 100644 index 0000000000000..740a8aef92102 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.symbols @@ -0,0 +1,12 @@ +=== /app/src/index.ts === +/// +export const x = y; +>x : Symbol(x, Decl(index.ts, 1, 12)) +>y : Symbol(y, Decl(bar.d.ts, 2, 13)) + +=== /app/lib/bar.d.ts === +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +declare const y: number; +>y : Symbol(y, Decl(bar.d.ts, 2, 13)) + diff --git a/tests/baselines/reference/commonSourceDirectory_dts.types b/tests/baselines/reference/commonSourceDirectory_dts.types new file mode 100644 index 0000000000000..b41b91c978f27 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.types @@ -0,0 +1,12 @@ +=== /app/src/index.ts === +/// +export const x = y; +>x : number +>y : number + +=== /app/lib/bar.d.ts === +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +declare const y: number; +>y : number + diff --git a/tests/cases/compiler/commonSourceDirectory_dts.ts b/tests/cases/compiler/commonSourceDirectory_dts.ts new file mode 100644 index 0000000000000..3a3dfea1772ef --- /dev/null +++ b/tests/cases/compiler/commonSourceDirectory_dts.ts @@ -0,0 +1,22 @@ +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. +// @noImplicitReferences: true +// @moduleResolution: node +// @fullEmitPaths: true + +// @filename: /app/lib/bar.d.ts +declare const y: number; + +// @filename: /app/src/index.ts +/// +export const x = y; + +// @filename: /app/tsconfig.json +{ + "compilerOptions": { + "outDir": "bin", + "sourceMap": true, + "mapRoot": "myMapRoot", + "sourceRoot": "mySourceRoot", + "declaration": true + } +}