From 9acff37947392bb3c3c53d16c9fb25039cbc0f4b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 24 Jan 2019 11:45:22 -0800 Subject: [PATCH 1/5] Add test to test the readFile called on prepend input file for emitting and verifying emit --- src/testRunner/unittests/tsbuild.ts | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/testRunner/unittests/tsbuild.ts b/src/testRunner/unittests/tsbuild.ts index ba94072b230..b8a58eb1bc0 100644 --- a/src/testRunner/unittests/tsbuild.ts +++ b/src/testRunner/unittests/tsbuild.ts @@ -469,11 +469,20 @@ export const b = new A();`); describe("unittests:: tsbuild - baseline sectioned sourcemaps", () => { let fs: vfs.FileSystem | undefined; + const actualReadFileMap = createMap(); before(() => { fs = outFileFs.shadow(); const host = new fakes.SolutionBuilderHost(fs); const builder = createSolutionBuilder(host, ["/src/third"], { dry: false, force: false, verbose: false }); host.clearDiagnostics(); + const originalReadFile = host.readFile; + host.readFile = path => { + // Dont record libs + if (path.startsWith("/src/")) { + actualReadFileMap.set(path, (actualReadFileMap.get(path) || 0) + 1); + } + return originalReadFile.call(host, path); + }; builder.buildAllProjects(); host.assertDiagnosticMessages(/*none*/); }); @@ -485,6 +494,39 @@ export const b = new A();`); // tslint:disable-next-line:no-null-keyword Harness.Baseline.runBaseline("outfile-concat.js", patch ? vfs.formatPatch(patch) : null); }); + it("verify readFile calls", () => { + const expectedMap = createMap(); + // Configs + expectedMap.set("/src/third/tsconfig.json", 1); + expectedMap.set("/src/second/tsconfig.json", 1); + expectedMap.set("/src/first/tsconfig.json", 1); + + // Source files + expectedMap.set("/src/third/third_part1.ts", 1); + expectedMap.set("/src/second/second_part1.ts", 1); + expectedMap.set("/src/second/second_part2.ts", 1); + expectedMap.set("/src/first/first_PART1.ts", 1); + expectedMap.set("/src/first/first_part2.ts", 1); + expectedMap.set("/src/first/first_part3.ts", 1); + + // outputs + expectedMap.set("/src/first/bin/first-output.js", 2); + expectedMap.set("/src/first/bin/first-output.js.map", 2); + // 1 for reading source File, 2 for forEachEmittedFiles (verifying compiler Options and actual emit)when prepend array is created + expectedMap.set("/src/first/bin/first-output.d.ts", 3); + expectedMap.set("/src/first/bin/first-output.d.ts.map", 2); + expectedMap.set("/src/2/second-output.js", 2); + expectedMap.set("/src/2/second-output.js.map", 2); + // 1 for reading source File, 2 for forEachEmittedFiles (verifying compiler Options and actual emit)when prepend array is created + expectedMap.set("/src/2/second-output.d.ts", 3); + expectedMap.set("/src/2/second-output.d.ts.map", 2); + + assert.equal(actualReadFileMap.size, expectedMap.size, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`); + actualReadFileMap.forEach((value, key) => { + const expected = expectedMap.get(key); + assert.equal(value, expected, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`); + }); + }); }); describe("unittests:: tsbuild - downstream prepend projects always get rebuilt", () => { From 50d98aee0e83bbf806d1f08c0b3eae785690da69 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 24 Jan 2019 12:40:52 -0800 Subject: [PATCH 2/5] Create getters for js sourcemap, dts and dts map text getters in prepend nodes --- src/compiler/emitter.ts | 19 +++-- src/compiler/factory.ts | 81 +++++++++++++++---- src/compiler/program.ts | 10 +-- src/compiler/transformers/declarations.ts | 2 +- src/compiler/transformers/ts.ts | 2 +- src/compiler/types.ts | 3 + src/testRunner/unittests/tsbuild.ts | 20 ++--- .../reference/api/tsserverlibrary.d.ts | 9 ++- tests/baselines/reference/api/typescript.d.ts | 9 ++- 9 files changed, 107 insertions(+), 48 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 395f6448890..8daedabf29a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -38,17 +38,22 @@ namespace ts { } } + /*@internal*/ + export function getOutputPathsForBundle(options: CompilerOptions, forceDtsPaths: boolean): EmitFileNames { + const outPath = options.outFile || options.out!; + const jsFilePath = options.emitDeclarationOnly ? undefined : outPath; + const sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options); + const declarationFilePath = (forceDtsPaths || getEmitDeclarations(options)) ? removeFileExtension(outPath) + Extension.Dts : undefined; + const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; + const bundleInfoPath = options.references && jsFilePath ? (removeFileExtension(jsFilePath) + infoExtension) : undefined; + return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath }; + } + /*@internal*/ export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths: boolean): EmitFileNames { const options = host.getCompilerOptions(); if (sourceFile.kind === SyntaxKind.Bundle) { - const outPath = options.outFile || options.out!; - const jsFilePath = options.emitDeclarationOnly ? undefined : outPath; - const sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options); - const declarationFilePath = (forceDtsPaths || getEmitDeclarations(options)) ? removeFileExtension(outPath) + Extension.Dts : undefined; - const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; - const bundleInfoPath = options.references && jsFilePath ? (removeFileExtension(jsFilePath) + infoExtension) : undefined; - return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath }; + return getOutputPathsForBundle(options, forceDtsPaths); } else { const ownOutputFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index ec19d2c906c..3707b725ed3 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2630,41 +2630,88 @@ namespace ts { } export function createUnparsedSourceFile(text: string): UnparsedSource; + export function createUnparsedSourceFile(inputFile: InputFiles, type: "js" | "dts"): UnparsedSource; export function createUnparsedSourceFile(text: string, mapPath: string | undefined, map: string | undefined): UnparsedSource; - export function createUnparsedSourceFile(text: string, mapPath?: string, map?: string): UnparsedSource { + export function createUnparsedSourceFile(textOrInputFiles: string | InputFiles, mapPathOrType?: string | "js" | "dts", map?: string): UnparsedSource { const node = createNode(SyntaxKind.UnparsedSource); - node.text = text; - node.sourceMapPath = mapPath; - node.sourceMapText = map; + if (!isString(textOrInputFiles)) { + Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts"); + node.fileName = mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath; + node.sourceMapPath = mapPathOrType === "js" ? textOrInputFiles.javascriptMapPath : textOrInputFiles.declarationMapPath; + Object.defineProperties(node, { + text: { get() { return mapPathOrType === "js" ? textOrInputFiles.javascriptText : textOrInputFiles.declarationText; } }, + sourceMapText: { get() { return mapPathOrType === "js" ? textOrInputFiles.javascriptMapText : textOrInputFiles.declarationMapText; } }, + }); + } + else { + node.text = textOrInputFiles; + node.sourceMapPath = mapPathOrType; + node.sourceMapText = map; + } return node; } export function createInputFiles( - javascript: string, - declaration: string + javascriptText: string, + declarationText: string ): InputFiles; export function createInputFiles( - javascript: string, - declaration: string, + readFileText: (path: string) => string | undefined, + javascriptPath: string, + javascriptMapPath: string | undefined, + declarationPath: string, + declarationMapPath: string | undefined, + ): InputFiles; + export function createInputFiles( + javascriptText: string, + declarationText: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined ): InputFiles; export function createInputFiles( - javascript: string, - declaration: string, + javascriptTextOrReadFileText: string | ((path: string) => string | undefined), + declarationTextOrJavascriptPath: string, javascriptMapPath?: string, - javascriptMapText?: string, + javascriptMapTextOrDeclarationPath?: string, declarationMapPath?: string, declarationMapText?: string ): InputFiles { const node = createNode(SyntaxKind.InputFiles); - node.javascriptText = javascript; - node.javascriptMapPath = javascriptMapPath; - node.javascriptMapText = javascriptMapText; - node.declarationText = declaration; - node.declarationMapPath = declarationMapPath; - node.declarationMapText = declarationMapText; + if (!isString(javascriptTextOrReadFileText)) { + const cache = createMap(); + const textGetter = (path: string | undefined) => { + if (path === undefined) return undefined; + let value = cache.get(path); + if (value === undefined) { + value = javascriptTextOrReadFileText(path); + cache.set(path, value !== undefined ? value : false); + } + return value !== false ? value as string : undefined; + }; + const definedTextGetter = (path: string) => { + const result = textGetter(path); + return result !== undefined ? result : `/* Input file ${path} was missing */\r\n`; + }; + node.javascriptPath = declarationTextOrJavascriptPath; + node.javascriptMapPath = javascriptMapPath; + node.declarationPath = Debug.assertDefined(javascriptMapTextOrDeclarationPath); + node.declarationMapPath = declarationMapPath; + Object.defineProperties(node, { + javascriptText: { get() { return definedTextGetter(declarationTextOrJavascriptPath); } }, + javascriptMapText: { get() { return textGetter(javascriptMapPath); } }, + declarationText: { get() { return definedTextGetter(Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } }, + declarationMapText: { get() { return textGetter(declarationMapPath); } } + }); + } + else { + node.javascriptText = javascriptTextOrReadFileText; + node.javascriptMapPath = javascriptMapPath; + node.javascriptMapText = javascriptMapTextOrDeclarationPath; + node.declarationText = declarationTextOrJavascriptPath; + node.declarationMapPath = declarationMapPath; + node.declarationMapText = declarationMapText; + } return node; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 14042a89e94..dbc2e61fa42 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1456,14 +1456,8 @@ namespace ts { // Upstream project didn't have outFile set -- skip (error will have been issued earlier) if (!out) continue; - const dtsFilename = changeExtension(out, ".d.ts"); - const js = host.readFile(out) || `/* Input file ${out} was missing */\r\n`; - const jsMapPath = out + ".map"; // TODO: try to read sourceMappingUrl comment from the file - const jsMap = host.readFile(jsMapPath); - const dts = host.readFile(dtsFilename) || `/* Input file ${dtsFilename} was missing */\r\n`; - const dtsMapPath = dtsFilename + ".map"; - const dtsMap = host.readFile(dtsMapPath); - const node = createInputFiles(js, dts, jsMap && jsMapPath, jsMap, dtsMap && dtsMapPath, dtsMap); + const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true); + const node = createInputFiles(path => host.readFile(path), jsFilePath!, sourceMapFilePath, declarationFilePath!, declarationMapPath); nodes.push(node); } } diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index d03c3b8d30b..42bb5d77931 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -207,7 +207,7 @@ namespace ts { } ), mapDefined(node.prepends, prepend => { if (prepend.kind === SyntaxKind.InputFiles) { - return createUnparsedSourceFile(prepend.declarationText, prepend.declarationMapPath, prepend.declarationMapText); + return createUnparsedSourceFile(prepend, "dts"); } })); bundle.syntheticFileReferences = []; diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index a22c6df8d06..7aebed59588 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -101,7 +101,7 @@ namespace ts { function transformBundle(node: Bundle) { return createBundle(node.sourceFiles.map(transformSourceFile), mapDefined(node.prepends, prepend => { if (prepend.kind === SyntaxKind.InputFiles) { - return createUnparsedSourceFile(prepend.javascriptText, prepend.javascriptMapPath, prepend.javascriptMapText); + return createUnparsedSourceFile(prepend, "js"); } return prepend; })); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d213e862299..c460b948347 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2761,9 +2761,11 @@ namespace ts { export interface InputFiles extends Node { kind: SyntaxKind.InputFiles; + javascriptPath?: string; javascriptText: string; javascriptMapPath?: string; javascriptMapText?: string; + declarationPath?: string; declarationText: string; declarationMapPath?: string; declarationMapText?: string; @@ -2771,6 +2773,7 @@ namespace ts { export interface UnparsedSource extends Node { kind: SyntaxKind.UnparsedSource; + fileName?: string; text: string; sourceMapPath?: string; sourceMapText?: string; diff --git a/src/testRunner/unittests/tsbuild.ts b/src/testRunner/unittests/tsbuild.ts index b8a58eb1bc0..be544f4eb1d 100644 --- a/src/testRunner/unittests/tsbuild.ts +++ b/src/testRunner/unittests/tsbuild.ts @@ -510,16 +510,16 @@ export const b = new A();`); expectedMap.set("/src/first/first_part3.ts", 1); // outputs - expectedMap.set("/src/first/bin/first-output.js", 2); - expectedMap.set("/src/first/bin/first-output.js.map", 2); - // 1 for reading source File, 2 for forEachEmittedFiles (verifying compiler Options and actual emit)when prepend array is created - expectedMap.set("/src/first/bin/first-output.d.ts", 3); - expectedMap.set("/src/first/bin/first-output.d.ts.map", 2); - expectedMap.set("/src/2/second-output.js", 2); - expectedMap.set("/src/2/second-output.js.map", 2); - // 1 for reading source File, 2 for forEachEmittedFiles (verifying compiler Options and actual emit)when prepend array is created - expectedMap.set("/src/2/second-output.d.ts", 3); - expectedMap.set("/src/2/second-output.d.ts.map", 2); + expectedMap.set("/src/first/bin/first-output.js", 1); + expectedMap.set("/src/first/bin/first-output.js.map", 1); + // 1 for reading source File, 1 for emit + expectedMap.set("/src/first/bin/first-output.d.ts", 2); + expectedMap.set("/src/first/bin/first-output.d.ts.map", 1); + expectedMap.set("/src/2/second-output.js", 1); + expectedMap.set("/src/2/second-output.js.map", 1); + // 1 for reading source File, 1 for emit + expectedMap.set("/src/2/second-output.d.ts", 2); + expectedMap.set("/src/2/second-output.d.ts.map", 1); assert.equal(actualReadFileMap.size, expectedMap.size, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`); actualReadFileMap.forEach((value, key) => { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 4353bbcd8fa..a384375b248 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1726,15 +1726,18 @@ declare namespace ts { } interface InputFiles extends Node { kind: SyntaxKind.InputFiles; + javascriptPath?: string; javascriptText: string; javascriptMapPath?: string; javascriptMapText?: string; + declarationPath?: string; declarationText: string; declarationMapPath?: string; declarationMapText?: string; } interface UnparsedSource extends Node { kind: SyntaxKind.UnparsedSource; + fileName?: string; text: string; sourceMapPath?: string; sourceMapText?: string; @@ -3979,9 +3982,11 @@ declare namespace ts { function updateCommaList(node: CommaListExpression, elements: ReadonlyArray): CommaListExpression; function createBundle(sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle; function createUnparsedSourceFile(text: string): UnparsedSource; + function createUnparsedSourceFile(inputFile: InputFiles, type: "js" | "dts"): UnparsedSource; function createUnparsedSourceFile(text: string, mapPath: string | undefined, map: string | undefined): UnparsedSource; - function createInputFiles(javascript: string, declaration: string): InputFiles; - function createInputFiles(javascript: string, declaration: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles; + function createInputFiles(javascriptText: string, declarationText: string): InputFiles; + function createInputFiles(readFileText: (path: string) => string | undefined, javascriptPath: string, javascriptMapPath: string | undefined, declarationPath: string, declarationMapPath: string | undefined): InputFiles; + function createInputFiles(javascriptText: string, declarationText: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles; function updateBundle(node: Bundle, sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle; function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray): CallExpression; function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray, param: ParameterDeclaration, paramValue: Expression): CallExpression; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index d8deb32c0ef..5ae49608353 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1726,15 +1726,18 @@ declare namespace ts { } interface InputFiles extends Node { kind: SyntaxKind.InputFiles; + javascriptPath?: string; javascriptText: string; javascriptMapPath?: string; javascriptMapText?: string; + declarationPath?: string; declarationText: string; declarationMapPath?: string; declarationMapText?: string; } interface UnparsedSource extends Node { kind: SyntaxKind.UnparsedSource; + fileName?: string; text: string; sourceMapPath?: string; sourceMapText?: string; @@ -3979,9 +3982,11 @@ declare namespace ts { function updateCommaList(node: CommaListExpression, elements: ReadonlyArray): CommaListExpression; function createBundle(sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle; function createUnparsedSourceFile(text: string): UnparsedSource; + function createUnparsedSourceFile(inputFile: InputFiles, type: "js" | "dts"): UnparsedSource; function createUnparsedSourceFile(text: string, mapPath: string | undefined, map: string | undefined): UnparsedSource; - function createInputFiles(javascript: string, declaration: string): InputFiles; - function createInputFiles(javascript: string, declaration: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles; + function createInputFiles(javascriptText: string, declarationText: string): InputFiles; + function createInputFiles(readFileText: (path: string) => string | undefined, javascriptPath: string, javascriptMapPath: string | undefined, declarationPath: string, declarationMapPath: string | undefined): InputFiles; + function createInputFiles(javascriptText: string, declarationText: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles; function updateBundle(node: Bundle, sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle; function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray): CallExpression; function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray, param: ParameterDeclaration, paramValue: Expression): CallExpression; From 216ed1b3859489a36a0ae0c315ec6209d64ec022 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 24 Jan 2019 13:47:27 -0800 Subject: [PATCH 3/5] Get dts content from sourceFile if present --- src/compiler/program.ts | 6 +++- src/testRunner/unittests/tsbuild.ts | 53 ++++++++++++++--------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index dbc2e61fa42..e7c2295a0ca 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1457,7 +1457,11 @@ namespace ts { if (!out) continue; const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true); - const node = createInputFiles(path => host.readFile(path), jsFilePath!, sourceMapFilePath, declarationFilePath!, declarationMapPath); + const node = createInputFiles(fileName => { + const path = toPath(fileName); + const sourceFile = getSourceFileByPath(path); + return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path); + }, jsFilePath! , sourceMapFilePath, declarationFilePath! , declarationMapPath); nodes.push(node); } } diff --git a/src/testRunner/unittests/tsbuild.ts b/src/testRunner/unittests/tsbuild.ts index be544f4eb1d..e1bc78c712b 100644 --- a/src/testRunner/unittests/tsbuild.ts +++ b/src/testRunner/unittests/tsbuild.ts @@ -495,36 +495,35 @@ export const b = new A();`); Harness.Baseline.runBaseline("outfile-concat.js", patch ? vfs.formatPatch(patch) : null); }); it("verify readFile calls", () => { - const expectedMap = createMap(); - // Configs - expectedMap.set("/src/third/tsconfig.json", 1); - expectedMap.set("/src/second/tsconfig.json", 1); - expectedMap.set("/src/first/tsconfig.json", 1); + const expected = [ + // Configs + "/src/third/tsconfig.json", + "/src/second/tsconfig.json", + "/src/first/tsconfig.json", - // Source files - expectedMap.set("/src/third/third_part1.ts", 1); - expectedMap.set("/src/second/second_part1.ts", 1); - expectedMap.set("/src/second/second_part2.ts", 1); - expectedMap.set("/src/first/first_PART1.ts", 1); - expectedMap.set("/src/first/first_part2.ts", 1); - expectedMap.set("/src/first/first_part3.ts", 1); + // Source files + "/src/third/third_part1.ts", + "/src/second/second_part1.ts", + "/src/second/second_part2.ts", + "/src/first/first_PART1.ts", + "/src/first/first_part2.ts", + "/src/first/first_part3.ts", - // outputs - expectedMap.set("/src/first/bin/first-output.js", 1); - expectedMap.set("/src/first/bin/first-output.js.map", 1); - // 1 for reading source File, 1 for emit - expectedMap.set("/src/first/bin/first-output.d.ts", 2); - expectedMap.set("/src/first/bin/first-output.d.ts.map", 1); - expectedMap.set("/src/2/second-output.js", 1); - expectedMap.set("/src/2/second-output.js.map", 1); - // 1 for reading source File, 1 for emit - expectedMap.set("/src/2/second-output.d.ts", 2); - expectedMap.set("/src/2/second-output.d.ts.map", 1); + // outputs + "/src/first/bin/first-output.js", + "/src/first/bin/first-output.js.map", + "/src/first/bin/first-output.d.ts", + "/src/first/bin/first-output.d.ts.map", + "/src/2/second-output.js", + "/src/2/second-output.js.map", + "/src/2/second-output.d.ts", + "/src/2/second-output.d.ts.map" + ]; - assert.equal(actualReadFileMap.size, expectedMap.size, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`); - actualReadFileMap.forEach((value, key) => { - const expected = expectedMap.get(key); - assert.equal(value, expected, `Expected: ${JSON.stringify(arrayFrom(expectedMap.entries()))} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`); + assert.equal(actualReadFileMap.size, expected.length, `Expected: ${JSON.stringify(expected)} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`); + expected.forEach(expectedValue => { + const actual = actualReadFileMap.get(expectedValue); + assert.equal(actual, 1, `Mismatch in read file call number for: ${expectedValue}\nExpected: ${JSON.stringify(expected)} \nActual: ${JSON.stringify(arrayFrom(actualReadFileMap.entries()))}`); }); }); }); From 399f98791808e3ace7731aa89a26a3e246d02a30 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 24 Jan 2019 13:54:45 -0800 Subject: [PATCH 4/5] Add todos for sourcemap that accidently got reverted. --- src/compiler/factory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 3707b725ed3..c59b2f67e98 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2699,9 +2699,9 @@ namespace ts { node.declarationMapPath = declarationMapPath; Object.defineProperties(node, { javascriptText: { get() { return definedTextGetter(declarationTextOrJavascriptPath); } }, - javascriptMapText: { get() { return textGetter(javascriptMapPath); } }, + javascriptMapText: { get() { return textGetter(javascriptMapPath); } }, // TODO:: if there is inline sourceMap in jsFile, use that declarationText: { get() { return definedTextGetter(Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } }, - declarationMapText: { get() { return textGetter(declarationMapPath); } } + declarationMapText: { get() { return textGetter(declarationMapPath); } } // TODO:: if there is inline sourceMap in dtsFile, use that }); } else { From ec817f55f3a143ca7b035c11cf88a621e4a6f0f1 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 24 Jan 2019 15:27:39 -0800 Subject: [PATCH 5/5] Fix unnecessary union --- src/compiler/factory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index c59b2f67e98..ab15bccafb0 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2632,7 +2632,7 @@ namespace ts { export function createUnparsedSourceFile(text: string): UnparsedSource; export function createUnparsedSourceFile(inputFile: InputFiles, type: "js" | "dts"): UnparsedSource; export function createUnparsedSourceFile(text: string, mapPath: string | undefined, map: string | undefined): UnparsedSource; - export function createUnparsedSourceFile(textOrInputFiles: string | InputFiles, mapPathOrType?: string | "js" | "dts", map?: string): UnparsedSource { + export function createUnparsedSourceFile(textOrInputFiles: string | InputFiles, mapPathOrType?: string, map?: string): UnparsedSource { const node = createNode(SyntaxKind.UnparsedSource); if (!isString(textOrInputFiles)) { Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts");