From 6af764c5606270fe34117b2051ba819581b3e199 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 26 Mar 2018 12:15:34 -0700 Subject: [PATCH] Declaration maps and transparent goto definition using them (#22658) * Add compiler option to enable declaration sourcemaps * Transparent goto definition for sourcemapped declaration files * Post-rebase touchups * Rename API methods * Fix lints * Fix typo in name XD * Log sourcemap decode errors * Share the cache more, but also invalidate it more * Remove todo * Enable mapping on go to implementation as well * Allow fourslash to test declaration maps mroe easily * more test * Handle sourceRoot * Add tests documenting current behavior with other sourcemapping flags * Ignore inline options for declaration file maps, simplify dispatch in emitter * Change program diagnostic * Fix nit * Use charCodeAt * Rename internal methods + veriables * Avoid filter * span -> position * Use character codes * Dont parse our sourcemap names until we need to start using them * zero-index parsed positions * Handle sourceMappingURL comments, including base64 encoded ones * Unittest b64 decoder, make mroe robust to handle unicode properly * Fix lint * declarationMaps -> declarationMap * Even more feedback * USE Mroe lenient combined regexp * only match base64 characters * Fix nit --- Jakefile.js | 1 + src/compiler/commandLineParser.ts | 7 + src/compiler/core.ts | 4 + src/compiler/diagnosticMessages.json | 8 + src/compiler/emitter.ts | 59 ++- src/compiler/program.ts | 22 +- src/compiler/scanner.ts | 2 +- src/compiler/sourcemap.ts | 44 +- src/compiler/sys.ts | 17 + src/compiler/types.ts | 1 + src/compiler/utilities.ts | 83 +++- src/harness/compilerRunner.ts | 2 +- src/harness/fourslash.ts | 9 +- src/harness/harness.ts | 15 +- src/harness/sourceMapRecorder.ts | 21 +- src/harness/tsconfig.json | 1 + src/harness/unittests/base64.ts | 23 + src/services/services.ts | 187 +++++++- src/services/sourcemaps.ts | 330 +++++++++++++ src/services/tsconfig.json | 1 + src/services/types.ts | 3 + .../reference/api/tsserverlibrary.d.ts | 5 +- tests/baselines/reference/api/typescript.d.ts | 5 +- tests/baselines/reference/declarationMaps.js | 43 ++ .../reference/declarationMaps.js.map | 2 + .../reference/declarationMaps.sourcemap.txt | 299 ++++++++++++ .../reference/declarationMaps.symbols | 50 ++ .../baselines/reference/declarationMaps.types | 50 ++ ...ionMapsGeneratedMapsEnableMapping.baseline | 34 ++ ...onMapsGeneratedMapsEnableMapping2.baseline | 35 ++ ...onMapsGeneratedMapsEnableMapping3.baseline | 34 ++ ...neratedMapsEnableMapping_NoInline.baseline | 34 ++ ...MapsEnableMapping_NoInlineSources.baseline | 34 ++ .../reference/declarationMapsMultifile.js | 64 +++ .../reference/declarationMapsMultifile.js.map | 3 + .../declarationMapsMultifile.sourcemap.txt | 201 ++++++++ .../declarationMapsMultifile.symbols | 47 ++ .../reference/declarationMapsMultifile.types | 56 +++ .../reference/declarationMapsOutFile.js | 69 +++ .../reference/declarationMapsOutFile.js.map | 2 + .../declarationMapsOutFile.sourcemap.txt | 195 ++++++++ .../reference/declarationMapsOutFile.symbols | 47 ++ .../reference/declarationMapsOutFile.types | 56 +++ .../reference/declarationMapsOutFile2.js | 49 ++ .../reference/declarationMapsOutFile2.js.map | 2 + .../declarationMapsOutFile2.sourcemap.txt | 139 ++++++ .../reference/declarationMapsOutFile2.symbols | 40 ++ .../reference/declarationMapsOutFile2.types | 49 ++ .../reference/declarationMapsWithSourceMap.js | 49 ++ .../declarationMapsWithSourceMap.js.map | 3 + ...declarationMapsWithSourceMap.sourcemap.txt | 433 ++++++++++++++++++ .../declarationMapsWithSourceMap.symbols | 40 ++ .../declarationMapsWithSourceMap.types | 49 ++ ...clarationMapsWithoutDeclaration.errors.txt | 23 + .../declarationMapsWithoutDeclaration.js | 24 + .../declarationMapsWithoutDeclaration.symbols | 50 ++ .../declarationMapsWithoutDeclaration.types | 50 ++ .../optionsInlineSourceMapMapRoot.errors.txt | 4 +- ...SourceRootWithNoSourceMapOption.errors.txt | 4 +- ...SourceRootWithNoSourceMapOption.errors.txt | 4 +- .../mapRootWithNoSourceMapOption.errors.txt | 4 +- .../mapRootWithNoSourceMapOption.errors.txt | 4 +- .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + tests/cases/compiler/declarationMaps.ts | 20 + .../compiler/declarationMapsMultifile.ts | 19 + .../cases/compiler/declarationMapsOutFile.ts | 21 + .../cases/compiler/declarationMapsOutFile2.ts | 17 + .../compiler/declarationMapsWithSourceMap.ts | 18 + .../declarationMapsWithoutDeclaration.ts | 19 + .../fourslash/declarationMapGoToDefinition.ts | 40 ++ .../declarationMapsEnableMapping_NoInline.ts | 34 ++ ...rationMapsEnableMapping_NoInlineSources.ts | 35 ++ ...clarationMapsGeneratedMapsEnableMapping.ts | 33 ++ ...larationMapsGeneratedMapsEnableMapping2.ts | 35 ++ ...larationMapsGeneratedMapsEnableMapping3.ts | 34 ++ tests/cases/fourslash/fourslash.ts | 2 +- 83 files changed, 3473 insertions(+), 87 deletions(-) create mode 100644 src/harness/unittests/base64.ts create mode 100644 src/services/sourcemaps.ts create mode 100644 tests/baselines/reference/declarationMaps.js create mode 100644 tests/baselines/reference/declarationMaps.js.map create mode 100644 tests/baselines/reference/declarationMaps.sourcemap.txt create mode 100644 tests/baselines/reference/declarationMaps.symbols create mode 100644 tests/baselines/reference/declarationMaps.types create mode 100644 tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping.baseline create mode 100644 tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping2.baseline create mode 100644 tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping3.baseline create mode 100644 tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping_NoInline.baseline create mode 100644 tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping_NoInlineSources.baseline create mode 100644 tests/baselines/reference/declarationMapsMultifile.js create mode 100644 tests/baselines/reference/declarationMapsMultifile.js.map create mode 100644 tests/baselines/reference/declarationMapsMultifile.sourcemap.txt create mode 100644 tests/baselines/reference/declarationMapsMultifile.symbols create mode 100644 tests/baselines/reference/declarationMapsMultifile.types create mode 100644 tests/baselines/reference/declarationMapsOutFile.js create mode 100644 tests/baselines/reference/declarationMapsOutFile.js.map create mode 100644 tests/baselines/reference/declarationMapsOutFile.sourcemap.txt create mode 100644 tests/baselines/reference/declarationMapsOutFile.symbols create mode 100644 tests/baselines/reference/declarationMapsOutFile.types create mode 100644 tests/baselines/reference/declarationMapsOutFile2.js create mode 100644 tests/baselines/reference/declarationMapsOutFile2.js.map create mode 100644 tests/baselines/reference/declarationMapsOutFile2.sourcemap.txt create mode 100644 tests/baselines/reference/declarationMapsOutFile2.symbols create mode 100644 tests/baselines/reference/declarationMapsOutFile2.types create mode 100644 tests/baselines/reference/declarationMapsWithSourceMap.js create mode 100644 tests/baselines/reference/declarationMapsWithSourceMap.js.map create mode 100644 tests/baselines/reference/declarationMapsWithSourceMap.sourcemap.txt create mode 100644 tests/baselines/reference/declarationMapsWithSourceMap.symbols create mode 100644 tests/baselines/reference/declarationMapsWithSourceMap.types create mode 100644 tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt create mode 100644 tests/baselines/reference/declarationMapsWithoutDeclaration.js create mode 100644 tests/baselines/reference/declarationMapsWithoutDeclaration.symbols create mode 100644 tests/baselines/reference/declarationMapsWithoutDeclaration.types create mode 100644 tests/cases/compiler/declarationMaps.ts create mode 100644 tests/cases/compiler/declarationMapsMultifile.ts create mode 100644 tests/cases/compiler/declarationMapsOutFile.ts create mode 100644 tests/cases/compiler/declarationMapsOutFile2.ts create mode 100644 tests/cases/compiler/declarationMapsWithSourceMap.ts create mode 100644 tests/cases/compiler/declarationMapsWithoutDeclaration.ts create mode 100644 tests/cases/fourslash/declarationMapGoToDefinition.ts create mode 100644 tests/cases/fourslash/declarationMapsEnableMapping_NoInline.ts create mode 100644 tests/cases/fourslash/declarationMapsEnableMapping_NoInlineSources.ts create mode 100644 tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping.ts create mode 100644 tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping2.ts create mode 100644 tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping3.ts diff --git a/Jakefile.js b/Jakefile.js index 584a9aa82b3a1..f2821a0168642 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -115,6 +115,7 @@ var harnessCoreSources = [ }); var harnessSources = harnessCoreSources.concat([ + "base64.ts", "incrementalParser.ts", "jsDocParsing.ts", "services/colorization.ts", diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 76a1d0b9db17a..e15cd5df7db0a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -194,6 +194,13 @@ namespace ts { category: Diagnostics.Basic_Options, description: Diagnostics.Generates_corresponding_d_ts_file, }, + { + name: "declarationMap", + type: "boolean", + showInSimplifiedHelpView: true, + category: Diagnostics.Basic_Options, + description: Diagnostics.Generates_a_sourcemap_for_each_corresponding_d_ts_file, + }, { name: "emitDeclarationOnly", type: "boolean", diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 0a05c1fcf8882..6df0a8d499791 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2048,6 +2048,10 @@ namespace ts { return moduleResolution; } + export function getAreDeclarationMapsEnabled(options: CompilerOptions) { + return !!(options.declaration && options.declarationMap); + } + export function getAllowSyntheticDefaultImports(compilerOptions: CompilerOptions) { const moduleKind = getEmitModuleKind(compilerOptions); return compilerOptions.allowSyntheticDefaultImports !== undefined diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f4f7587b78ac9..0905963541df6 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2767,7 +2767,15 @@ "category": "Error", "code": 5068 }, + "Option '{0}' cannot be specified without specifying option '{1}' or option '{2}'.": { + "category": "Error", + "code": 5069 + }, + "Generates a sourcemap for each corresponding '.d.ts' file.": { + "category": "Message", + "code": 6000 + }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f2f6980f488d0..b46ca85213557 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -49,7 +49,8 @@ namespace ts { const jsFilePath = options.outFile || options.out; const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options); const declarationFilePath = (forceDtsPaths || options.declaration) ? removeFileExtension(jsFilePath) + Extension.Dts : undefined; - return { jsFilePath, sourceMapFilePath, declarationFilePath }; + const declarationMapPath = getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; + return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath }; } else { const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options)); @@ -57,12 +58,13 @@ namespace ts { // For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error const isJs = isSourceFileJavaScript(sourceFile); const declarationFilePath = ((forceDtsPaths || options.declaration) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined; - return { jsFilePath, sourceMapFilePath, declarationFilePath }; + const declarationMapPath = getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; + return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath }; } } function getSourceMapFilePath(jsFilePath: string, options: CompilerOptions) { - return options.sourceMap ? jsFilePath + ".map" : undefined; + return (options.sourceMap && !options.inlineSourceMap) ? jsFilePath + ".map" : undefined; } // JavaScript files are always LanguageVariant.JSX, as JSX syntax is allowed in .js files also. @@ -88,12 +90,19 @@ namespace ts { export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile, emitOnlyDtsFiles?: boolean, transformers?: TransformerFactory[]): EmitResult { const compilerOptions = host.getCompilerOptions(); const moduleKind = getEmitModuleKind(compilerOptions); - const sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; + const sourceMapDataList: SourceMapData[] = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined; const emittedFilesList: string[] = compilerOptions.listEmittedFiles ? [] : undefined; const emitterDiagnostics = createDiagnosticCollection(); const newLine = host.getNewLine(); const writer = createTextWriter(newLine); const sourceMap = createSourceMapWriter(host, writer); + const declarationSourceMap = createSourceMapWriter(host, writer, { + sourceMap: compilerOptions.declarationMap, + sourceRoot: compilerOptions.sourceRoot, + mapRoot: compilerOptions.mapRoot, + extendedDiagnostics: compilerOptions.extendedDiagnostics, + // Explicitly do not passthru either `inline` option + }); let currentSourceFile: SourceFile; let bundledHelpers: Map; @@ -113,9 +122,9 @@ namespace ts { sourceMaps: sourceMapDataList }; - function emitSourceFileOrBundle({ jsFilePath, sourceMapFilePath, declarationFilePath }: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) { + function emitSourceFileOrBundle({ jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath }: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) { emitJsFileOrBundle(sourceFileOrBundle, jsFilePath, sourceMapFilePath); - emitDeclarationFileOrBundle(sourceFileOrBundle, declarationFilePath); + emitDeclarationFileOrBundle(sourceFileOrBundle, declarationFilePath, declarationMapPath); if (!emitSkipped && emittedFilesList) { if (!emitOnlyDtsFiles) { @@ -162,13 +171,13 @@ namespace ts { onSetSourceFile: setSourceFile, }); - printSourceFileOrBundle(jsFilePath, sourceMapFilePath, isSourceFile(sourceFileOrBundle) ? transform.transformed[0] : createBundle(transform.transformed), printer); + printSourceFileOrBundle(jsFilePath, sourceMapFilePath, isSourceFile(sourceFileOrBundle) ? transform.transformed[0] : createBundle(transform.transformed), printer, sourceMap); // Clean up emit nodes on parse tree transform.dispose(); } - function emitDeclarationFileOrBundle(sourceFileOrBundle: SourceFile | Bundle, declarationFilePath: string | undefined) { + function emitDeclarationFileOrBundle(sourceFileOrBundle: SourceFile | Bundle, declarationFilePath: string | undefined, declarationMapPath: string | undefined) { if (!(declarationFilePath && !isInJavaScriptFile(sourceFileOrBundle))) { return; } @@ -186,6 +195,12 @@ namespace ts { // resolver hooks hasGlobalName: resolver.hasGlobalName, + // sourcemap hooks + onEmitSourceMapOfNode: declarationSourceMap.emitNodeWithSourceMap, + onEmitSourceMapOfToken: declarationSourceMap.emitTokenWithSourceMap, + onEmitSourceMapOfPosition: declarationSourceMap.emitPos, + onSetSourceFile: setSourceFileForDeclarationSourceMaps, + // transform hooks onEmitNode: declarationTransform.emitNodeWithNotification, substituteNode: declarationTransform.substituteNode, @@ -193,18 +208,16 @@ namespace ts { const declBlocked = (!!declarationTransform.diagnostics && !!declarationTransform.diagnostics.length) || !!host.isEmitBlocked(declarationFilePath) || !!compilerOptions.noEmit; emitSkipped = emitSkipped || declBlocked; if (!declBlocked || emitOnlyDtsFiles) { - const previousState = sourceMap.setState(/*disabled*/ true); - printSourceFileOrBundle(declarationFilePath, /*sourceMapFilePath*/ undefined, declarationTransform.transformed[0], declarationPrinter, /*shouldSkipSourcemap*/ true); - sourceMap.setState(previousState); + printSourceFileOrBundle(declarationFilePath, declarationMapPath, declarationTransform.transformed[0], declarationPrinter, declarationSourceMap); } declarationTransform.dispose(); } - function printSourceFileOrBundle(jsFilePath: string, sourceMapFilePath: string, sourceFileOrBundle: SourceFile | Bundle, printer: Printer, shouldSkipSourcemap = false) { + function printSourceFileOrBundle(jsFilePath: string, sourceMapFilePath: string | undefined, sourceFileOrBundle: SourceFile | Bundle, printer: Printer, mapRecorder: SourceMapWriter) { const bundle = sourceFileOrBundle.kind === SyntaxKind.Bundle ? sourceFileOrBundle : undefined; const sourceFile = sourceFileOrBundle.kind === SyntaxKind.SourceFile ? sourceFileOrBundle : undefined; const sourceFiles = bundle ? bundle.sourceFiles : [sourceFile]; - sourceMap.initialize(jsFilePath, sourceMapFilePath, sourceFileOrBundle); + mapRecorder.initialize(jsFilePath, sourceMapFilePath || "", sourceFileOrBundle, sourceMapDataList); if (bundle) { bundledHelpers = createMap(); @@ -218,26 +231,21 @@ namespace ts { writer.writeLine(); - const sourceMappingURL = sourceMap.getSourceMappingURL(); - if (!shouldSkipSourcemap && sourceMappingURL) { + const sourceMappingURL = mapRecorder.getSourceMappingURL(); + if (sourceMappingURL) { writer.write(`//# ${"sourceMappingURL"}=${sourceMappingURL}`); // Sometimes tools can sometimes see this line as a source mapping url comment } // Write the source map - if (!shouldSkipSourcemap && compilerOptions.sourceMap && !compilerOptions.inlineSourceMap) { - writeFile(host, emitterDiagnostics, sourceMapFilePath, sourceMap.getText(), /*writeByteOrderMark*/ false, sourceFiles); - } - - // Record source map data for the test harness. - if (!shouldSkipSourcemap && sourceMapDataList) { - sourceMapDataList.push(sourceMap.getSourceMapData()); + if (sourceMapFilePath) { + writeFile(host, emitterDiagnostics, sourceMapFilePath, mapRecorder.getText(), /*writeByteOrderMark*/ false, sourceFiles); } // Write the output file writeFile(host, emitterDiagnostics, jsFilePath, writer.getText(), compilerOptions.emitBOM, sourceFiles); // Reset state - sourceMap.reset(); + mapRecorder.reset(); writer.clear(); currentSourceFile = undefined; @@ -250,6 +258,11 @@ namespace ts { sourceMap.setSourceFile(node); } + function setSourceFileForDeclarationSourceMaps(node: SourceFile) { + currentSourceFile = node; + declarationSourceMap.setSourceFile(node); + } + function emitHelpers(node: Node, writeLines: (text: string) => void) { let helpersEmitted = false; const bundle = node.kind === SyntaxKind.Bundle ? node : undefined; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index f17b4c319601c..b76f8d8b154b7 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2113,9 +2113,9 @@ namespace ts { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile"); } - if (options.mapRoot && !options.sourceMap) { + if (options.mapRoot && !(options.sourceMap || options.declarationMap)) { // Error to specify --mapRoot without --sourcemap - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap"); + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "mapRoot", "sourceMap", "declarationMap"); } if (options.declarationDir) { @@ -2127,6 +2127,10 @@ namespace ts { } } + if (options.declarationMap && !options.declaration) { + createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "declarationMap", "declaration"); + } + if (options.lib && options.noLib) { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "lib", "noLib"); } @@ -2301,21 +2305,21 @@ namespace ts { return emptyArray; } - function createDiagnosticForOptionName(message: DiagnosticMessage, option1: string, option2?: string) { - createDiagnosticForOption(/*onKey*/ true, option1, option2, message, option1, option2); + function createDiagnosticForOptionName(message: DiagnosticMessage, option1: string, option2?: string, option3?: string) { + createDiagnosticForOption(/*onKey*/ true, option1, option2, message, option1, option2, option3); } function createOptionValueDiagnostic(option1: string, message: DiagnosticMessage, arg0: string) { createDiagnosticForOption(/*onKey*/ false, option1, /*option2*/ undefined, message, arg0); } - function createDiagnosticForOption(onKey: boolean, option1: string, option2: string, message: DiagnosticMessage, arg0: string | number, arg1?: string | number) { + function createDiagnosticForOption(onKey: boolean, option1: string, option2: string, message: DiagnosticMessage, arg0: string | number, arg1?: string | number, arg2?: string | number) { const compilerOptionsObjectLiteralSyntax = getCompilerOptionsObjectLiteralSyntax(); const needCompilerDiagnostic = !compilerOptionsObjectLiteralSyntax || - !createOptionDiagnosticInObjectLiteralSyntax(compilerOptionsObjectLiteralSyntax, onKey, option1, option2, message, arg0, arg1); + !createOptionDiagnosticInObjectLiteralSyntax(compilerOptionsObjectLiteralSyntax, onKey, option1, option2, message, arg0, arg1, arg2); if (needCompilerDiagnostic) { - programDiagnostics.add(createCompilerDiagnostic(message, arg0, arg1)); + programDiagnostics.add(createCompilerDiagnostic(message, arg0, arg1, arg2)); } } @@ -2334,10 +2338,10 @@ namespace ts { return _compilerOptionsObjectLiteralSyntax; } - function createOptionDiagnosticInObjectLiteralSyntax(objectLiteral: ObjectLiteralExpression, onKey: boolean, key1: string, key2: string, message: DiagnosticMessage, arg0: string | number, arg1?: string | number): boolean { + function createOptionDiagnosticInObjectLiteralSyntax(objectLiteral: ObjectLiteralExpression, onKey: boolean, key1: string, key2: string, message: DiagnosticMessage, arg0: string | number, arg1?: string | number, arg2?: string | number): boolean { const props = getPropertyAssignment(objectLiteral, key1, key2); for (const prop of props) { - programDiagnostics.add(createDiagnosticForNodeInSourceFile(options.configFile, onKey ? prop.name : prop.initializer, message, arg0, arg1)); + programDiagnostics.add(createDiagnosticForNodeInSourceFile(options.configFile, onKey ? prop.name : prop.initializer, message, arg0, arg1, arg2)); } return !!props.length; } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 0cb9ed92d25ea..25608d0c77c6d 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -330,7 +330,7 @@ namespace ts { return result; } - export function getPositionOfLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number { + export function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number { return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character, sourceFile.text); } diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index ee5e713a9ef6b..2e81da35cfd62 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -10,7 +10,7 @@ namespace ts { * @param sourceMapFilePath The path to the output source map file. * @param sourceFileOrBundle The input source file or bundle for the program. */ - initialize(filePath: string, sourceMapFilePath: string, sourceFileOrBundle: SourceFile | Bundle): void; + initialize(filePath: string, sourceMapFilePath: string, sourceFileOrBundle: SourceFile | Bundle, sourceMapOutput?: SourceMapData[]): void; /** * Reset the SourceMapWriter to an empty state. @@ -62,16 +62,6 @@ namespace ts { * Gets the SourceMappingURL for the source map. */ getSourceMappingURL(): string; - - /** - * Gets test data for source maps. - */ - getSourceMapData(): SourceMapData; - - /** - * @returns the previous disabled state - */ - setState(disabled: boolean): boolean; } // Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans @@ -83,8 +73,16 @@ namespace ts { sourceIndex: 0 }; - export function createSourceMapWriter(host: EmitHost, writer: EmitTextWriter): SourceMapWriter { - const compilerOptions = host.getCompilerOptions(); + export interface SourceMapOptions { + sourceMap?: boolean; + inlineSourceMap?: boolean; + inlineSources?: boolean; + sourceRoot?: string; + mapRoot?: string; + extendedDiagnostics?: boolean; + } + + export function createSourceMapWriter(host: EmitHost, writer: EmitTextWriter, compilerOptions: SourceMapOptions = host.getCompilerOptions()): SourceMapWriter { const extendedDiagnostics = compilerOptions.extendedDiagnostics; let currentSource: SourceMapSource; let currentSourceText: string; @@ -100,27 +98,20 @@ namespace ts { // Source map data let sourceMapData: SourceMapData; + let sourceMapDataList: SourceMapData[]; let disabled: boolean = !(compilerOptions.sourceMap || compilerOptions.inlineSourceMap); return { initialize, reset, - getSourceMapData: () => sourceMapData, setSourceFile, emitPos, emitNodeWithSourceMap, emitTokenWithSourceMap, getText, getSourceMappingURL, - setState, }; - function setState(state: boolean) { - const last = disabled; - disabled = state; - return last; - } - /** * Skips trivia such as comments and white-space that can optionally overriden by the source map source */ @@ -135,7 +126,7 @@ namespace ts { * @param sourceMapFilePath The path to the output source map file. * @param sourceFileOrBundle The input source file or bundle for the program. */ - function initialize(filePath: string, sourceMapFilePath: string, sourceFileOrBundle: SourceFile | Bundle) { + function initialize(filePath: string, sourceMapFilePath: string, sourceFileOrBundle: SourceFile | Bundle, outputSourceMapDataList?: SourceMapData[]) { if (disabled) { return; } @@ -143,6 +134,7 @@ namespace ts { if (sourceMapData) { reset(); } + sourceMapDataList = outputSourceMapDataList; currentSource = undefined; currentSourceText = undefined; @@ -211,6 +203,11 @@ namespace ts { return; } + // Record source map data for the test harness. + if (sourceMapDataList) { + sourceMapDataList.push(sourceMapData); + } + currentSource = undefined; sourceMapDir = undefined; sourceMapSourceIndex = undefined; @@ -218,6 +215,7 @@ namespace ts { lastEncodedSourceMapSpan = undefined; lastEncodedNameIndex = undefined; sourceMapData = undefined; + sourceMapDataList = undefined; } // Encoding for sourcemap span @@ -477,7 +475,7 @@ namespace ts { if (compilerOptions.inlineSourceMap) { // Encode the sourceMap into the sourceMap url - const base64SourceMapText = convertToBase64(getText()); + const base64SourceMapText = base64encode(sys, getText()); return sourceMapData.jsSourceMappingURL = `data:application/json;base64,${base64SourceMapText}`; } else { diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index e3c304afb8f36..f459515301cac 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -457,6 +457,8 @@ namespace ts { clearTimeout?(timeoutId: any): void; clearScreen?(): void; /*@internal*/ setBlocking?(): void; + base64decode?(input: string): string; + base64encode?(input: string): string; } export interface FileWatcher { @@ -528,6 +530,11 @@ namespace ts { _crypto = undefined; } + const Buffer: { + new (input: string, encoding?: string): any; + from?(input: string, encoding?: string): any; + } = require("buffer").Buffer; + const nodeVersion = getNodeMajorVersion(); const isNode4OrLater = nodeVersion >= 4; @@ -620,6 +627,16 @@ namespace ts { if (process.stdout && process.stdout._handle && process.stdout._handle.setBlocking) { process.stdout._handle.setBlocking(true); } + }, + base64decode: Buffer.from ? input => { + return Buffer.from(input, "base64").toString("utf8"); + } : input => { + return new Buffer(input, "base64").toString("utf8"); + }, + base64encode: Buffer.from ? input => { + return Buffer.from(input).toString("base64"); + } : input => { + return new Buffer(input).toString("base64"); } }; return nodeSystem; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 99e94f2d576d5..51b1d984bf6a6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4105,6 +4105,7 @@ namespace ts { /** configFile is set as non enumerable property so as to avoid checking of json source files */ /* @internal */ readonly configFile?: JsonSourceFile; declaration?: boolean; + declarationMap?: boolean; emitDeclarationOnly?: boolean; declarationDir?: string; /* @internal */ diagnostics?: boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bcb9f5992a9d8..c9d8b6af5c04d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2834,8 +2834,9 @@ namespace ts { export interface EmitFileNames { jsFilePath: string; - sourceMapFilePath: string; - declarationFilePath: string; + sourceMapFilePath: string | undefined; + declarationFilePath: string | undefined; + declarationMapPath: string | undefined; } /** @@ -3413,7 +3414,7 @@ namespace ts { for (let i = 0; i < length; i++) { const charCode = input.charCodeAt(i); - // handel utf8 + // handle utf8 if (charCode < 0x80) { output.push(charCode); } @@ -3478,6 +3479,82 @@ namespace ts { return result; } + function getStringFromExpandedCharCodes(codes: number[]): string { + let output = ""; + let i = 0; + const length = codes.length; + while (i < length) { + const charCode = codes[i]; + + if (charCode < 0x80) { + output += String.fromCharCode(charCode); + i++; + } + else if ((charCode & 0B11000000) === 0B11000000) { + let value = charCode & 0B00111111; + i++; + let nextCode: number = codes[i]; + while ((nextCode & 0B11000000) === 0B10000000) { + value = (value << 6) | (nextCode & 0B00111111); + i++; + nextCode = codes[i]; + } + // `value` may be greater than 10FFFF (the maximum unicode codepoint) - JS will just make this into an invalid character for us + output += String.fromCharCode(value); + } + else { + // We don't want to kill the process when decoding fails (due to a following char byte not + // following a leading char), so we just print the (bad) value + output += String.fromCharCode(charCode); + i++; + } + } + return output; + } + + export function base64encode(host: { base64encode?(input: string): string }, input: string): string { + if (host.base64encode) { + return host.base64encode(input); + } + return convertToBase64(input); + } + + export function base64decode(host: { base64decode?(input: string): string }, input: string): string { + if (host.base64decode) { + return host.base64decode(input); + } + const length = input.length; + const expandedCharCodes: number[] = []; + let i = 0; + while (i < length) { + // Stop decoding once padding characters are present + if (input.charCodeAt(i) === base64Digits.charCodeAt(64)) { + break; + } + // convert 4 input digits into three characters, ignoring padding characters at the end + const ch1 = base64Digits.indexOf(input[i]); + const ch2 = base64Digits.indexOf(input[i + 1]); + const ch3 = base64Digits.indexOf(input[i + 2]); + const ch4 = base64Digits.indexOf(input[i + 3]); + + const code1 = ((ch1 & 0B00111111) << 2) | ((ch2 >> 4) & 0B00000011); + const code2 = ((ch2 & 0B00001111) << 4) | ((ch3 >> 2) & 0B00001111); + const code3 = ((ch3 & 0B00000011) << 6) | (ch4 & 0B00111111); + + if (code2 === 0 && ch3 !== 0) { // code2 decoded to zero, but ch3 was padding - elide code2 and code3 + expandedCharCodes.push(code1); + } + else if (code3 === 0 && ch4 !== 0) { // code3 decoded to zero, but ch4 was padding, elide code3 + expandedCharCodes.push(code1, code2); + } + else { + expandedCharCodes.push(code1, code2, code3); + } + i += 4; + } + return getStringFromExpandedCharCodes(expandedCharCodes); + } + const carriageReturnLineFeed = "\r\n"; const lineFeed = "\n"; export function getNewLineCharacter(options: CompilerOptions | PrinterOptions, getNewLine?: () => string): string { diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 30c5e47949f44..4edff00b2887e 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -148,7 +148,7 @@ class CompilerBaselineRunner extends RunnerBase { // Source maps? it("Correct sourcemap content for " + fileName, () => { - if (options.sourceMap || options.inlineSourceMap) { + if (options.sourceMap || options.inlineSourceMap || options.declarationMap) { Harness.Baseline.runBaseline(justName.replace(/\.tsx?$/, ".sourcemap.txt"), () => { const record = result.getSourceMapRecord(); if ((options.noEmitOnError && result.errors.length !== 0) || record === undefined) { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 4c0b775a6175a..f209cafb8a114 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1600,7 +1600,7 @@ Actual: ${stringify(fullActual)}`); }); } - public baselineGetEmitOutput() { + public baselineGetEmitOutput(insertResultsIntoVfs?: boolean) { // Find file to be emitted const emitFiles: FourSlashFile[] = []; // List of FourSlashFile that has emitThisFile flag on @@ -1649,6 +1649,9 @@ Actual: ${stringify(fullActual)}`); for (const outputFile of emitOutput.outputFiles) { const fileName = "FileName : " + outputFile.name + Harness.IO.newLine(); resultString = resultString + fileName + outputFile.text; + if (insertResultsIntoVfs) { + this.languageServiceAdapterHost.addScript(ts.getNormalizedAbsolutePath(outputFile.name, "/"), outputFile.text, /*isRootFile*/ true); + } } resultString += Harness.IO.newLine(); }); @@ -4154,8 +4157,8 @@ namespace FourSlashInterface { this.state.baselineCurrentFileNameOrDottedNameSpans(); } - public baselineGetEmitOutput() { - this.state.baselineGetEmitOutput(); + public baselineGetEmitOutput(insertResultsIntoVfs?: boolean) { + this.state.baselineGetEmitOutput(insertResultsIntoVfs); } public baselineQuickInfo() { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 424ee932541a4..9e6978f2a15ff 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1632,14 +1632,15 @@ namespace Harness { } export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult, harnessSettings: TestCaseParser.CompilerSettings) { + const declMaps = ts.getAreDeclarationMapsEnabled(options); if (options.inlineSourceMap) { - if (result.sourceMaps.length > 0) { + if (result.sourceMaps.length > 0 && !declMaps) { throw new Error("No sourcemap files should be generated if inlineSourceMaps was set."); } return; } - else if (options.sourceMap) { - if (result.sourceMaps.length !== result.files.length) { + else if (options.sourceMap || declMaps) { + if (result.sourceMaps.length !== (result.files.length * (declMaps && options.sourceMap ? 2 : 1))) { throw new Error("Number of sourcemap files should be same as js files."); } @@ -1806,6 +1807,10 @@ namespace Harness { return ts.endsWith(fileName, ".js.map") || ts.endsWith(fileName, ".jsx.map"); } + export function isDTSMap(fileName: string) { + return ts.endsWith(fileName, ".d.ts.map"); + } + /** Contains the code and errors of a compilation and some helper methods to check its status. */ export class CompilerResult { public files: GeneratedFile[] = []; @@ -1826,7 +1831,7 @@ namespace Harness { // .js file, add to files this.files.push(emittedFile); } - else if (isJSMap(emittedFile.fileName)) { + else if (isJSMap(emittedFile.fileName) || isDTSMap(emittedFile.fileName)) { this.sourceMaps.push(emittedFile); } else { @@ -1839,7 +1844,7 @@ namespace Harness { public getSourceMapRecord() { if (this.sourceMapData && this.sourceMapData.length > 0) { - return SourceMapRecorder.getSourceMapRecord(this.sourceMapData, this.program, this.files); + return SourceMapRecorder.getSourceMapRecord(this.sourceMapData, this.program, this.files, this.declFilesCode); } } } diff --git a/src/harness/sourceMapRecorder.ts b/src/harness/sourceMapRecorder.ts index 606d4e67acdf3..78a0fe7969df1 100644 --- a/src/harness/sourceMapRecorder.ts +++ b/src/harness/sourceMapRecorder.ts @@ -434,14 +434,31 @@ namespace Harness.SourceMapRecorder { } } - export function getSourceMapRecord(sourceMapDataList: ts.SourceMapData[], program: ts.Program, jsFiles: Compiler.GeneratedFile[]) { + export function getSourceMapRecord(sourceMapDataList: ts.SourceMapData[], program: ts.Program, jsFiles: Compiler.GeneratedFile[], declarationFiles: Compiler.GeneratedFile[]) { const sourceMapRecorder = new Compiler.WriterAggregator(); for (let i = 0; i < sourceMapDataList.length; i++) { const sourceMapData = sourceMapDataList[i]; let prevSourceFile: ts.SourceFile; + let currentFile: Compiler.GeneratedFile; + if (ts.endsWith(sourceMapData.sourceMapFile, ts.Extension.Dts)) { + if (sourceMapDataList.length > jsFiles.length) { + currentFile = declarationFiles[Math.floor(i / 2)]; // When both kinds of source map are present, they alternate js/dts + } + else { + currentFile = declarationFiles[i]; + } + } + else { + if (sourceMapDataList.length > jsFiles.length) { + currentFile = jsFiles[Math.floor(i / 2)]; + } + else { + currentFile = jsFiles[i]; + } + } - SourceMapSpanWriter.initializeSourceMapSpanWriter(sourceMapRecorder, sourceMapData, jsFiles[i]); + SourceMapSpanWriter.initializeSourceMapSpanWriter(sourceMapRecorder, sourceMapData, currentFile); for (const decodedSourceMapping of sourceMapData.sourceMapDecodedMappings) { const currentSourceFile = program.getSourceFile(sourceMapData.inputSourceFileNames[decodedSourceMapping.sourceIndex]); if (currentSourceFile !== prevSourceFile) { diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 6b5a42c2d98e0..54766ed02eca4 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -95,6 +95,7 @@ "../server/session.ts", "../server/client.ts", "../server/editorServices.ts", + "./unittests/base64.ts", "./unittests/incrementalParser.ts", "./unittests/jsDocParsing.ts", "./unittests/services/colorization.ts", diff --git a/src/harness/unittests/base64.ts b/src/harness/unittests/base64.ts new file mode 100644 index 0000000000000..b503955ee68d9 --- /dev/null +++ b/src/harness/unittests/base64.ts @@ -0,0 +1,23 @@ +/// +namespace ts { + describe("base64", () => { + describe("base64decode", () => { + it("can decode input strings correctly without needing a host implementation", () => { + const tests = [ + // "a", + // "this is a test", + // " !\"#$ %&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", + "日本語", + "🐱", + "\x00\x01", + "\t\n\r\\\"\'\u0062", + "====", + "", + ]; + for (const test of tests) { + assert.equal(base64decode({}, convertToBase64(test)), test); + } + }); + }); + }); +} diff --git a/src/services/services.ts b/src/services/services.ts index d498b5d911591..cd35e0375a38b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -30,6 +30,7 @@ /// /// /// +/// namespace ts { /** The version of the language service API */ @@ -1169,6 +1170,35 @@ namespace ts { } } + /* @internal */ + export interface SourceFileLikeCache { + get(path: Path): SourceFileLike | undefined; + } + + /* @internal */ + export function createSourceFileLikeCache(host: { readFile?: (path: string) => string, fileExists?: (path: string) => boolean }): SourceFileLikeCache { + const cached = createMap(); + return { + get(path: Path) { + if (cached.has(path)) { + return cached.get(path); + } + if (!host.fileExists || !host.readFile || !host.fileExists(path)) return; + // And failing that, check the disk + const text = host.readFile(path); + const file: SourceFileLike = { + text, + lineMap: undefined, + getLineAndCharacterOfPosition(pos) { + return computeLineAndCharacterOfPosition(getLineStarts(this), pos); + } + }; + cached.set(path, file); + return file; + } + }; + } + export function createLanguageService(host: LanguageServiceHost, documentRegistry: DocumentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory())): LanguageService { @@ -1186,6 +1216,8 @@ namespace ts { localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages(); } + let sourcemappedFileCache: SourceFileLikeCache; + function log(message: string) { if (host.log) { host.log(message); @@ -1293,6 +1325,11 @@ namespace ts { // It needs to be cleared to allow all collected snapshots to be released hostCache = undefined; + // We reset this cache on structure invalidation so we don't hold on to outdated files for long; however we can't use the `compilerHost` above, + // Because it only functions until `hostCache` is cleared, while we'll potentially need the functionality to lazily read sourcemap files during + // the course of whatever called `synchronizeHostData` + sourcemappedFileCache = createSourceFileLikeCache(host); + // Make sure all the nodes in the program are both bound, and have their parent // pointers set property. program.getTypeChecker(); @@ -1543,26 +1580,168 @@ namespace ts { return checker.getSymbolAtLocation(node); } + + const sourceMapCommentRegExp = /^\/\/[@#] sourceMappingURL=(.+)$/gm; + const base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/; + function scanForSourcemapURL(fileName: string) { + const mappedFile = sourcemappedFileCache.get(toPath(fileName, currentDirectory, getCanonicalFileName)); + if (!mappedFile) { + return; + } + const starts = getLineStarts(mappedFile); + for (let index = starts.length - 1; index >= 0; index--) { + sourceMapCommentRegExp.lastIndex = starts[index]; + const comment = sourceMapCommentRegExp.exec(mappedFile.text); + if (comment) { + return comment[1]; + } + } + } + + function convertDocumentToSourceMapper(file: { sourceMapper?: sourcemaps.SourceMapper }, contents: string, mapFileName: string) { + let maps: sourcemaps.SourceMapData; + try { + maps = JSON.parse(contents); + } + catch { + // swallow error + } + if (!maps || !maps.sources || !maps.file || !maps.mappings) { + // obviously invalid map + return file.sourceMapper = sourcemaps.identitySourceMapper; + } + return file.sourceMapper = sourcemaps.decode({ + readFile: s => host.readFile(s), + fileExists: s => host.fileExists(s), + getCanonicalFileName, + log, + }, mapFileName, maps, program, sourcemappedFileCache); + } + + function getSourceMapper(fileName: string, file: { sourceMapper?: sourcemaps.SourceMapper }) { + if (!host.readFile || !host.fileExists) { + return file.sourceMapper = sourcemaps.identitySourceMapper; + } + if (file.sourceMapper) { + return file.sourceMapper; + } + let mapFileName = scanForSourcemapURL(fileName); + if (mapFileName) { + const match = base64UrlRegExp.exec(mapFileName); + if (match) { + if (match[1]) { + const base64Object = match[1]; + return convertDocumentToSourceMapper(file, base64decode(sys, base64Object), fileName); + } + // Not a data URL we can parse, skip it + mapFileName = undefined; + } + } + const possibleMapLocations: string[] = []; + if (mapFileName) { + possibleMapLocations.push(mapFileName); + } + possibleMapLocations.push(fileName + ".map"); + for (const location of possibleMapLocations) { + const mapPath = toPath(location, getDirectoryPath(fileName), getCanonicalFileName); + if (host.fileExists(mapPath)) { + return convertDocumentToSourceMapper(file, host.readFile(mapPath), mapPath); + } + } + return file.sourceMapper = sourcemaps.identitySourceMapper; + } + + function makeGetTargetOfMappedPosition( + extract: (original: TIn) => sourcemaps.SourceMappableLocation, + create: (result: sourcemaps.SourceMappableLocation, original: TIn) => TIn + ) { + return getTargetOfMappedPosition; + function getTargetOfMappedPosition(input: TIn): TIn { + const info = extract(input); + if (endsWith(info.fileName, Extension.Dts)) { + let file: SourceFileLike = program.getSourceFile(info.fileName); + if (!file) { + const path = toPath(info.fileName, currentDirectory, getCanonicalFileName); + file = sourcemappedFileCache.get(path); + } + if (!file) { + return input; + } + const mapper = getSourceMapper(info.fileName, file); + const newLoc = mapper.getOriginalPosition(info); + if (newLoc === info) return input; + return getTargetOfMappedPosition(create(newLoc, input)); + } + return input; + } + } + + const getTargetOfMappedDeclarationInfo = makeGetTargetOfMappedPosition( + (info: DefinitionInfo) => ({ fileName: info.fileName, position: info.textSpan.start }), + (newLoc, info) => ({ + containerKind: info.containerKind, + containerName: info.containerName, + fileName: newLoc.fileName, + kind: info.kind, + name: info.name, + textSpan: { + start: newLoc.position, + length: info.textSpan.length + } + }) + ); + + function getTargetOfMappedDeclarationFiles(infos: ReadonlyArray): DefinitionInfo[] { + return map(infos, getTargetOfMappedDeclarationInfo); + } + /// Goto definition function getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { synchronizeHostData(); - return GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position); + return getTargetOfMappedDeclarationFiles(GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position)); } function getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan { synchronizeHostData(); - return GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position); + const result = GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position); + if (!result) return result; + const mappedDefs = getTargetOfMappedDeclarationFiles(result.definitions); + if (mappedDefs === result.definitions) { + return result; + } + return { + definitions: mappedDefs, + textSpan: result.textSpan + }; } function getTypeDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { synchronizeHostData(); - return GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position); + return getTargetOfMappedDeclarationFiles(GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position)); } /// Goto implementation + + const getTargetOfMappedImplementationLocation = makeGetTargetOfMappedPosition( + (info: ImplementationLocation) => ({ fileName: info.fileName, position: info.textSpan.start }), + (newLoc, info) => ({ + fileName: newLoc.fileName, + kind: info.kind, + displayParts: info.displayParts, + textSpan: { + start: newLoc.position, + length: info.textSpan.length + } + }) + ); + + function getTargetOfMappedImplementationLocations(infos: ReadonlyArray): ImplementationLocation[] { + return map(infos, getTargetOfMappedImplementationLocation); + } + function getImplementationAtPosition(fileName: string, position: number): ImplementationLocation[] { synchronizeHostData(); - return FindAllReferences.getImplementationsAtPosition(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position); + return getTargetOfMappedImplementationLocations(FindAllReferences.getImplementationsAtPosition(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position)); } /// References and Occurrences diff --git a/src/services/sourcemaps.ts b/src/services/sourcemaps.ts new file mode 100644 index 0000000000000..c24ed0f64a8f4 --- /dev/null +++ b/src/services/sourcemaps.ts @@ -0,0 +1,330 @@ +/* @internal */ +namespace ts.sourcemaps { + export interface SourceMapData { + version?: number; + file?: string; + sourceRoot?: string; + sources: string[]; + sourcesContent?: string[]; + names?: string[]; + mappings: string; + } + + export interface SourceMappableLocation { + fileName: string; + position: number; + } + + export interface SourceMapper { + getOriginalPosition(input: SourceMappableLocation): SourceMappableLocation; + getGeneratedPosition(input: SourceMappableLocation): SourceMappableLocation; + } + + export const identitySourceMapper = { getOriginalPosition: identity, getGeneratedPosition: identity }; + + export interface SourceMapDecodeHost { + readFile(path: string): string; + fileExists(path: string): boolean; + getCanonicalFileName(path: string): string; + log(text: string): void; + } + + export function decode(host: SourceMapDecodeHost, mapPath: string, map: SourceMapData, program?: Program, fallbackCache = createSourceFileLikeCache(host)): SourceMapper { + const currentDirectory = getDirectoryPath(mapPath); + const sourceRoot = map.sourceRoot || currentDirectory; + let decodedMappings: ProcessedSourceMapPosition[]; + let generatedOrderedMappings: ProcessedSourceMapPosition[]; + let sourceOrderedMappings: ProcessedSourceMapPosition[]; + + return { + getOriginalPosition, + getGeneratedPosition + }; + + function getGeneratedPosition(loc: SourceMappableLocation): SourceMappableLocation { + const maps = getGeneratedOrderedMappings(); + if (!length(maps)) return loc; + let targetIndex = binarySearch(maps, { sourcePath: loc.fileName, sourcePosition: loc.position }, identity, compareProcessedPositionSourcePositions); + if (targetIndex < 0 && maps.length > 0) { + // if no exact match, closest is 2's compliment of result + targetIndex = ~targetIndex; + } + if (!maps[targetIndex] || comparePaths(loc.fileName, maps[targetIndex].sourcePath, sourceRoot) !== 0) { + return loc; + } + return { fileName: toPath(map.file, sourceRoot, host.getCanonicalFileName), position: maps[targetIndex].emittedPosition }; // Closest pos + } + + function getOriginalPosition(loc: SourceMappableLocation): SourceMappableLocation { + const maps = getSourceOrderedMappings(); + if (!length(maps)) return loc; + let targetIndex = binarySearch(maps, { emittedPosition: loc.position }, identity, compareProcessedPositionEmittedPositions); + if (targetIndex < 0 && maps.length > 0) { + // if no exact match, closest is 2's compliment of result + targetIndex = ~targetIndex; + } + return { fileName: toPath(maps[targetIndex].sourcePath, sourceRoot, host.getCanonicalFileName), position: maps[targetIndex].sourcePosition }; // Closest pos + } + + function getSourceFileLike(fileName: string, location: string): SourceFileLike | undefined { + // Lookup file in program, if provided + const file: SourceFileLike = program && program.getSourceFile(fileName); + if (!file) { + // Otherwise check the cache (which may hit disk) + const path = toPath(fileName, location, host.getCanonicalFileName); + return fallbackCache.get(path); + } + return file; + } + + function getPositionOfLineAndCharacterUsingName(fileName: string, directory: string, line: number, character: number) { + const file = getSourceFileLike(fileName, directory); + if (!file) { + return -1; + } + return getPositionOfLineAndCharacter(file, line, character); + } + + function getDecodedMappings() { + return decodedMappings || (decodedMappings = calculateDecodedMappings()); + } + + function getSourceOrderedMappings() { + return sourceOrderedMappings || (sourceOrderedMappings = getDecodedMappings().slice().sort(compareProcessedPositionSourcePositions)); + } + + function getGeneratedOrderedMappings() { + return generatedOrderedMappings || (generatedOrderedMappings = getDecodedMappings().slice().sort(compareProcessedPositionEmittedPositions)); + } + + function calculateDecodedMappings(): ProcessedSourceMapPosition[] { + const state: DecoderState = { + encodedText: map.mappings, + currentNameIndex: undefined, + sourceMapNamesLength: map.names ? map.names.length : undefined, + currentEmittedColumn: 0, + currentEmittedLine: 0, + currentSourceColumn: 0, + currentSourceLine: 0, + currentSourceIndex: 0, + positions: [], + decodingIndex: 0, + processPosition, + }; + while (!hasCompletedDecoding(state)) { + decodeSinglePosition(state); + if (state.error) { + host.log(`Encountered error while decoding sourcemap found at ${mapPath}: ${state.error}`); + return []; + } + } + return state.positions; + } + + function compareProcessedPositionSourcePositions(a: ProcessedSourceMapPosition, b: ProcessedSourceMapPosition) { + return comparePaths(a.sourcePath, b.sourcePath, sourceRoot) || + compareValues(a.sourcePosition, b.sourcePosition); + } + + function compareProcessedPositionEmittedPositions(a: ProcessedSourceMapPosition, b: ProcessedSourceMapPosition) { + return compareValues(a.emittedPosition, b.emittedPosition); + } + + function processPosition(position: RawSourceMapPosition): ProcessedSourceMapPosition { + const sourcePath = map.sources[position.sourceIndex]; + return { + emittedPosition: getPositionOfLineAndCharacterUsingName(map.file, currentDirectory, position.emittedLine, position.emittedColumn), + sourcePosition: getPositionOfLineAndCharacterUsingName(sourcePath, sourceRoot, position.sourceLine, position.sourceColumn), + sourcePath, + // TODO: Consider using `name` field to remap the expected identifier to scan for renames to handle another tool renaming oout output + // name: position.nameIndex ? map.names[position.nameIndex] : undefined + }; + } + } + + interface ProcessedSourceMapPosition { + emittedPosition: number; + sourcePosition: number; + sourcePath: string; + } + + interface RawSourceMapPosition { + emittedLine: number; + emittedColumn: number; + sourceLine: number; + sourceColumn: number; + sourceIndex: number; + nameIndex?: number; + } + + interface DecoderState { + decodingIndex: number; + currentEmittedLine: number; + currentEmittedColumn: number; + currentSourceLine: number; + currentSourceColumn: number; + currentSourceIndex: number; + currentNameIndex: number; + encodedText: string; + sourceMapNamesLength?: number; + error?: string; + positions: T[]; + processPosition: (position: RawSourceMapPosition) => T; + } + + function hasCompletedDecoding(state: DecoderState) { + return state.decodingIndex === state.encodedText.length; + } + + function decodeSinglePosition(state: DecoderState): void { + while (state.decodingIndex < state.encodedText.length) { + const char = state.encodedText.charCodeAt(state.decodingIndex); + if (char === CharacterCodes.semicolon) { + // New line + state.currentEmittedLine++; + state.currentEmittedColumn = 0; + state.decodingIndex++; + continue; + } + + if (char === CharacterCodes.comma) { + // Next entry is on same line - no action needed + state.decodingIndex++; + continue; + } + + // Read the current position + // 1. Column offset from prev read jsColumn + state.currentEmittedColumn += base64VLQFormatDecode(); + // Incorrect emittedColumn dont support this map + if (createErrorIfCondition(state.currentEmittedColumn < 0, "Invalid emittedColumn found")) { + return; + } + // Dont support reading mappings that dont have information about original source and its line numbers + if (createErrorIfCondition(isSourceMappingSegmentEnd(state.encodedText, state.decodingIndex), "Unsupported Error Format: No entries after emitted column")) { + return; + } + + // 2. Relative sourceIndex + state.currentSourceIndex += base64VLQFormatDecode(); + // Incorrect sourceIndex dont support this map + if (createErrorIfCondition(state.currentSourceIndex < 0, "Invalid sourceIndex found")) { + return; + } + // Dont support reading mappings that dont have information about original source position + if (createErrorIfCondition(isSourceMappingSegmentEnd(state.encodedText, state.decodingIndex), "Unsupported Error Format: No entries after sourceIndex")) { + return; + } + + // 3. Relative sourceLine 0 based + state.currentSourceLine += base64VLQFormatDecode(); + // Incorrect sourceLine dont support this map + if (createErrorIfCondition(state.currentSourceLine < 0, "Invalid sourceLine found")) { + return; + } + // Dont support reading mappings that dont have information about original source and its line numbers + if (createErrorIfCondition(isSourceMappingSegmentEnd(state.encodedText, state.decodingIndex), "Unsupported Error Format: No entries after emitted Line")) { + return; + } + + // 4. Relative sourceColumn 0 based + state.currentSourceColumn += base64VLQFormatDecode(); + // Incorrect sourceColumn dont support this map + if (createErrorIfCondition(state.currentSourceColumn < 0, "Invalid sourceLine found")) { + return; + } + // 5. Check if there is name: + if (!isSourceMappingSegmentEnd(state.encodedText, state.decodingIndex)) { + if (state.currentNameIndex === undefined) { + state.currentNameIndex = 0; + } + state.currentNameIndex += base64VLQFormatDecode(); + // Incorrect nameIndex dont support this map + // TODO: If we start using `name`s, issue errors when they aren't correct in the sourcemap + // if (createErrorIfCondition(state.currentNameIndex < 0 || state.currentNameIndex >= state.sourceMapNamesLength, "Invalid name index for the source map entry")) { + // return; + // } + } + // Dont support reading mappings that dont have information about original source and its line numbers + if (createErrorIfCondition(!isSourceMappingSegmentEnd(state.encodedText, state.decodingIndex), "Unsupported Error Format: There are more entries after " + (state.currentNameIndex === undefined ? "sourceColumn" : "nameIndex"))) { + return; + } + + // Entry should be complete + capturePosition(); + return; + } + + createErrorIfCondition(/*condition*/ true, "No encoded entry found"); + return; + + function capturePosition() { + state.positions.push(state.processPosition({ + emittedColumn: state.currentEmittedColumn, + emittedLine: state.currentEmittedLine, + sourceColumn: state.currentSourceColumn, + sourceIndex: state.currentSourceIndex, + sourceLine: state.currentSourceLine, + nameIndex: state.currentNameIndex + })); + } + + function createErrorIfCondition(condition: boolean, errormsg: string) { + if (state.error) { + // An error was already reported + return true; + } + + if (condition) { + state.error = errormsg; + } + + return condition; + } + + function base64VLQFormatDecode() { + let moreDigits = true; + let shiftCount = 0; + let value = 0; + + for (; moreDigits; state.decodingIndex++) { + if (createErrorIfCondition(state.decodingIndex >= state.encodedText.length, "Error in decoding base64VLQFormatDecode, past the mapping string")) { + return; + } + + // 6 digit number + const currentByte = base64FormatDecode(state.encodedText.charAt(state.decodingIndex)); + + // If msb is set, we still have more bits to continue + moreDigits = (currentByte & 32) !== 0; + + // least significant 5 bits are the next msbs in the final value. + value = value | ((currentByte & 31) << shiftCount); + shiftCount += 5; + } + + // Least significant bit if 1 represents negative and rest of the msb is actual absolute value + if ((value & 1) === 0) { + // + number + value = value >> 1; + } + else { + // - number + value = value >> 1; + value = -value; + } + + return value; + } + } + + function base64FormatDecode(char: string) { + return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(char); + } + + function isSourceMappingSegmentEnd(encodedText: string, pos: number) { + return (pos === encodedText.length || + encodedText.charCodeAt(pos) === CharacterCodes.comma || + encodedText.charCodeAt(pos) === CharacterCodes.semicolon); + } +} \ No newline at end of file diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 7ea6c1fa976f1..4f838df6341fb 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -72,6 +72,7 @@ "shims.ts", "signatureHelp.ts", "suggestionDiagnostics.ts", + "sourcemaps.ts", "symbolDisplay.ts", "textChanges.ts", "refactorProvider.ts", diff --git a/src/services/types.ts b/src/services/types.ts index f37d3cb592c8b..af496cfeb118d 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -75,10 +75,13 @@ namespace ts { getLineStarts(): ReadonlyArray; getPositionOfLineAndCharacter(line: number, character: number): number; update(newText: string, textChangeRange: TextChangeRange): SourceFile; + + /* @internal */ sourceMapper?: sourcemaps.SourceMapper; } export interface SourceFileLike { getLineAndCharacterOfPosition(pos: number): LineAndCharacter; + /*@internal*/ sourceMapper?: sourcemaps.SourceMapper; } export interface SourceMapSource { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index c0bca57854500..c344b31b1fc13 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2307,6 +2307,7 @@ declare namespace ts { charset?: string; checkJs?: boolean; declaration?: boolean; + declarationMap?: boolean; emitDeclarationOnly?: boolean; declarationDir?: string; disableSizeLimit?: boolean; @@ -2897,6 +2898,8 @@ declare namespace ts { setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any; clearTimeout?(timeoutId: any): void; clearScreen?(): void; + base64decode?(input: string): string; + base64encode?(input: string): string; } interface FileWatcher { close(): void; @@ -3283,7 +3286,7 @@ declare namespace ts { tryScan(callback: () => T): T; } function tokenToString(t: SyntaxKind): string | undefined; - function getPositionOfLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; + function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; function isWhiteSpaceLike(ch: number): boolean; /** Does not include line breaks. For that, see isWhiteSpaceLike. */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index ae3ad58ea33c3..f849dc7f664e6 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2307,6 +2307,7 @@ declare namespace ts { charset?: string; checkJs?: boolean; declaration?: boolean; + declarationMap?: boolean; emitDeclarationOnly?: boolean; declarationDir?: string; disableSizeLimit?: boolean; @@ -2897,6 +2898,8 @@ declare namespace ts { setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any; clearTimeout?(timeoutId: any): void; clearScreen?(): void; + base64decode?(input: string): string; + base64encode?(input: string): string; } interface FileWatcher { close(): void; @@ -2938,7 +2941,7 @@ declare namespace ts { tryScan(callback: () => T): T; } function tokenToString(t: SyntaxKind): string | undefined; - function getPositionOfLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; + function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; function isWhiteSpaceLike(ch: number): boolean; /** Does not include line breaks. For that, see isWhiteSpaceLike. */ diff --git a/tests/baselines/reference/declarationMaps.js b/tests/baselines/reference/declarationMaps.js new file mode 100644 index 0000000000000..1e8dc97d6c4bf --- /dev/null +++ b/tests/baselines/reference/declarationMaps.js @@ -0,0 +1,43 @@ +//// [declarationMaps.ts] +module m2 { + export interface connectModule { + (res, req, next): void; + } + export interface connectExport { + use: (mod: connectModule) => connectExport; + listen: (port: number) => void; + } + +} + +var m2: { + (): m2.connectExport; + test1: m2.connectModule; + test2(): m2.connectModule; +}; + +export = m2; + +//// [declarationMaps.js] +"use strict"; +var m2; +module.exports = m2; + + +//// [declarationMaps.d.ts] +declare module m2 { + interface connectModule { + (res: any, req: any, next: any): void; + } + interface connectExport { + use: (mod: connectModule) => connectExport; + listen: (port: number) => void; + } +} +declare var m2: { + (): m2.connectExport; + test1: m2.connectModule; + test2(): m2.connectModule; +}; +export = m2; +//# sourceMappingURL=declarationMaps.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMaps.js.map b/tests/baselines/reference/declarationMaps.js.map new file mode 100644 index 0000000000000..973eb12afdab5 --- /dev/null +++ b/tests/baselines/reference/declarationMaps.js.map @@ -0,0 +1,2 @@ +//// [declarationMaps.d.ts.map] +{"version":3,"file":"declarationMaps.d.ts","sourceRoot":"","sources":["declarationMaps.ts"],"names":[],"mappings":"AAAA,eAAO,EAAE,CAAC;IACN,UAAiB,aAAa;QAC1B,CAAC,GAAG,KAAA,EAAE,GAAG,KAAA,EAAE,IAAI,KAAA,GAAG,IAAI,CAAC;KAC1B;IACD,UAAiB,aAAa;QAC1B,GAAG,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,aAAa,CAAC;QAC3C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;KAClC;CAEJ;AAED,QAAA,IAAI,EAAE,EAAE;IACJ,IAAI,EAAE,CAAC,aAAa,CAAC;IACrB,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC;IACxB,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC;CAC7B,CAAC;AAEF,SAAS,EAAE,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/declarationMaps.sourcemap.txt b/tests/baselines/reference/declarationMaps.sourcemap.txt new file mode 100644 index 0000000000000..f1c4591aacb47 --- /dev/null +++ b/tests/baselines/reference/declarationMaps.sourcemap.txt @@ -0,0 +1,299 @@ +=================================================================== +JsFile: declarationMaps.d.ts +mapUrl: declarationMaps.d.ts.map +sourceRoot: +sources: declarationMaps.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/declarationMaps.d.ts +sourceFile:declarationMaps.ts +------------------------------------------------------------------- +>>>declare module m2 { +1 > +2 >^^^^^^^^^^^^^^^ +3 > ^^ +4 > ^ +5 > ^^^^^^^^^^^^-> +1 > +2 >module +3 > m2 +4 > +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 16) Source(1, 8) + SourceIndex(0) +3 >Emitted(1, 18) Source(1, 10) + SourceIndex(0) +4 >Emitted(1, 19) Source(1, 11) + SourceIndex(0) +--- +>>> interface connectModule { +1->^^^^ +2 > ^^^^^^^^^^ +3 > ^^^^^^^^^^^^^ +4 > ^^^^^^^^^^^^^^^^^^^^-> +1->{ + > +2 > export interface +3 > connectModule +1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) +2 >Emitted(2, 15) Source(2, 22) + SourceIndex(0) +3 >Emitted(2, 28) Source(2, 35) + SourceIndex(0) +--- +>>> (res: any, req: any, next: any): void; +1->^^^^^^^^ +2 > ^ +3 > ^^^ +4 > ^^^^^ +5 > ^^ +6 > ^^^ +7 > ^^^^^ +8 > ^^ +9 > ^^^^ +10> ^^^^^ +11> ^^^ +12> ^^^^ +13> ^ +1-> { + > +2 > ( +3 > res +4 > +5 > , +6 > req +7 > +8 > , +9 > next +10> +11> ): +12> void +13> ; +1->Emitted(3, 9) Source(3, 9) + SourceIndex(0) +2 >Emitted(3, 10) Source(3, 10) + SourceIndex(0) +3 >Emitted(3, 13) Source(3, 13) + SourceIndex(0) +4 >Emitted(3, 18) Source(3, 13) + SourceIndex(0) +5 >Emitted(3, 20) Source(3, 15) + SourceIndex(0) +6 >Emitted(3, 23) Source(3, 18) + SourceIndex(0) +7 >Emitted(3, 28) Source(3, 18) + SourceIndex(0) +8 >Emitted(3, 30) Source(3, 20) + SourceIndex(0) +9 >Emitted(3, 34) Source(3, 24) + SourceIndex(0) +10>Emitted(3, 39) Source(3, 24) + SourceIndex(0) +11>Emitted(3, 42) Source(3, 27) + SourceIndex(0) +12>Emitted(3, 46) Source(3, 31) + SourceIndex(0) +13>Emitted(3, 47) Source(3, 32) + SourceIndex(0) +--- +>>> } +1 >^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > } +1 >Emitted(4, 6) Source(4, 6) + SourceIndex(0) +--- +>>> interface connectExport { +1->^^^^ +2 > ^^^^^^^^^^ +3 > ^^^^^^^^^^^^^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +2 > export interface +3 > connectExport +1->Emitted(5, 5) Source(5, 5) + SourceIndex(0) +2 >Emitted(5, 15) Source(5, 22) + SourceIndex(0) +3 >Emitted(5, 28) Source(5, 35) + SourceIndex(0) +--- +>>> use: (mod: connectModule) => connectExport; +1->^^^^^^^^ +2 > ^^^ +3 > ^^ +4 > ^ +5 > ^^^ +6 > ^^ +7 > ^^^^^^^^^^^^^ +8 > ^^^^^ +9 > ^^^^^^^^^^^^^ +10> ^ +1-> { + > +2 > use +3 > : +4 > ( +5 > mod +6 > : +7 > connectModule +8 > ) => +9 > connectExport +10> ; +1->Emitted(6, 9) Source(6, 9) + SourceIndex(0) +2 >Emitted(6, 12) Source(6, 12) + SourceIndex(0) +3 >Emitted(6, 14) Source(6, 14) + SourceIndex(0) +4 >Emitted(6, 15) Source(6, 15) + SourceIndex(0) +5 >Emitted(6, 18) Source(6, 18) + SourceIndex(0) +6 >Emitted(6, 20) Source(6, 20) + SourceIndex(0) +7 >Emitted(6, 33) Source(6, 33) + SourceIndex(0) +8 >Emitted(6, 38) Source(6, 38) + SourceIndex(0) +9 >Emitted(6, 51) Source(6, 51) + SourceIndex(0) +10>Emitted(6, 52) Source(6, 52) + SourceIndex(0) +--- +>>> listen: (port: number) => void; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^^ +4 > ^ +5 > ^^^^ +6 > ^^ +7 > ^^^^^^ +8 > ^^^^^ +9 > ^^^^ +10> ^ +1 > + > +2 > listen +3 > : +4 > ( +5 > port +6 > : +7 > number +8 > ) => +9 > void +10> ; +1 >Emitted(7, 9) Source(7, 9) + SourceIndex(0) +2 >Emitted(7, 15) Source(7, 15) + SourceIndex(0) +3 >Emitted(7, 17) Source(7, 17) + SourceIndex(0) +4 >Emitted(7, 18) Source(7, 18) + SourceIndex(0) +5 >Emitted(7, 22) Source(7, 22) + SourceIndex(0) +6 >Emitted(7, 24) Source(7, 24) + SourceIndex(0) +7 >Emitted(7, 30) Source(7, 30) + SourceIndex(0) +8 >Emitted(7, 35) Source(7, 35) + SourceIndex(0) +9 >Emitted(7, 39) Source(7, 39) + SourceIndex(0) +10>Emitted(7, 40) Source(7, 40) + SourceIndex(0) +--- +>>> } +1 >^^^^^ +1 > + > } +1 >Emitted(8, 6) Source(8, 6) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^-> +1 > + > + >} +1 >Emitted(9, 2) Source(10, 2) + SourceIndex(0) +--- +>>>declare var m2: { +1-> +2 >^^^^^^^^ +3 > ^^^^ +4 > ^^ +5 > ^^ +6 > ^^^^^^^^^^-> +1-> + > + > +2 > +3 > var +4 > m2 +5 > : +1->Emitted(10, 1) Source(12, 1) + SourceIndex(0) +2 >Emitted(10, 9) Source(12, 1) + SourceIndex(0) +3 >Emitted(10, 13) Source(12, 5) + SourceIndex(0) +4 >Emitted(10, 15) Source(12, 7) + SourceIndex(0) +5 >Emitted(10, 17) Source(12, 9) + SourceIndex(0) +--- +>>> (): m2.connectExport; +1->^^^^ +2 > ^^^^ +3 > ^^ +4 > ^ +5 > ^^^^^^^^^^^^^ +6 > ^ +7 > ^^^^-> +1->{ + > +2 > (): +3 > m2 +4 > . +5 > connectExport +6 > ; +1->Emitted(11, 5) Source(13, 5) + SourceIndex(0) +2 >Emitted(11, 9) Source(13, 9) + SourceIndex(0) +3 >Emitted(11, 11) Source(13, 11) + SourceIndex(0) +4 >Emitted(11, 12) Source(13, 12) + SourceIndex(0) +5 >Emitted(11, 25) Source(13, 25) + SourceIndex(0) +6 >Emitted(11, 26) Source(13, 26) + SourceIndex(0) +--- +>>> test1: m2.connectModule; +1->^^^^ +2 > ^^^^^ +3 > ^^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^^^ +7 > ^ +8 > ^^^-> +1-> + > +2 > test1 +3 > : +4 > m2 +5 > . +6 > connectModule +7 > ; +1->Emitted(12, 5) Source(14, 5) + SourceIndex(0) +2 >Emitted(12, 10) Source(14, 10) + SourceIndex(0) +3 >Emitted(12, 12) Source(14, 12) + SourceIndex(0) +4 >Emitted(12, 14) Source(14, 14) + SourceIndex(0) +5 >Emitted(12, 15) Source(14, 15) + SourceIndex(0) +6 >Emitted(12, 28) Source(14, 28) + SourceIndex(0) +7 >Emitted(12, 29) Source(14, 29) + SourceIndex(0) +--- +>>> test2(): m2.connectModule; +1->^^^^ +2 > ^^^^^ +3 > ^^^^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^^^ +7 > ^ +1-> + > +2 > test2 +3 > (): +4 > m2 +5 > . +6 > connectModule +7 > ; +1->Emitted(13, 5) Source(15, 5) + SourceIndex(0) +2 >Emitted(13, 10) Source(15, 10) + SourceIndex(0) +3 >Emitted(13, 14) Source(15, 14) + SourceIndex(0) +4 >Emitted(13, 16) Source(15, 16) + SourceIndex(0) +5 >Emitted(13, 17) Source(15, 17) + SourceIndex(0) +6 >Emitted(13, 30) Source(15, 30) + SourceIndex(0) +7 >Emitted(13, 31) Source(15, 31) + SourceIndex(0) +--- +>>>}; +1 >^ +2 > ^ +3 > ^^^^^^^^^^^-> +1 > + >} +2 > ; +1 >Emitted(14, 2) Source(16, 2) + SourceIndex(0) +2 >Emitted(14, 3) Source(16, 3) + SourceIndex(0) +--- +>>>export = m2; +1-> +2 >^^^^^^^^^ +3 > ^^ +4 > ^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + > + > +2 >export = +3 > m2 +4 > ; +1->Emitted(15, 1) Source(18, 1) + SourceIndex(0) +2 >Emitted(15, 10) Source(18, 10) + SourceIndex(0) +3 >Emitted(15, 12) Source(18, 12) + SourceIndex(0) +4 >Emitted(15, 13) Source(18, 13) + SourceIndex(0) +--- +>>>//# sourceMappingURL=declarationMaps.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMaps.symbols b/tests/baselines/reference/declarationMaps.symbols new file mode 100644 index 0000000000000..b7fb7a5555a4d --- /dev/null +++ b/tests/baselines/reference/declarationMaps.symbols @@ -0,0 +1,50 @@ +=== tests/cases/compiler/declarationMaps.ts === +module m2 { +>m2 : Symbol(m2, Decl(declarationMaps.ts, 0, 0), Decl(declarationMaps.ts, 11, 3)) + + export interface connectModule { +>connectModule : Symbol(connectModule, Decl(declarationMaps.ts, 0, 11)) + + (res, req, next): void; +>res : Symbol(res, Decl(declarationMaps.ts, 2, 9)) +>req : Symbol(req, Decl(declarationMaps.ts, 2, 13)) +>next : Symbol(next, Decl(declarationMaps.ts, 2, 18)) + } + export interface connectExport { +>connectExport : Symbol(connectExport, Decl(declarationMaps.ts, 3, 5)) + + use: (mod: connectModule) => connectExport; +>use : Symbol(connectExport.use, Decl(declarationMaps.ts, 4, 36)) +>mod : Symbol(mod, Decl(declarationMaps.ts, 5, 14)) +>connectModule : Symbol(connectModule, Decl(declarationMaps.ts, 0, 11)) +>connectExport : Symbol(connectExport, Decl(declarationMaps.ts, 3, 5)) + + listen: (port: number) => void; +>listen : Symbol(connectExport.listen, Decl(declarationMaps.ts, 5, 51)) +>port : Symbol(port, Decl(declarationMaps.ts, 6, 17)) + } + +} + +var m2: { +>m2 : Symbol(m2, Decl(declarationMaps.ts, 0, 0), Decl(declarationMaps.ts, 11, 3)) + + (): m2.connectExport; +>m2 : Symbol(m2, Decl(declarationMaps.ts, 0, 0), Decl(declarationMaps.ts, 11, 3)) +>connectExport : Symbol(m2.connectExport, Decl(declarationMaps.ts, 3, 5)) + + test1: m2.connectModule; +>test1 : Symbol(test1, Decl(declarationMaps.ts, 12, 25)) +>m2 : Symbol(m2, Decl(declarationMaps.ts, 0, 0), Decl(declarationMaps.ts, 11, 3)) +>connectModule : Symbol(m2.connectModule, Decl(declarationMaps.ts, 0, 11)) + + test2(): m2.connectModule; +>test2 : Symbol(test2, Decl(declarationMaps.ts, 13, 28)) +>m2 : Symbol(m2, Decl(declarationMaps.ts, 0, 0), Decl(declarationMaps.ts, 11, 3)) +>connectModule : Symbol(m2.connectModule, Decl(declarationMaps.ts, 0, 11)) + +}; + +export = m2; +>m2 : Symbol(m2, Decl(declarationMaps.ts, 0, 0), Decl(declarationMaps.ts, 11, 3)) + diff --git a/tests/baselines/reference/declarationMaps.types b/tests/baselines/reference/declarationMaps.types new file mode 100644 index 0000000000000..e66c2364c6b3b --- /dev/null +++ b/tests/baselines/reference/declarationMaps.types @@ -0,0 +1,50 @@ +=== tests/cases/compiler/declarationMaps.ts === +module m2 { +>m2 : { (): connectExport; test1: connectModule; test2(): connectModule; } + + export interface connectModule { +>connectModule : connectModule + + (res, req, next): void; +>res : any +>req : any +>next : any + } + export interface connectExport { +>connectExport : connectExport + + use: (mod: connectModule) => connectExport; +>use : (mod: connectModule) => connectExport +>mod : connectModule +>connectModule : connectModule +>connectExport : connectExport + + listen: (port: number) => void; +>listen : (port: number) => void +>port : number + } + +} + +var m2: { +>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; } + + (): m2.connectExport; +>m2 : any +>connectExport : m2.connectExport + + test1: m2.connectModule; +>test1 : m2.connectModule +>m2 : any +>connectModule : m2.connectModule + + test2(): m2.connectModule; +>test2 : () => m2.connectModule +>m2 : any +>connectModule : m2.connectModule + +}; + +export = m2; +>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; } + diff --git a/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping.baseline b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping.baseline new file mode 100644 index 0000000000000..10cc53e95face --- /dev/null +++ b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping.baseline @@ -0,0 +1,34 @@ +EmitSkipped: false +FileName : ./dist/index.js +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.methodName = function (propName) { }; + Foo.prototype.otherMethod = function () { + if (Math.random() > 0.5) { + return { x: 42 }; + } + return { y: "yes" }; + }; + return Foo; +}()); +exports.Foo = Foo; +FileName : ./dist/index.d.ts.map +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../tests/cases/fourslash/index.ts"],"names":[],"mappings":"AAAA;IACI,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts +export declare class Foo { + member: string; + methodName(propName: SomeType): void; + otherMethod(): { + x: number; + y?: undefined; + } | { + y: string; + x?: undefined; + }; +} +export interface SomeType { + member: number; +} +//# sourceMappingURL=index.d.ts.map diff --git a/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping2.baseline b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping2.baseline new file mode 100644 index 0000000000000..484dd75768221 --- /dev/null +++ b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping2.baseline @@ -0,0 +1,35 @@ +EmitSkipped: false +FileName : ./dist/index.js.map +{"version":3,"file":"index.js","sourceRoot":"/tests/cases/fourslash/","sources":["index.ts"],"names":[],"mappings":";;AAAA;IAAA;IASA,CAAC;IAPG,wBAAU,GAAV,UAAW,QAAkB,IAAS,CAAC;IACvC,yBAAW,GAAX;QACI,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE;YACrB,OAAO,EAAC,CAAC,EAAE,EAAE,EAAC,CAAC;SAClB;QACD,OAAO,EAAC,CAAC,EAAE,KAAK,EAAC,CAAC;IACtB,CAAC;IACL,UAAC;AAAD,CAAC,AATD,IASC;AATY,kBAAG"}FileName : ./dist/index.js +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.methodName = function (propName) { }; + Foo.prototype.otherMethod = function () { + if (Math.random() > 0.5) { + return { x: 42 }; + } + return { y: "yes" }; + }; + return Foo; +}()); +exports.Foo = Foo; +//# sourceMappingURL=index.js.mapFileName : ./dist/index.d.ts.map +{"version":3,"file":"index.d.ts","sourceRoot":"/tests/cases/fourslash/","sources":["index.ts"],"names":[],"mappings":"AAAA;IACI,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts +export declare class Foo { + member: string; + methodName(propName: SomeType): void; + otherMethod(): { + x: number; + y?: undefined; + } | { + y: string; + x?: undefined; + }; +} +export interface SomeType { + member: number; +} +//# sourceMappingURL=index.d.ts.map diff --git a/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping3.baseline b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping3.baseline new file mode 100644 index 0000000000000..80860234baf0f --- /dev/null +++ b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping3.baseline @@ -0,0 +1,34 @@ +EmitSkipped: false +FileName : ./dist/index.js +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.methodName = function (propName) { }; + Foo.prototype.otherMethod = function () { + if (Math.random() > 0.5) { + return { x: 42 }; + } + return { y: "yes" }; + }; + return Foo; +}()); +exports.Foo = Foo; +FileName : ./dist/index.d.ts.map +{"version":3,"file":"index.d.ts","sourceRoot":"/tests/cases/fourslash/","sources":["index.ts"],"names":[],"mappings":"AAAA;IACI,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts +export declare class Foo { + member: string; + methodName(propName: SomeType): void; + otherMethod(): { + x: number; + y?: undefined; + } | { + y: string; + x?: undefined; + }; +} +export interface SomeType { + member: number; +} +//# sourceMappingURL=index.d.ts.map diff --git a/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping_NoInline.baseline b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping_NoInline.baseline new file mode 100644 index 0000000000000..d8d978c954f87 --- /dev/null +++ b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping_NoInline.baseline @@ -0,0 +1,34 @@ +EmitSkipped: false +FileName : ./dist/index.js +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.methodName = function (propName) { }; + Foo.prototype.otherMethod = function () { + if (Math.random() > 0.5) { + return { x: 42 }; + } + return { y: "yes" }; + }; + return Foo; +}()); +exports.Foo = Foo; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90ZXN0cy9jYXNlcy9mb3Vyc2xhc2gvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQTtJQUFBO0lBU0EsQ0FBQztJQVBHLHdCQUFVLEdBQVYsVUFBVyxRQUFrQixJQUFTLENBQUM7SUFDdkMseUJBQVcsR0FBWDtRQUNJLElBQUksSUFBSSxDQUFDLE1BQU0sRUFBRSxHQUFHLEdBQUcsRUFBRTtZQUNyQixPQUFPLEVBQUMsQ0FBQyxFQUFFLEVBQUUsRUFBQyxDQUFDO1NBQ2xCO1FBQ0QsT0FBTyxFQUFDLENBQUMsRUFBRSxLQUFLLEVBQUMsQ0FBQztJQUN0QixDQUFDO0lBQ0wsVUFBQztBQUFELENBQUMsQUFURCxJQVNDO0FBVFksa0JBQUcifQ==FileName : ./dist/index.d.ts.map +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../tests/cases/fourslash/index.ts"],"names":[],"mappings":"AAAA;IACI,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts +export declare class Foo { + member: string; + methodName(propName: SomeType): void; + otherMethod(): { + x: number; + y?: undefined; + } | { + y: string; + x?: undefined; + }; +} +export interface SomeType { + member: number; +} +//# sourceMappingURL=index.d.ts.map diff --git a/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping_NoInlineSources.baseline b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping_NoInlineSources.baseline new file mode 100644 index 0000000000000..6114662156a11 --- /dev/null +++ b/tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping_NoInlineSources.baseline @@ -0,0 +1,34 @@ +EmitSkipped: false +FileName : ./dist/index.js +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.methodName = function (propName) { }; + Foo.prototype.otherMethod = function () { + if (Math.random() > 0.5) { + return { x: 42 }; + } + return { y: "yes" }; + }; + return Foo; +}()); +exports.Foo = Foo; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90ZXN0cy9jYXNlcy9mb3Vyc2xhc2gvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQTtJQUFBO0lBU0EsQ0FBQztJQVBHLHdCQUFVLEdBQVYsVUFBVyxRQUFrQixJQUFTLENBQUM7SUFDdkMseUJBQVcsR0FBWDtRQUNJLElBQUksSUFBSSxDQUFDLE1BQU0sRUFBRSxHQUFHLEdBQUcsRUFBRTtZQUNyQixPQUFPLEVBQUMsQ0FBQyxFQUFFLEVBQUUsRUFBQyxDQUFDO1NBQ2xCO1FBQ0QsT0FBTyxFQUFDLENBQUMsRUFBRSxLQUFLLEVBQUMsQ0FBQztJQUN0QixDQUFDO0lBQ0wsVUFBQztBQUFELENBQUMsQUFURCxJQVNDO0FBVFksa0JBQUciLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgY2xhc3MgRm9vIHtcbiAgICBtZW1iZXI6IHN0cmluZztcbiAgICBtZXRob2ROYW1lKHByb3BOYW1lOiBTb21lVHlwZSk6IHZvaWQge31cbiAgICBvdGhlck1ldGhvZCgpIHtcbiAgICAgICAgaWYgKE1hdGgucmFuZG9tKCkgPiAwLjUpIHtcbiAgICAgICAgICAgIHJldHVybiB7eDogNDJ9O1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB7eTogXCJ5ZXNcIn07XG4gICAgfVxufVxuXG5leHBvcnQgaW50ZXJmYWNlIFNvbWVUeXBlIHtcbiAgICBtZW1iZXI6IG51bWJlcjtcbn0iXX0=FileName : ./dist/index.d.ts.map +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../tests/cases/fourslash/index.ts"],"names":[],"mappings":"AAAA;IACI,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"}FileName : ./dist/index.d.ts +export declare class Foo { + member: string; + methodName(propName: SomeType): void; + otherMethod(): { + x: number; + y?: undefined; + } | { + y: string; + x?: undefined; + }; +} +export interface SomeType { + member: number; +} +//# sourceMappingURL=index.d.ts.map diff --git a/tests/baselines/reference/declarationMapsMultifile.js b/tests/baselines/reference/declarationMapsMultifile.js new file mode 100644 index 0000000000000..ee86a044f9d71 --- /dev/null +++ b/tests/baselines/reference/declarationMapsMultifile.js @@ -0,0 +1,64 @@ +//// [tests/cases/compiler/declarationMapsMultifile.ts] //// + +//// [a.ts] +export class Foo { + doThing(x: {a: number}) { + return {b: x.a}; + } + static make() { + return new Foo(); + } +} +//// [index.ts] +import {Foo} from "./a"; + +const c = new Foo(); +c.doThing({a: 42}); + +export let x = c.doThing({a: 12}); +export { c, Foo }; + + +//// [a.js] +"use strict"; +exports.__esModule = true; +var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.doThing = function (x) { + return { b: x.a }; + }; + Foo.make = function () { + return new Foo(); + }; + return Foo; +}()); +exports.Foo = Foo; +//// [index.js] +"use strict"; +exports.__esModule = true; +var a_1 = require("./a"); +exports.Foo = a_1.Foo; +var c = new a_1.Foo(); +exports.c = c; +c.doThing({ a: 42 }); +exports.x = c.doThing({ a: 12 }); + + +//// [a.d.ts] +export declare class Foo { + doThing(x: { + a: number; + }): { + b: number; + }; + static make(): Foo; +} +//# sourceMappingURL=a.d.ts.map//// [index.d.ts] +import { Foo } from "./a"; +declare const c: Foo; +export declare let x: { + b: number; +}; +export { c, Foo }; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsMultifile.js.map b/tests/baselines/reference/declarationMapsMultifile.js.map new file mode 100644 index 0000000000000..6890407554a3d --- /dev/null +++ b/tests/baselines/reference/declarationMapsMultifile.js.map @@ -0,0 +1,3 @@ +//// [a.d.ts.map] +{"version":3,"file":"a.d.ts","sourceRoot":"","sources":["a.ts"],"names":[],"mappings":"AAAA;IACI,OAAO,CAAC,CAAC,EAAE;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC;;;IAGtB,MAAM,CAAC,IAAI;CAGd"}//// [index.d.ts.map] +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,CAAC,KAAY,CAAC;AAGpB,eAAO,IAAI,CAAC;;CAAqB,CAAC;AAClC,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsMultifile.sourcemap.txt b/tests/baselines/reference/declarationMapsMultifile.sourcemap.txt new file mode 100644 index 0000000000000..6d03fcbc60920 --- /dev/null +++ b/tests/baselines/reference/declarationMapsMultifile.sourcemap.txt @@ -0,0 +1,201 @@ +=================================================================== +JsFile: a.d.ts +mapUrl: a.d.ts.map +sourceRoot: +sources: a.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/a.d.ts +sourceFile:a.ts +------------------------------------------------------------------- +>>>export declare class Foo { +1 > +2 >^^^^^^^^^^^^^^^^^-> +1 > +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +--- +>>> doThing(x: { +1->^^^^ +2 > ^^^^^^^ +3 > ^ +4 > ^ +5 > ^^ +6 > ^^^^-> +1->export class Foo { + > +2 > doThing +3 > ( +4 > x +5 > : +1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) +2 >Emitted(2, 12) Source(2, 12) + SourceIndex(0) +3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) +4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) +5 >Emitted(2, 16) Source(2, 16) + SourceIndex(0) +--- +>>> a: number; +1->^^^^^^^^ +2 > ^ +3 > ^^ +4 > ^^^^^^ +5 > ^ +1->{ +2 > a +3 > : +4 > number +5 > +1->Emitted(3, 9) Source(2, 17) + SourceIndex(0) +2 >Emitted(3, 10) Source(2, 18) + SourceIndex(0) +3 >Emitted(3, 12) Source(2, 20) + SourceIndex(0) +4 >Emitted(3, 18) Source(2, 26) + SourceIndex(0) +5 >Emitted(3, 19) Source(2, 26) + SourceIndex(0) +--- +>>> }): { +1 >^^^^^ +2 > ^^^^^^^^^^^^^^-> +1 >} +1 >Emitted(4, 6) Source(2, 27) + SourceIndex(0) +--- +>>> b: number; +>>> }; +>>> static make(): Foo; +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^ +1->) { + > return {b: x.a}; + > } + > +2 > static +3 > +4 > make +1->Emitted(7, 5) Source(5, 5) + SourceIndex(0) +2 >Emitted(7, 11) Source(5, 11) + SourceIndex(0) +3 >Emitted(7, 12) Source(5, 12) + SourceIndex(0) +4 >Emitted(7, 16) Source(5, 16) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 >() { + > return new Foo(); + > } + >} +1 >Emitted(8, 2) Source(8, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=a.d.ts.map=================================================================== +JsFile: index.d.ts +mapUrl: index.d.ts.map +sourceRoot: +sources: index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/index.d.ts +sourceFile:index.ts +------------------------------------------------------------------- +>>>import { Foo } from "./a"; +1 > +2 >^^^^^^^ +3 > ^^ +4 > ^^^ +5 > ^^ +6 > ^^^^^^ +7 > ^^^^^ +8 > ^ +1 > +2 >import +3 > { +4 > Foo +5 > } +6 > from +7 > "./a" +8 > ; +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 8) Source(1, 8) + SourceIndex(0) +3 >Emitted(1, 10) Source(1, 9) + SourceIndex(0) +4 >Emitted(1, 13) Source(1, 12) + SourceIndex(0) +5 >Emitted(1, 15) Source(1, 13) + SourceIndex(0) +6 >Emitted(1, 21) Source(1, 19) + SourceIndex(0) +7 >Emitted(1, 26) Source(1, 24) + SourceIndex(0) +8 >Emitted(1, 27) Source(1, 25) + SourceIndex(0) +--- +>>>declare const c: Foo; +1 > +2 >^^^^^^^^ +3 > ^^^^^^ +4 > ^ +5 > ^^^^^ +6 > ^ +7 > ^^^-> +1 > + > + > +2 > +3 > const +4 > c +5 > = new Foo() +6 > ; +1 >Emitted(2, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(2, 9) Source(3, 1) + SourceIndex(0) +3 >Emitted(2, 15) Source(3, 7) + SourceIndex(0) +4 >Emitted(2, 16) Source(3, 8) + SourceIndex(0) +5 >Emitted(2, 21) Source(3, 20) + SourceIndex(0) +6 >Emitted(2, 22) Source(3, 21) + SourceIndex(0) +--- +>>>export declare let x: { +1-> +2 >^^^^^^^^^^^^^^^ +3 > ^^^^ +4 > ^ +1-> + >c.doThing({a: 42}); + > + > +2 >export +3 > let +4 > x +1->Emitted(3, 1) Source(6, 1) + SourceIndex(0) +2 >Emitted(3, 16) Source(6, 8) + SourceIndex(0) +3 >Emitted(3, 20) Source(6, 12) + SourceIndex(0) +4 >Emitted(3, 21) Source(6, 13) + SourceIndex(0) +--- +>>> b: number; +>>>}; +1 >^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^-> +1 > = c.doThing({a: 12}) +2 > ; +1 >Emitted(5, 2) Source(6, 34) + SourceIndex(0) +2 >Emitted(5, 3) Source(6, 35) + SourceIndex(0) +--- +>>>export { c, Foo }; +1-> +2 >^^^^^^^ +3 > ^^ +4 > ^ +5 > ^^ +6 > ^^^ +7 > ^^ +8 > ^ +9 > ^^^^^^^^^^^^^^^^-> +1-> + > +2 >export +3 > { +4 > c +5 > , +6 > Foo +7 > } +8 > ; +1->Emitted(6, 1) Source(7, 1) + SourceIndex(0) +2 >Emitted(6, 8) Source(7, 8) + SourceIndex(0) +3 >Emitted(6, 10) Source(7, 10) + SourceIndex(0) +4 >Emitted(6, 11) Source(7, 11) + SourceIndex(0) +5 >Emitted(6, 13) Source(7, 13) + SourceIndex(0) +6 >Emitted(6, 16) Source(7, 16) + SourceIndex(0) +7 >Emitted(6, 18) Source(7, 18) + SourceIndex(0) +8 >Emitted(6, 19) Source(7, 19) + SourceIndex(0) +--- +>>>//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsMultifile.symbols b/tests/baselines/reference/declarationMapsMultifile.symbols new file mode 100644 index 0000000000000..51efaafec3a5e --- /dev/null +++ b/tests/baselines/reference/declarationMapsMultifile.symbols @@ -0,0 +1,47 @@ +=== tests/cases/compiler/a.ts === +export class Foo { +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + + doThing(x: {a: number}) { +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>x : Symbol(x, Decl(a.ts, 1, 12)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + + return {b: x.a}; +>b : Symbol(b, Decl(a.ts, 2, 16)) +>x.a : Symbol(a, Decl(a.ts, 1, 16)) +>x : Symbol(x, Decl(a.ts, 1, 12)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + } + static make() { +>make : Symbol(Foo.make, Decl(a.ts, 3, 5)) + + return new Foo(); +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + } +} +=== tests/cases/compiler/index.ts === +import {Foo} from "./a"; +>Foo : Symbol(Foo, Decl(index.ts, 0, 8)) + +const c = new Foo(); +>c : Symbol(c, Decl(index.ts, 2, 5)) +>Foo : Symbol(Foo, Decl(index.ts, 0, 8)) + +c.doThing({a: 42}); +>c.doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>c : Symbol(c, Decl(index.ts, 2, 5)) +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>a : Symbol(a, Decl(index.ts, 3, 11)) + +export let x = c.doThing({a: 12}); +>x : Symbol(x, Decl(index.ts, 5, 10)) +>c.doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>c : Symbol(c, Decl(index.ts, 2, 5)) +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>a : Symbol(a, Decl(index.ts, 5, 26)) + +export { c, Foo }; +>c : Symbol(c, Decl(index.ts, 6, 8)) +>Foo : Symbol(Foo, Decl(index.ts, 6, 11)) + diff --git a/tests/baselines/reference/declarationMapsMultifile.types b/tests/baselines/reference/declarationMapsMultifile.types new file mode 100644 index 0000000000000..f77a3983a4df9 --- /dev/null +++ b/tests/baselines/reference/declarationMapsMultifile.types @@ -0,0 +1,56 @@ +=== tests/cases/compiler/a.ts === +export class Foo { +>Foo : Foo + + doThing(x: {a: number}) { +>doThing : (x: { a: number; }) => { b: number; } +>x : { a: number; } +>a : number + + return {b: x.a}; +>{b: x.a} : { b: number; } +>b : number +>x.a : number +>x : { a: number; } +>a : number + } + static make() { +>make : () => Foo + + return new Foo(); +>new Foo() : Foo +>Foo : typeof Foo + } +} +=== tests/cases/compiler/index.ts === +import {Foo} from "./a"; +>Foo : typeof Foo + +const c = new Foo(); +>c : Foo +>new Foo() : Foo +>Foo : typeof Foo + +c.doThing({a: 42}); +>c.doThing({a: 42}) : { b: number; } +>c.doThing : (x: { a: number; }) => { b: number; } +>c : Foo +>doThing : (x: { a: number; }) => { b: number; } +>{a: 42} : { a: number; } +>a : number +>42 : 42 + +export let x = c.doThing({a: 12}); +>x : { b: number; } +>c.doThing({a: 12}) : { b: number; } +>c.doThing : (x: { a: number; }) => { b: number; } +>c : Foo +>doThing : (x: { a: number; }) => { b: number; } +>{a: 12} : { a: number; } +>a : number +>12 : 12 + +export { c, Foo }; +>c : Foo +>Foo : typeof Foo + diff --git a/tests/baselines/reference/declarationMapsOutFile.js b/tests/baselines/reference/declarationMapsOutFile.js new file mode 100644 index 0000000000000..def1f470a72bc --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile.js @@ -0,0 +1,69 @@ +//// [tests/cases/compiler/declarationMapsOutFile.ts] //// + +//// [a.ts] +export class Foo { + doThing(x: {a: number}) { + return {b: x.a}; + } + static make() { + return new Foo(); + } +} +//// [index.ts] +import {Foo} from "./a"; + +const c = new Foo(); +c.doThing({a: 42}); + +export let x = c.doThing({a: 12}); +export { c, Foo }; + + +//// [bundle.js] +define("a", ["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.doThing = function (x) { + return { b: x.a }; + }; + Foo.make = function () { + return new Foo(); + }; + return Foo; + }()); + exports.Foo = Foo; +}); +define("index", ["require", "exports", "a"], function (require, exports, a_1) { + "use strict"; + exports.__esModule = true; + exports.Foo = a_1.Foo; + var c = new a_1.Foo(); + exports.c = c; + c.doThing({ a: 42 }); + exports.x = c.doThing({ a: 12 }); +}); + + +//// [bundle.d.ts] +declare module "a" { + export class Foo { + doThing(x: { + a: number; + }): { + b: number; + }; + static make(): Foo; + } +} +declare module "index" { + import { Foo } from "a"; + const c: Foo; + export let x: { + b: number; + }; + export { c, Foo }; +} +//# sourceMappingURL=bundle.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsOutFile.js.map b/tests/baselines/reference/declarationMapsOutFile.js.map new file mode 100644 index 0000000000000..051318f806401 --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile.js.map @@ -0,0 +1,2 @@ +//// [bundle.d.ts.map] +{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["tests/cases/compiler/a.ts","tests/cases/compiler/index.ts"],"names":[],"mappings":";IAAA,MAAM;QACF,OAAO,CAAC,CAAC,EAAE;YAAC,CAAC,EAAE,MAAM,CAAA;SAAC;;;QAGtB,MAAM,CAAC,IAAI;KAGd;;;ICPD,OAAO,EAAC,GAAG,EAAC,UAAY;IAExB,MAAM,CAAC,KAAY,CAAC;IAGpB,MAAM,CAAC,IAAI,CAAC;;KAAqB,CAAC;IAClC,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsOutFile.sourcemap.txt b/tests/baselines/reference/declarationMapsOutFile.sourcemap.txt new file mode 100644 index 0000000000000..39d83719b20f3 --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile.sourcemap.txt @@ -0,0 +1,195 @@ +=================================================================== +JsFile: bundle.d.ts +mapUrl: bundle.d.ts.map +sourceRoot: +sources: tests/cases/compiler/a.ts,tests/cases/compiler/index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:bundle.d.ts +sourceFile:tests/cases/compiler/a.ts +------------------------------------------------------------------- +>>>declare module "a" { +>>> export class Foo { +1 >^^^^ +2 > ^^^^^^ +3 > ^^^^^^^^^^^-> +1 > +2 > export +1 >Emitted(2, 5) Source(1, 1) + SourceIndex(0) +2 >Emitted(2, 11) Source(1, 7) + SourceIndex(0) +--- +>>> doThing(x: { +1->^^^^^^^^ +2 > ^^^^^^^ +3 > ^ +4 > ^ +5 > ^^ +6 > ^^^^-> +1-> class Foo { + > +2 > doThing +3 > ( +4 > x +5 > : +1->Emitted(3, 9) Source(2, 5) + SourceIndex(0) +2 >Emitted(3, 16) Source(2, 12) + SourceIndex(0) +3 >Emitted(3, 17) Source(2, 13) + SourceIndex(0) +4 >Emitted(3, 18) Source(2, 14) + SourceIndex(0) +5 >Emitted(3, 20) Source(2, 16) + SourceIndex(0) +--- +>>> a: number; +1->^^^^^^^^^^^^ +2 > ^ +3 > ^^ +4 > ^^^^^^ +5 > ^ +1->{ +2 > a +3 > : +4 > number +5 > +1->Emitted(4, 13) Source(2, 17) + SourceIndex(0) +2 >Emitted(4, 14) Source(2, 18) + SourceIndex(0) +3 >Emitted(4, 16) Source(2, 20) + SourceIndex(0) +4 >Emitted(4, 22) Source(2, 26) + SourceIndex(0) +5 >Emitted(4, 23) Source(2, 26) + SourceIndex(0) +--- +>>> }): { +1 >^^^^^^^^^ +2 > ^^^^^^^^^^^^^^-> +1 >} +1 >Emitted(5, 10) Source(2, 27) + SourceIndex(0) +--- +>>> b: number; +>>> }; +>>> static make(): Foo; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^ +1->) { + > return {b: x.a}; + > } + > +2 > static +3 > +4 > make +1->Emitted(8, 9) Source(5, 5) + SourceIndex(0) +2 >Emitted(8, 15) Source(5, 11) + SourceIndex(0) +3 >Emitted(8, 16) Source(5, 12) + SourceIndex(0) +4 >Emitted(8, 20) Source(5, 16) + SourceIndex(0) +--- +>>> } +1 >^^^^^ +1 >() { + > return new Foo(); + > } + >} +1 >Emitted(9, 6) Source(8, 2) + SourceIndex(0) +--- +------------------------------------------------------------------- +emittedFile:bundle.d.ts +sourceFile:tests/cases/compiler/index.ts +------------------------------------------------------------------- +>>>} +>>>declare module "index" { +>>> import { Foo } from "a"; +1 >^^^^ +2 > ^^^^^^^ +3 > ^^ +4 > ^^^ +5 > ^^ +6 > ^^^^^^^^^^ +1 > +2 > import +3 > { +4 > Foo +5 > } +6 > from "./a"; +1 >Emitted(12, 5) Source(1, 1) + SourceIndex(1) +2 >Emitted(12, 12) Source(1, 8) + SourceIndex(1) +3 >Emitted(12, 14) Source(1, 9) + SourceIndex(1) +4 >Emitted(12, 17) Source(1, 12) + SourceIndex(1) +5 >Emitted(12, 19) Source(1, 13) + SourceIndex(1) +6 >Emitted(12, 29) Source(1, 25) + SourceIndex(1) +--- +>>> const c: Foo; +1 >^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^^ +5 > ^ +6 > ^^^-> +1 > + > + > +2 > const +3 > c +4 > = new Foo() +5 > ; +1 >Emitted(13, 5) Source(3, 1) + SourceIndex(1) +2 >Emitted(13, 11) Source(3, 7) + SourceIndex(1) +3 >Emitted(13, 12) Source(3, 8) + SourceIndex(1) +4 >Emitted(13, 17) Source(3, 20) + SourceIndex(1) +5 >Emitted(13, 18) Source(3, 21) + SourceIndex(1) +--- +>>> export let x: { +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^ +5 > ^ +6 > ^^^-> +1-> + >c.doThing({a: 42}); + > + > +2 > export +3 > +4 > let +5 > x +1->Emitted(14, 5) Source(6, 1) + SourceIndex(1) +2 >Emitted(14, 11) Source(6, 7) + SourceIndex(1) +3 >Emitted(14, 12) Source(6, 8) + SourceIndex(1) +4 >Emitted(14, 16) Source(6, 12) + SourceIndex(1) +5 >Emitted(14, 17) Source(6, 13) + SourceIndex(1) +--- +>>> b: number; +>>> }; +1->^^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^-> +1-> = c.doThing({a: 12}) +2 > ; +1->Emitted(16, 6) Source(6, 34) + SourceIndex(1) +2 >Emitted(16, 7) Source(6, 35) + SourceIndex(1) +--- +>>> export { c, Foo }; +1->^^^^ +2 > ^^^^^^^ +3 > ^^ +4 > ^ +5 > ^^ +6 > ^^^ +7 > ^^ +8 > ^ +1-> + > +2 > export +3 > { +4 > c +5 > , +6 > Foo +7 > } +8 > ; +1->Emitted(17, 5) Source(7, 1) + SourceIndex(1) +2 >Emitted(17, 12) Source(7, 8) + SourceIndex(1) +3 >Emitted(17, 14) Source(7, 10) + SourceIndex(1) +4 >Emitted(17, 15) Source(7, 11) + SourceIndex(1) +5 >Emitted(17, 17) Source(7, 13) + SourceIndex(1) +6 >Emitted(17, 20) Source(7, 16) + SourceIndex(1) +7 >Emitted(17, 22) Source(7, 18) + SourceIndex(1) +8 >Emitted(17, 23) Source(7, 19) + SourceIndex(1) +--- +>>>} +>>>//# sourceMappingURL=bundle.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsOutFile.symbols b/tests/baselines/reference/declarationMapsOutFile.symbols new file mode 100644 index 0000000000000..51efaafec3a5e --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile.symbols @@ -0,0 +1,47 @@ +=== tests/cases/compiler/a.ts === +export class Foo { +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + + doThing(x: {a: number}) { +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>x : Symbol(x, Decl(a.ts, 1, 12)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + + return {b: x.a}; +>b : Symbol(b, Decl(a.ts, 2, 16)) +>x.a : Symbol(a, Decl(a.ts, 1, 16)) +>x : Symbol(x, Decl(a.ts, 1, 12)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + } + static make() { +>make : Symbol(Foo.make, Decl(a.ts, 3, 5)) + + return new Foo(); +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + } +} +=== tests/cases/compiler/index.ts === +import {Foo} from "./a"; +>Foo : Symbol(Foo, Decl(index.ts, 0, 8)) + +const c = new Foo(); +>c : Symbol(c, Decl(index.ts, 2, 5)) +>Foo : Symbol(Foo, Decl(index.ts, 0, 8)) + +c.doThing({a: 42}); +>c.doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>c : Symbol(c, Decl(index.ts, 2, 5)) +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>a : Symbol(a, Decl(index.ts, 3, 11)) + +export let x = c.doThing({a: 12}); +>x : Symbol(x, Decl(index.ts, 5, 10)) +>c.doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>c : Symbol(c, Decl(index.ts, 2, 5)) +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 18)) +>a : Symbol(a, Decl(index.ts, 5, 26)) + +export { c, Foo }; +>c : Symbol(c, Decl(index.ts, 6, 8)) +>Foo : Symbol(Foo, Decl(index.ts, 6, 11)) + diff --git a/tests/baselines/reference/declarationMapsOutFile.types b/tests/baselines/reference/declarationMapsOutFile.types new file mode 100644 index 0000000000000..f77a3983a4df9 --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile.types @@ -0,0 +1,56 @@ +=== tests/cases/compiler/a.ts === +export class Foo { +>Foo : Foo + + doThing(x: {a: number}) { +>doThing : (x: { a: number; }) => { b: number; } +>x : { a: number; } +>a : number + + return {b: x.a}; +>{b: x.a} : { b: number; } +>b : number +>x.a : number +>x : { a: number; } +>a : number + } + static make() { +>make : () => Foo + + return new Foo(); +>new Foo() : Foo +>Foo : typeof Foo + } +} +=== tests/cases/compiler/index.ts === +import {Foo} from "./a"; +>Foo : typeof Foo + +const c = new Foo(); +>c : Foo +>new Foo() : Foo +>Foo : typeof Foo + +c.doThing({a: 42}); +>c.doThing({a: 42}) : { b: number; } +>c.doThing : (x: { a: number; }) => { b: number; } +>c : Foo +>doThing : (x: { a: number; }) => { b: number; } +>{a: 42} : { a: number; } +>a : number +>42 : 42 + +export let x = c.doThing({a: 12}); +>x : { b: number; } +>c.doThing({a: 12}) : { b: number; } +>c.doThing : (x: { a: number; }) => { b: number; } +>c : Foo +>doThing : (x: { a: number; }) => { b: number; } +>{a: 12} : { a: number; } +>a : number +>12 : 12 + +export { c, Foo }; +>c : Foo +>Foo : typeof Foo + diff --git a/tests/baselines/reference/declarationMapsOutFile2.js b/tests/baselines/reference/declarationMapsOutFile2.js new file mode 100644 index 0000000000000..42bb8db558672 --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile2.js @@ -0,0 +1,49 @@ +//// [tests/cases/compiler/declarationMapsOutFile2.ts] //// + +//// [a.ts] +class Foo { + doThing(x: {a: number}) { + return {b: x.a}; + } + static make() { + return new Foo(); + } +} +//// [index.ts] +const c = new Foo(); +c.doThing({a: 42}); + +let x = c.doThing({a: 12}); + + +//// [bundle.js] +var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.doThing = function (x) { + return { b: x.a }; + }; + Foo.make = function () { + return new Foo(); + }; + return Foo; +}()); +var c = new Foo(); +c.doThing({ a: 42 }); +var x = c.doThing({ a: 12 }); + + +//// [bundle.d.ts] +declare class Foo { + doThing(x: { + a: number; + }): { + b: number; + }; + static make(): Foo; +} +declare const c: Foo; +declare let x: { + b: number; +}; +//# sourceMappingURL=bundle.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsOutFile2.js.map b/tests/baselines/reference/declarationMapsOutFile2.js.map new file mode 100644 index 0000000000000..22845f90fb202 --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile2.js.map @@ -0,0 +1,2 @@ +//// [bundle.d.ts.map] +{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["tests/cases/compiler/a.ts","tests/cases/compiler/index.ts"],"names":[],"mappings":"AAAA;IACI,OAAO,CAAC,CAAC,EAAE;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC;;;IAGtB,MAAM,CAAC,IAAI;CAGd;ACPD,QAAA,MAAM,CAAC,KAAY,CAAC;AAGpB,QAAA,IAAI,CAAC;;CAAqB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsOutFile2.sourcemap.txt b/tests/baselines/reference/declarationMapsOutFile2.sourcemap.txt new file mode 100644 index 0000000000000..d7a829917e653 --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile2.sourcemap.txt @@ -0,0 +1,139 @@ +=================================================================== +JsFile: bundle.d.ts +mapUrl: bundle.d.ts.map +sourceRoot: +sources: tests/cases/compiler/a.ts,tests/cases/compiler/index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:bundle.d.ts +sourceFile:tests/cases/compiler/a.ts +------------------------------------------------------------------- +>>>declare class Foo { +1 > +2 >^^^^^^^^^^^^^^^^^-> +1 > +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +--- +>>> doThing(x: { +1->^^^^ +2 > ^^^^^^^ +3 > ^ +4 > ^ +5 > ^^ +6 > ^^^^-> +1->class Foo { + > +2 > doThing +3 > ( +4 > x +5 > : +1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) +2 >Emitted(2, 12) Source(2, 12) + SourceIndex(0) +3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) +4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) +5 >Emitted(2, 16) Source(2, 16) + SourceIndex(0) +--- +>>> a: number; +1->^^^^^^^^ +2 > ^ +3 > ^^ +4 > ^^^^^^ +5 > ^ +1->{ +2 > a +3 > : +4 > number +5 > +1->Emitted(3, 9) Source(2, 17) + SourceIndex(0) +2 >Emitted(3, 10) Source(2, 18) + SourceIndex(0) +3 >Emitted(3, 12) Source(2, 20) + SourceIndex(0) +4 >Emitted(3, 18) Source(2, 26) + SourceIndex(0) +5 >Emitted(3, 19) Source(2, 26) + SourceIndex(0) +--- +>>> }): { +1 >^^^^^ +2 > ^^^^^^^^^^^^^^-> +1 >} +1 >Emitted(4, 6) Source(2, 27) + SourceIndex(0) +--- +>>> b: number; +>>> }; +>>> static make(): Foo; +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^ +1->) { + > return {b: x.a}; + > } + > +2 > static +3 > +4 > make +1->Emitted(7, 5) Source(5, 5) + SourceIndex(0) +2 >Emitted(7, 11) Source(5, 11) + SourceIndex(0) +3 >Emitted(7, 12) Source(5, 12) + SourceIndex(0) +4 >Emitted(7, 16) Source(5, 16) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^-> +1 >() { + > return new Foo(); + > } + >} +1 >Emitted(8, 2) Source(8, 2) + SourceIndex(0) +--- +------------------------------------------------------------------- +emittedFile:bundle.d.ts +sourceFile:tests/cases/compiler/index.ts +------------------------------------------------------------------- +>>>declare const c: Foo; +1-> +2 >^^^^^^^^ +3 > ^^^^^^ +4 > ^ +5 > ^^^^^ +6 > ^ +1-> +2 > +3 > const +4 > c +5 > = new Foo() +6 > ; +1->Emitted(9, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(9, 9) Source(1, 1) + SourceIndex(1) +3 >Emitted(9, 15) Source(1, 7) + SourceIndex(1) +4 >Emitted(9, 16) Source(1, 8) + SourceIndex(1) +5 >Emitted(9, 21) Source(1, 20) + SourceIndex(1) +6 >Emitted(9, 22) Source(1, 21) + SourceIndex(1) +--- +>>>declare let x: { +1 > +2 >^^^^^^^^ +3 > ^^^^ +4 > ^ +5 > ^^-> +1 > + >c.doThing({a: 42}); + > + > +2 > +3 > let +4 > x +1 >Emitted(10, 1) Source(4, 1) + SourceIndex(1) +2 >Emitted(10, 9) Source(4, 1) + SourceIndex(1) +3 >Emitted(10, 13) Source(4, 5) + SourceIndex(1) +4 >Emitted(10, 14) Source(4, 6) + SourceIndex(1) +--- +>>> b: number; +>>>}; +1->^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> = c.doThing({a: 12}) +2 > ; +1->Emitted(12, 2) Source(4, 27) + SourceIndex(1) +2 >Emitted(12, 3) Source(4, 28) + SourceIndex(1) +--- +>>>//# sourceMappingURL=bundle.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsOutFile2.symbols b/tests/baselines/reference/declarationMapsOutFile2.symbols new file mode 100644 index 0000000000000..7ae52d3824513 --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile2.symbols @@ -0,0 +1,40 @@ +=== tests/cases/compiler/a.ts === +class Foo { +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + + doThing(x: {a: number}) { +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>x : Symbol(x, Decl(a.ts, 1, 12)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + + return {b: x.a}; +>b : Symbol(b, Decl(a.ts, 2, 16)) +>x.a : Symbol(a, Decl(a.ts, 1, 16)) +>x : Symbol(x, Decl(a.ts, 1, 12)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + } + static make() { +>make : Symbol(Foo.make, Decl(a.ts, 3, 5)) + + return new Foo(); +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + } +} +=== tests/cases/compiler/index.ts === +const c = new Foo(); +>c : Symbol(c, Decl(index.ts, 0, 5)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +c.doThing({a: 42}); +>c.doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>c : Symbol(c, Decl(index.ts, 0, 5)) +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>a : Symbol(a, Decl(index.ts, 1, 11)) + +let x = c.doThing({a: 12}); +>x : Symbol(x, Decl(index.ts, 3, 3)) +>c.doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>c : Symbol(c, Decl(index.ts, 0, 5)) +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>a : Symbol(a, Decl(index.ts, 3, 19)) + diff --git a/tests/baselines/reference/declarationMapsOutFile2.types b/tests/baselines/reference/declarationMapsOutFile2.types new file mode 100644 index 0000000000000..c4fc42619950d --- /dev/null +++ b/tests/baselines/reference/declarationMapsOutFile2.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/a.ts === +class Foo { +>Foo : Foo + + doThing(x: {a: number}) { +>doThing : (x: { a: number; }) => { b: number; } +>x : { a: number; } +>a : number + + return {b: x.a}; +>{b: x.a} : { b: number; } +>b : number +>x.a : number +>x : { a: number; } +>a : number + } + static make() { +>make : () => Foo + + return new Foo(); +>new Foo() : Foo +>Foo : typeof Foo + } +} +=== tests/cases/compiler/index.ts === +const c = new Foo(); +>c : Foo +>new Foo() : Foo +>Foo : typeof Foo + +c.doThing({a: 42}); +>c.doThing({a: 42}) : { b: number; } +>c.doThing : (x: { a: number; }) => { b: number; } +>c : Foo +>doThing : (x: { a: number; }) => { b: number; } +>{a: 42} : { a: number; } +>a : number +>42 : 42 + +let x = c.doThing({a: 12}); +>x : { b: number; } +>c.doThing({a: 12}) : { b: number; } +>c.doThing : (x: { a: number; }) => { b: number; } +>c : Foo +>doThing : (x: { a: number; }) => { b: number; } +>{a: 12} : { a: number; } +>a : number +>12 : 12 + diff --git a/tests/baselines/reference/declarationMapsWithSourceMap.js b/tests/baselines/reference/declarationMapsWithSourceMap.js new file mode 100644 index 0000000000000..38cbb61a10e85 --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithSourceMap.js @@ -0,0 +1,49 @@ +//// [tests/cases/compiler/declarationMapsWithSourceMap.ts] //// + +//// [a.ts] +class Foo { + doThing(x: {a: number}) { + return {b: x.a}; + } + static make() { + return new Foo(); + } +} +//// [index.ts] +const c = new Foo(); +c.doThing({a: 42}); + +let x = c.doThing({a: 12}); + + +//// [bundle.js] +var Foo = /** @class */ (function () { + function Foo() { + } + Foo.prototype.doThing = function (x) { + return { b: x.a }; + }; + Foo.make = function () { + return new Foo(); + }; + return Foo; +}()); +var c = new Foo(); +c.doThing({ a: 42 }); +var x = c.doThing({ a: 12 }); +//# sourceMappingURL=bundle.js.map + +//// [bundle.d.ts] +declare class Foo { + doThing(x: { + a: number; + }): { + b: number; + }; + static make(): Foo; +} +declare const c: Foo; +declare let x: { + b: number; +}; +//# sourceMappingURL=bundle.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsWithSourceMap.js.map b/tests/baselines/reference/declarationMapsWithSourceMap.js.map new file mode 100644 index 0000000000000..17ef6a6004ccc --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithSourceMap.js.map @@ -0,0 +1,3 @@ +//// [bundle.js.map] +{"version":3,"file":"bundle.js","sourceRoot":"","sources":["tests/cases/compiler/a.ts","tests/cases/compiler/index.ts"],"names":[],"mappings":"AAAA;IAAA;IAOA,CAAC;IANG,qBAAO,GAAP,UAAQ,CAAc;QAClB,OAAO,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAC,CAAC;IACpB,CAAC;IACM,QAAI,GAAX;QACI,OAAO,IAAI,GAAG,EAAE,CAAC;IACrB,CAAC;IACL,UAAC;AAAD,CAAC,AAPD,IAOC;ACPD,IAAM,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;AACpB,CAAC,CAAC,OAAO,CAAC,EAAC,CAAC,EAAE,EAAE,EAAC,CAAC,CAAC;AAEnB,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAC,CAAC,EAAE,EAAE,EAAC,CAAC,CAAC"}//// [bundle.d.ts.map] +{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["tests/cases/compiler/a.ts","tests/cases/compiler/index.ts"],"names":[],"mappings":"AAAA;IACI,OAAO,CAAC,CAAC,EAAE;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC;;;IAGtB,MAAM,CAAC,IAAI;CAGd;ACPD,QAAA,MAAM,CAAC,KAAY,CAAC;AAGpB,QAAA,IAAI,CAAC;;CAAqB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsWithSourceMap.sourcemap.txt b/tests/baselines/reference/declarationMapsWithSourceMap.sourcemap.txt new file mode 100644 index 0000000000000..0f9df308ef6cb --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithSourceMap.sourcemap.txt @@ -0,0 +1,433 @@ +=================================================================== +JsFile: bundle.js +mapUrl: bundle.js.map +sourceRoot: +sources: tests/cases/compiler/a.ts,tests/cases/compiler/index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:bundle.js +sourceFile:tests/cases/compiler/a.ts +------------------------------------------------------------------- +>>>var Foo = /** @class */ (function () { +1 > +2 >^^^^^^^^^^^^^^^^^^^^^-> +1 > +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +--- +>>> function Foo() { +1->^^^^ +2 > ^^-> +1-> +1->Emitted(2, 5) Source(1, 1) + SourceIndex(0) +--- +>>> } +1->^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->class Foo { + > doThing(x: {a: number}) { + > return {b: x.a}; + > } + > static make() { + > return new Foo(); + > } + > +2 > } +1->Emitted(3, 5) Source(8, 1) + SourceIndex(0) +2 >Emitted(3, 6) Source(8, 2) + SourceIndex(0) +--- +>>> Foo.prototype.doThing = function (x) { +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^ +4 > ^^^^^^^^^^ +5 > ^ +1-> +2 > doThing +3 > +4 > doThing( +5 > x: {a: number} +1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) +2 >Emitted(4, 26) Source(2, 12) + SourceIndex(0) +3 >Emitted(4, 29) Source(2, 5) + SourceIndex(0) +4 >Emitted(4, 39) Source(2, 13) + SourceIndex(0) +5 >Emitted(4, 40) Source(2, 27) + SourceIndex(0) +--- +>>> return { b: x.a }; +1 >^^^^^^^^ +2 > ^^^^^^^ +3 > ^^ +4 > ^ +5 > ^^ +6 > ^ +7 > ^ +8 > ^ +9 > ^^ +10> ^ +1 >) { + > +2 > return +3 > { +4 > b +5 > : +6 > x +7 > . +8 > a +9 > } +10> ; +1 >Emitted(5, 9) Source(3, 9) + SourceIndex(0) +2 >Emitted(5, 16) Source(3, 16) + SourceIndex(0) +3 >Emitted(5, 18) Source(3, 17) + SourceIndex(0) +4 >Emitted(5, 19) Source(3, 18) + SourceIndex(0) +5 >Emitted(5, 21) Source(3, 20) + SourceIndex(0) +6 >Emitted(5, 22) Source(3, 21) + SourceIndex(0) +7 >Emitted(5, 23) Source(3, 22) + SourceIndex(0) +8 >Emitted(5, 24) Source(3, 23) + SourceIndex(0) +9 >Emitted(5, 26) Source(3, 24) + SourceIndex(0) +10>Emitted(5, 27) Source(3, 25) + SourceIndex(0) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(4, 5) + SourceIndex(0) +2 >Emitted(6, 6) Source(4, 6) + SourceIndex(0) +--- +>>> Foo.make = function () { +1->^^^^ +2 > ^^^^^^^^ +3 > ^^^ +4 > ^^^^^^^^^^^-> +1-> + > static +2 > make +3 > +1->Emitted(7, 5) Source(5, 12) + SourceIndex(0) +2 >Emitted(7, 13) Source(5, 16) + SourceIndex(0) +3 >Emitted(7, 16) Source(5, 5) + SourceIndex(0) +--- +>>> return new Foo(); +1->^^^^^^^^ +2 > ^^^^^^^ +3 > ^^^^ +4 > ^^^ +5 > ^^ +6 > ^ +1->static make() { + > +2 > return +3 > new +4 > Foo +5 > () +6 > ; +1->Emitted(8, 9) Source(6, 9) + SourceIndex(0) +2 >Emitted(8, 16) Source(6, 16) + SourceIndex(0) +3 >Emitted(8, 20) Source(6, 20) + SourceIndex(0) +4 >Emitted(8, 23) Source(6, 23) + SourceIndex(0) +5 >Emitted(8, 25) Source(6, 25) + SourceIndex(0) +6 >Emitted(8, 26) Source(6, 26) + SourceIndex(0) +--- +>>> }; +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(9, 5) Source(7, 5) + SourceIndex(0) +2 >Emitted(9, 6) Source(7, 6) + SourceIndex(0) +--- +>>> return Foo; +1->^^^^ +2 > ^^^^^^^^^^ +1-> + > +2 > } +1->Emitted(10, 5) Source(8, 1) + SourceIndex(0) +2 >Emitted(10, 15) Source(8, 2) + SourceIndex(0) +--- +>>>}()); +1 > +2 >^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^-> +1 > +2 >} +3 > +4 > class Foo { + > doThing(x: {a: number}) { + > return {b: x.a}; + > } + > static make() { + > return new Foo(); + > } + > } +1 >Emitted(11, 1) Source(8, 1) + SourceIndex(0) +2 >Emitted(11, 2) Source(8, 2) + SourceIndex(0) +3 >Emitted(11, 2) Source(1, 1) + SourceIndex(0) +4 >Emitted(11, 6) Source(8, 2) + SourceIndex(0) +--- +------------------------------------------------------------------- +emittedFile:bundle.js +sourceFile:tests/cases/compiler/index.ts +------------------------------------------------------------------- +>>>var c = new Foo(); +1-> +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^^^^ +6 > ^^^ +7 > ^^ +8 > ^ +9 > ^^^^-> +1-> +2 >const +3 > c +4 > = +5 > new +6 > Foo +7 > () +8 > ; +1->Emitted(12, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(12, 5) Source(1, 7) + SourceIndex(1) +3 >Emitted(12, 6) Source(1, 8) + SourceIndex(1) +4 >Emitted(12, 9) Source(1, 11) + SourceIndex(1) +5 >Emitted(12, 13) Source(1, 15) + SourceIndex(1) +6 >Emitted(12, 16) Source(1, 18) + SourceIndex(1) +7 >Emitted(12, 18) Source(1, 20) + SourceIndex(1) +8 >Emitted(12, 19) Source(1, 21) + SourceIndex(1) +--- +>>>c.doThing({ a: 42 }); +1-> +2 >^ +3 > ^ +4 > ^^^^^^^ +5 > ^ +6 > ^^ +7 > ^ +8 > ^^ +9 > ^^ +10> ^^ +11> ^ +12> ^ +13> ^^^^^^^^^-> +1-> + > +2 >c +3 > . +4 > doThing +5 > ( +6 > { +7 > a +8 > : +9 > 42 +10> } +11> ) +12> ; +1->Emitted(13, 1) Source(2, 1) + SourceIndex(1) +2 >Emitted(13, 2) Source(2, 2) + SourceIndex(1) +3 >Emitted(13, 3) Source(2, 3) + SourceIndex(1) +4 >Emitted(13, 10) Source(2, 10) + SourceIndex(1) +5 >Emitted(13, 11) Source(2, 11) + SourceIndex(1) +6 >Emitted(13, 13) Source(2, 12) + SourceIndex(1) +7 >Emitted(13, 14) Source(2, 13) + SourceIndex(1) +8 >Emitted(13, 16) Source(2, 15) + SourceIndex(1) +9 >Emitted(13, 18) Source(2, 17) + SourceIndex(1) +10>Emitted(13, 20) Source(2, 18) + SourceIndex(1) +11>Emitted(13, 21) Source(2, 19) + SourceIndex(1) +12>Emitted(13, 22) Source(2, 20) + SourceIndex(1) +--- +>>>var x = c.doThing({ a: 12 }); +1-> +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^^ +8 > ^ +9 > ^^ +10> ^ +11> ^^ +12> ^^ +13> ^^ +14> ^ +15> ^ +16> ^^^^-> +1-> + > + > +2 >let +3 > x +4 > = +5 > c +6 > . +7 > doThing +8 > ( +9 > { +10> a +11> : +12> 12 +13> } +14> ) +15> ; +1->Emitted(14, 1) Source(4, 1) + SourceIndex(1) +2 >Emitted(14, 5) Source(4, 5) + SourceIndex(1) +3 >Emitted(14, 6) Source(4, 6) + SourceIndex(1) +4 >Emitted(14, 9) Source(4, 9) + SourceIndex(1) +5 >Emitted(14, 10) Source(4, 10) + SourceIndex(1) +6 >Emitted(14, 11) Source(4, 11) + SourceIndex(1) +7 >Emitted(14, 18) Source(4, 18) + SourceIndex(1) +8 >Emitted(14, 19) Source(4, 19) + SourceIndex(1) +9 >Emitted(14, 21) Source(4, 20) + SourceIndex(1) +10>Emitted(14, 22) Source(4, 21) + SourceIndex(1) +11>Emitted(14, 24) Source(4, 23) + SourceIndex(1) +12>Emitted(14, 26) Source(4, 25) + SourceIndex(1) +13>Emitted(14, 28) Source(4, 26) + SourceIndex(1) +14>Emitted(14, 29) Source(4, 27) + SourceIndex(1) +15>Emitted(14, 30) Source(4, 28) + SourceIndex(1) +--- +>>>//# sourceMappingURL=bundle.js.map=================================================================== +JsFile: bundle.d.ts +mapUrl: bundle.d.ts.map +sourceRoot: +sources: tests/cases/compiler/a.ts,tests/cases/compiler/index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:bundle.d.ts +sourceFile:tests/cases/compiler/a.ts +------------------------------------------------------------------- +>>>declare class Foo { +1 > +2 >^^^^^^^^^^^^^^^^^-> +1 > +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +--- +>>> doThing(x: { +1->^^^^ +2 > ^^^^^^^ +3 > ^ +4 > ^ +5 > ^^ +6 > ^^^^-> +1->class Foo { + > +2 > doThing +3 > ( +4 > x +5 > : +1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) +2 >Emitted(2, 12) Source(2, 12) + SourceIndex(0) +3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) +4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) +5 >Emitted(2, 16) Source(2, 16) + SourceIndex(0) +--- +>>> a: number; +1->^^^^^^^^ +2 > ^ +3 > ^^ +4 > ^^^^^^ +5 > ^ +1->{ +2 > a +3 > : +4 > number +5 > +1->Emitted(3, 9) Source(2, 17) + SourceIndex(0) +2 >Emitted(3, 10) Source(2, 18) + SourceIndex(0) +3 >Emitted(3, 12) Source(2, 20) + SourceIndex(0) +4 >Emitted(3, 18) Source(2, 26) + SourceIndex(0) +5 >Emitted(3, 19) Source(2, 26) + SourceIndex(0) +--- +>>> }): { +1 >^^^^^ +2 > ^^^^^^^^^^^^^^-> +1 >} +1 >Emitted(4, 6) Source(2, 27) + SourceIndex(0) +--- +>>> b: number; +>>> }; +>>> static make(): Foo; +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^ +1->) { + > return {b: x.a}; + > } + > +2 > static +3 > +4 > make +1->Emitted(7, 5) Source(5, 5) + SourceIndex(0) +2 >Emitted(7, 11) Source(5, 11) + SourceIndex(0) +3 >Emitted(7, 12) Source(5, 12) + SourceIndex(0) +4 >Emitted(7, 16) Source(5, 16) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^-> +1 >() { + > return new Foo(); + > } + >} +1 >Emitted(8, 2) Source(8, 2) + SourceIndex(0) +--- +------------------------------------------------------------------- +emittedFile:bundle.d.ts +sourceFile:tests/cases/compiler/index.ts +------------------------------------------------------------------- +>>>declare const c: Foo; +1-> +2 >^^^^^^^^ +3 > ^^^^^^ +4 > ^ +5 > ^^^^^ +6 > ^ +1-> +2 > +3 > const +4 > c +5 > = new Foo() +6 > ; +1->Emitted(9, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(9, 9) Source(1, 1) + SourceIndex(1) +3 >Emitted(9, 15) Source(1, 7) + SourceIndex(1) +4 >Emitted(9, 16) Source(1, 8) + SourceIndex(1) +5 >Emitted(9, 21) Source(1, 20) + SourceIndex(1) +6 >Emitted(9, 22) Source(1, 21) + SourceIndex(1) +--- +>>>declare let x: { +1 > +2 >^^^^^^^^ +3 > ^^^^ +4 > ^ +5 > ^^-> +1 > + >c.doThing({a: 42}); + > + > +2 > +3 > let +4 > x +1 >Emitted(10, 1) Source(4, 1) + SourceIndex(1) +2 >Emitted(10, 9) Source(4, 1) + SourceIndex(1) +3 >Emitted(10, 13) Source(4, 5) + SourceIndex(1) +4 >Emitted(10, 14) Source(4, 6) + SourceIndex(1) +--- +>>> b: number; +>>>}; +1->^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> = c.doThing({a: 12}) +2 > ; +1->Emitted(12, 2) Source(4, 27) + SourceIndex(1) +2 >Emitted(12, 3) Source(4, 28) + SourceIndex(1) +--- +>>>//# sourceMappingURL=bundle.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsWithSourceMap.symbols b/tests/baselines/reference/declarationMapsWithSourceMap.symbols new file mode 100644 index 0000000000000..7ae52d3824513 --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithSourceMap.symbols @@ -0,0 +1,40 @@ +=== tests/cases/compiler/a.ts === +class Foo { +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + + doThing(x: {a: number}) { +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>x : Symbol(x, Decl(a.ts, 1, 12)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + + return {b: x.a}; +>b : Symbol(b, Decl(a.ts, 2, 16)) +>x.a : Symbol(a, Decl(a.ts, 1, 16)) +>x : Symbol(x, Decl(a.ts, 1, 12)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + } + static make() { +>make : Symbol(Foo.make, Decl(a.ts, 3, 5)) + + return new Foo(); +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + } +} +=== tests/cases/compiler/index.ts === +const c = new Foo(); +>c : Symbol(c, Decl(index.ts, 0, 5)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +c.doThing({a: 42}); +>c.doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>c : Symbol(c, Decl(index.ts, 0, 5)) +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>a : Symbol(a, Decl(index.ts, 1, 11)) + +let x = c.doThing({a: 12}); +>x : Symbol(x, Decl(index.ts, 3, 3)) +>c.doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>c : Symbol(c, Decl(index.ts, 0, 5)) +>doThing : Symbol(Foo.doThing, Decl(a.ts, 0, 11)) +>a : Symbol(a, Decl(index.ts, 3, 19)) + diff --git a/tests/baselines/reference/declarationMapsWithSourceMap.types b/tests/baselines/reference/declarationMapsWithSourceMap.types new file mode 100644 index 0000000000000..c4fc42619950d --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithSourceMap.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/a.ts === +class Foo { +>Foo : Foo + + doThing(x: {a: number}) { +>doThing : (x: { a: number; }) => { b: number; } +>x : { a: number; } +>a : number + + return {b: x.a}; +>{b: x.a} : { b: number; } +>b : number +>x.a : number +>x : { a: number; } +>a : number + } + static make() { +>make : () => Foo + + return new Foo(); +>new Foo() : Foo +>Foo : typeof Foo + } +} +=== tests/cases/compiler/index.ts === +const c = new Foo(); +>c : Foo +>new Foo() : Foo +>Foo : typeof Foo + +c.doThing({a: 42}); +>c.doThing({a: 42}) : { b: number; } +>c.doThing : (x: { a: number; }) => { b: number; } +>c : Foo +>doThing : (x: { a: number; }) => { b: number; } +>{a: 42} : { a: number; } +>a : number +>42 : 42 + +let x = c.doThing({a: 12}); +>x : { b: number; } +>c.doThing({a: 12}) : { b: number; } +>c.doThing : (x: { a: number; }) => { b: number; } +>c : Foo +>doThing : (x: { a: number; }) => { b: number; } +>{a: 12} : { a: number; } +>a : number +>12 : 12 + diff --git a/tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt b/tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt new file mode 100644 index 0000000000000..c432f44513058 --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithoutDeclaration.errors.txt @@ -0,0 +1,23 @@ +error TS5052: Option 'declarationMap' cannot be specified without specifying option 'declaration'. + + +!!! error TS5052: Option 'declarationMap' cannot be specified without specifying option 'declaration'. +==== tests/cases/compiler/declarationMapsWithoutDeclaration.ts (0 errors) ==== + module m2 { + export interface connectModule { + (res, req, next): void; + } + export interface connectExport { + use: (mod: connectModule) => connectExport; + listen: (port: number) => void; + } + + } + + var m2: { + (): m2.connectExport; + test1: m2.connectModule; + test2(): m2.connectModule; + }; + + export = m2; \ No newline at end of file diff --git a/tests/baselines/reference/declarationMapsWithoutDeclaration.js b/tests/baselines/reference/declarationMapsWithoutDeclaration.js new file mode 100644 index 0000000000000..c4f402cb4dfcb --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithoutDeclaration.js @@ -0,0 +1,24 @@ +//// [declarationMapsWithoutDeclaration.ts] +module m2 { + export interface connectModule { + (res, req, next): void; + } + export interface connectExport { + use: (mod: connectModule) => connectExport; + listen: (port: number) => void; + } + +} + +var m2: { + (): m2.connectExport; + test1: m2.connectModule; + test2(): m2.connectModule; +}; + +export = m2; + +//// [declarationMapsWithoutDeclaration.js] +"use strict"; +var m2; +module.exports = m2; diff --git a/tests/baselines/reference/declarationMapsWithoutDeclaration.symbols b/tests/baselines/reference/declarationMapsWithoutDeclaration.symbols new file mode 100644 index 0000000000000..b74c089162722 --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithoutDeclaration.symbols @@ -0,0 +1,50 @@ +=== tests/cases/compiler/declarationMapsWithoutDeclaration.ts === +module m2 { +>m2 : Symbol(m2, Decl(declarationMapsWithoutDeclaration.ts, 0, 0), Decl(declarationMapsWithoutDeclaration.ts, 11, 3)) + + export interface connectModule { +>connectModule : Symbol(connectModule, Decl(declarationMapsWithoutDeclaration.ts, 0, 11)) + + (res, req, next): void; +>res : Symbol(res, Decl(declarationMapsWithoutDeclaration.ts, 2, 9)) +>req : Symbol(req, Decl(declarationMapsWithoutDeclaration.ts, 2, 13)) +>next : Symbol(next, Decl(declarationMapsWithoutDeclaration.ts, 2, 18)) + } + export interface connectExport { +>connectExport : Symbol(connectExport, Decl(declarationMapsWithoutDeclaration.ts, 3, 5)) + + use: (mod: connectModule) => connectExport; +>use : Symbol(connectExport.use, Decl(declarationMapsWithoutDeclaration.ts, 4, 36)) +>mod : Symbol(mod, Decl(declarationMapsWithoutDeclaration.ts, 5, 14)) +>connectModule : Symbol(connectModule, Decl(declarationMapsWithoutDeclaration.ts, 0, 11)) +>connectExport : Symbol(connectExport, Decl(declarationMapsWithoutDeclaration.ts, 3, 5)) + + listen: (port: number) => void; +>listen : Symbol(connectExport.listen, Decl(declarationMapsWithoutDeclaration.ts, 5, 51)) +>port : Symbol(port, Decl(declarationMapsWithoutDeclaration.ts, 6, 17)) + } + +} + +var m2: { +>m2 : Symbol(m2, Decl(declarationMapsWithoutDeclaration.ts, 0, 0), Decl(declarationMapsWithoutDeclaration.ts, 11, 3)) + + (): m2.connectExport; +>m2 : Symbol(m2, Decl(declarationMapsWithoutDeclaration.ts, 0, 0), Decl(declarationMapsWithoutDeclaration.ts, 11, 3)) +>connectExport : Symbol(m2.connectExport, Decl(declarationMapsWithoutDeclaration.ts, 3, 5)) + + test1: m2.connectModule; +>test1 : Symbol(test1, Decl(declarationMapsWithoutDeclaration.ts, 12, 25)) +>m2 : Symbol(m2, Decl(declarationMapsWithoutDeclaration.ts, 0, 0), Decl(declarationMapsWithoutDeclaration.ts, 11, 3)) +>connectModule : Symbol(m2.connectModule, Decl(declarationMapsWithoutDeclaration.ts, 0, 11)) + + test2(): m2.connectModule; +>test2 : Symbol(test2, Decl(declarationMapsWithoutDeclaration.ts, 13, 28)) +>m2 : Symbol(m2, Decl(declarationMapsWithoutDeclaration.ts, 0, 0), Decl(declarationMapsWithoutDeclaration.ts, 11, 3)) +>connectModule : Symbol(m2.connectModule, Decl(declarationMapsWithoutDeclaration.ts, 0, 11)) + +}; + +export = m2; +>m2 : Symbol(m2, Decl(declarationMapsWithoutDeclaration.ts, 0, 0), Decl(declarationMapsWithoutDeclaration.ts, 11, 3)) + diff --git a/tests/baselines/reference/declarationMapsWithoutDeclaration.types b/tests/baselines/reference/declarationMapsWithoutDeclaration.types new file mode 100644 index 0000000000000..69b4b3e21e8b0 --- /dev/null +++ b/tests/baselines/reference/declarationMapsWithoutDeclaration.types @@ -0,0 +1,50 @@ +=== tests/cases/compiler/declarationMapsWithoutDeclaration.ts === +module m2 { +>m2 : { (): connectExport; test1: connectModule; test2(): connectModule; } + + export interface connectModule { +>connectModule : connectModule + + (res, req, next): void; +>res : any +>req : any +>next : any + } + export interface connectExport { +>connectExport : connectExport + + use: (mod: connectModule) => connectExport; +>use : (mod: connectModule) => connectExport +>mod : connectModule +>connectModule : connectModule +>connectExport : connectExport + + listen: (port: number) => void; +>listen : (port: number) => void +>port : number + } + +} + +var m2: { +>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; } + + (): m2.connectExport; +>m2 : any +>connectExport : m2.connectExport + + test1: m2.connectModule; +>test1 : m2.connectModule +>m2 : any +>connectModule : m2.connectModule + + test2(): m2.connectModule; +>test2 : () => m2.connectModule +>m2 : any +>connectModule : m2.connectModule + +}; + +export = m2; +>m2 : { (): m2.connectExport; test1: m2.connectModule; test2(): m2.connectModule; } + diff --git a/tests/baselines/reference/optionsInlineSourceMapMapRoot.errors.txt b/tests/baselines/reference/optionsInlineSourceMapMapRoot.errors.txt index 77a221a8cbbd7..09c29b6ea65b9 100644 --- a/tests/baselines/reference/optionsInlineSourceMapMapRoot.errors.txt +++ b/tests/baselines/reference/optionsInlineSourceMapMapRoot.errors.txt @@ -1,8 +1,8 @@ -error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. error TS5053: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. +error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. -!!! error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. !!! error TS5053: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. +!!! error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. ==== tests/cases/compiler/optionsInlineSourceMapMapRoot.ts (0 errors) ==== var a = 10; \ No newline at end of file diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt index 2a780bdeda0b3..aa02b659d5de9 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/amd/mapRootSourceRootWithNoSourceMapOption.errors.txt @@ -1,9 +1,9 @@ error TS5051: Option 'sourceRoot can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided. -error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. +error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. !!! error TS5051: Option 'sourceRoot can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided. -!!! error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. +!!! error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt index 2a780bdeda0b3..aa02b659d5de9 100644 --- a/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootSourceRootWithNoSourceMapOption/node/mapRootSourceRootWithNoSourceMapOption.errors.txt @@ -1,9 +1,9 @@ error TS5051: Option 'sourceRoot can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided. -error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. +error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. !!! error TS5051: Option 'sourceRoot can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided. -!!! error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. +!!! error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt index 97e3ed02cf915..7ad42e1a26d37 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/amd/mapRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. +error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. -!!! error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. +!!! error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt index 97e3ed02cf915..7ad42e1a26d37 100644 --- a/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt +++ b/tests/baselines/reference/project/mapRootWithNoSourceMapOption/node/mapRootWithNoSourceMapOption.errors.txt @@ -1,7 +1,7 @@ -error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. +error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. -!!! error TS5052: Option 'mapRoot' cannot be specified without specifying option 'sourceMap'. +!!! error TS5069: Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'. ==== m1.ts (0 errors) ==== var m1_a1 = 10; class m1_c1 { diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index cb57cd1366bb5..28ccc78540c7a 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -8,6 +8,7 @@ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "outDir": "./", /* Redirect output structure to the directory. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 6614dd9e48e1a..25c75a4b55699 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -8,6 +8,7 @@ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "outDir": "./", /* Redirect output structure to the directory. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 8c19ad58bed7f..168fcc6dfe637 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -8,6 +8,7 @@ // "checkJs": true, /* Report errors in .js files. */ "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "outDir": "./", /* Redirect output structure to the directory. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index f5e2b163a21a3..e87936a34fc8d 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -8,6 +8,7 @@ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "outDir": "./", /* Redirect output structure to the directory. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index ced3eae17b824..c00426a373b6a 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -8,6 +8,7 @@ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "outDir": "./", /* Redirect output structure to the directory. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index cb57cd1366bb5..28ccc78540c7a 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -8,6 +8,7 @@ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "outDir": "./", /* Redirect output structure to the directory. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 1356e2258f7b4..a4d7d4ffc2c90 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -8,6 +8,7 @@ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "outDir": "./", /* Redirect output structure to the directory. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index 473280f675ee1..d01ba76d82237 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -8,6 +8,7 @@ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ // "outDir": "./", /* Redirect output structure to the directory. */ diff --git a/tests/cases/compiler/declarationMaps.ts b/tests/cases/compiler/declarationMaps.ts new file mode 100644 index 0000000000000..cb7883359432b --- /dev/null +++ b/tests/cases/compiler/declarationMaps.ts @@ -0,0 +1,20 @@ +// @declaration: true +// @declarationMap: true +module m2 { + export interface connectModule { + (res, req, next): void; + } + export interface connectExport { + use: (mod: connectModule) => connectExport; + listen: (port: number) => void; + } + +} + +var m2: { + (): m2.connectExport; + test1: m2.connectModule; + test2(): m2.connectModule; +}; + +export = m2; \ No newline at end of file diff --git a/tests/cases/compiler/declarationMapsMultifile.ts b/tests/cases/compiler/declarationMapsMultifile.ts new file mode 100644 index 0000000000000..43d77c4c49e1c --- /dev/null +++ b/tests/cases/compiler/declarationMapsMultifile.ts @@ -0,0 +1,19 @@ +// @declaration: true +// @declarationMap: true +// @filename: a.ts +export class Foo { + doThing(x: {a: number}) { + return {b: x.a}; + } + static make() { + return new Foo(); + } +} +// @filename: index.ts +import {Foo} from "./a"; + +const c = new Foo(); +c.doThing({a: 42}); + +export let x = c.doThing({a: 12}); +export { c, Foo }; diff --git a/tests/cases/compiler/declarationMapsOutFile.ts b/tests/cases/compiler/declarationMapsOutFile.ts new file mode 100644 index 0000000000000..b388d567ef335 --- /dev/null +++ b/tests/cases/compiler/declarationMapsOutFile.ts @@ -0,0 +1,21 @@ +// @declaration: true +// @declarationMap: true +// @module: amd +// @outFile: bundle.js +// @filename: a.ts +export class Foo { + doThing(x: {a: number}) { + return {b: x.a}; + } + static make() { + return new Foo(); + } +} +// @filename: index.ts +import {Foo} from "./a"; + +const c = new Foo(); +c.doThing({a: 42}); + +export let x = c.doThing({a: 12}); +export { c, Foo }; diff --git a/tests/cases/compiler/declarationMapsOutFile2.ts b/tests/cases/compiler/declarationMapsOutFile2.ts new file mode 100644 index 0000000000000..713f6f5391044 --- /dev/null +++ b/tests/cases/compiler/declarationMapsOutFile2.ts @@ -0,0 +1,17 @@ +// @declaration: true +// @declarationMap: true +// @outFile: bundle.js +// @filename: a.ts +class Foo { + doThing(x: {a: number}) { + return {b: x.a}; + } + static make() { + return new Foo(); + } +} +// @filename: index.ts +const c = new Foo(); +c.doThing({a: 42}); + +let x = c.doThing({a: 12}); diff --git a/tests/cases/compiler/declarationMapsWithSourceMap.ts b/tests/cases/compiler/declarationMapsWithSourceMap.ts new file mode 100644 index 0000000000000..332ccb04fce36 --- /dev/null +++ b/tests/cases/compiler/declarationMapsWithSourceMap.ts @@ -0,0 +1,18 @@ +// @declaration: true +// @declarationMap: true +// @outFile: bundle.js +// @sourceMap: true +// @filename: a.ts +class Foo { + doThing(x: {a: number}) { + return {b: x.a}; + } + static make() { + return new Foo(); + } +} +// @filename: index.ts +const c = new Foo(); +c.doThing({a: 42}); + +let x = c.doThing({a: 12}); diff --git a/tests/cases/compiler/declarationMapsWithoutDeclaration.ts b/tests/cases/compiler/declarationMapsWithoutDeclaration.ts new file mode 100644 index 0000000000000..266b0760bb126 --- /dev/null +++ b/tests/cases/compiler/declarationMapsWithoutDeclaration.ts @@ -0,0 +1,19 @@ +// @declarationMap: true +module m2 { + export interface connectModule { + (res, req, next): void; + } + export interface connectExport { + use: (mod: connectModule) => connectExport; + listen: (port: number) => void; + } + +} + +var m2: { + (): m2.connectExport; + test1: m2.connectModule; + test2(): m2.connectModule; +}; + +export = m2; \ No newline at end of file diff --git a/tests/cases/fourslash/declarationMapGoToDefinition.ts b/tests/cases/fourslash/declarationMapGoToDefinition.ts new file mode 100644 index 0000000000000..a83fd7e8396e3 --- /dev/null +++ b/tests/cases/fourslash/declarationMapGoToDefinition.ts @@ -0,0 +1,40 @@ +/// +// @Filename: index.ts +////export class Foo { +//// member: string; +//// /*2*/methodName(propName: SomeType): void {} +//// otherMethod() { +//// if (Math.random() > 0.5) { +//// return {x: 42}; +//// } +//// return {y: "yes"}; +//// } +////} +//// +////export interface SomeType { +//// member: number; +////} +// @Filename: indexdef.d.ts.map +////{"version":3,"file":"indexdef.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;IACI,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IACpC,WAAW;;;;;;;CAMd;AAED,MAAM,WAAW,QAAQ;IACrB,MAAM,EAAE,MAAM,CAAC;CAClB"} +// @Filename: indexdef.d.ts +////export declare class Foo { +//// member: string; +//// methodName(propName: SomeType): void; +//// otherMethod(): { +//// x: number; +//// y?: undefined; +//// } | { +//// y: string; +//// x?: undefined; +//// }; +////} +////export interface SomeType { +//// member: number; +////} +//////# sourceMappingURL=indexdef.d.ts.map +// @Filename: mymodule.ts +////import * as mod from "./indexdef"; +////const instance = new mod.Foo(); +////instance.[|/*1*/methodName|]({member: 12}); + +verify.goToDefinition("1", "2"); diff --git a/tests/cases/fourslash/declarationMapsEnableMapping_NoInline.ts b/tests/cases/fourslash/declarationMapsEnableMapping_NoInline.ts new file mode 100644 index 0000000000000..a17f7afcdd884 --- /dev/null +++ b/tests/cases/fourslash/declarationMapsEnableMapping_NoInline.ts @@ -0,0 +1,34 @@ +/// +// @BaselineFile: declarationMapsGeneratedMapsEnableMapping_NoInline.baseline +// @outDir: ./dist +// @inlineSourceMap: true +// @declaration: true +// @declarationMap: true +// @Filename: index.ts +// @emitThisFile: true +////export class Foo { +//// member: string; +//// /*2*/methodName(propName: SomeType): void {} +//// otherMethod() { +//// if (Math.random() > 0.5) { +//// return {x: 42}; +//// } +//// return {y: "yes"}; +//// } +////} +//// +////export interface SomeType { +//// member: number; +////} +// @Filename: mymodule.ts +////import * as mod from "/dist/index"; +////const instance = new mod.Foo(); +////instance.[|/*1*/methodName|]({member: 12}); + +verify.baselineGetEmitOutput(/*insertResultIntoVfs*/ true); +verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan +verify.goToType("1", "2"); // getTypeDefinitionAtPosition +goTo.marker("1"); +verify.goToDefinitionIs("2"); // getDefinitionAtPosition +goTo.implementation(); // getImplementationAtPosition +verify.caretAtMarker("2"); \ No newline at end of file diff --git a/tests/cases/fourslash/declarationMapsEnableMapping_NoInlineSources.ts b/tests/cases/fourslash/declarationMapsEnableMapping_NoInlineSources.ts new file mode 100644 index 0000000000000..4760bbc628d2d --- /dev/null +++ b/tests/cases/fourslash/declarationMapsEnableMapping_NoInlineSources.ts @@ -0,0 +1,35 @@ +/// +// @BaselineFile: declarationMapsGeneratedMapsEnableMapping_NoInlineSources.baseline +// @outDir: ./dist +// @inlineSourceMap: true +// @inlineSources: true +// @declaration: true +// @declarationMap: true +// @Filename: index.ts +// @emitThisFile: true +////export class Foo { +//// member: string; +//// /*2*/methodName(propName: SomeType): void {} +//// otherMethod() { +//// if (Math.random() > 0.5) { +//// return {x: 42}; +//// } +//// return {y: "yes"}; +//// } +////} +//// +////export interface SomeType { +//// member: number; +////} +// @Filename: mymodule.ts +////import * as mod from "/dist/index"; +////const instance = new mod.Foo(); +////instance.[|/*1*/methodName|]({member: 12}); + +verify.baselineGetEmitOutput(/*insertResultIntoVfs*/ true); +verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan +verify.goToType("1", "2"); // getTypeDefinitionAtPosition +goTo.marker("1"); +verify.goToDefinitionIs("2"); // getDefinitionAtPosition +goTo.implementation(); // getImplementationAtPosition +verify.caretAtMarker("2"); \ No newline at end of file diff --git a/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping.ts b/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping.ts new file mode 100644 index 0000000000000..42e08f8a27f31 --- /dev/null +++ b/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping.ts @@ -0,0 +1,33 @@ +/// +// @BaselineFile: declarationMapsGeneratedMapsEnableMapping.baseline +// @outDir: ./dist +// @declaration: true +// @declarationMap: true +// @Filename: index.ts +// @emitThisFile: true +////export class Foo { +//// member: string; +//// /*2*/methodName(propName: SomeType): void {} +//// otherMethod() { +//// if (Math.random() > 0.5) { +//// return {x: 42}; +//// } +//// return {y: "yes"}; +//// } +////} +//// +////export interface SomeType { +//// member: number; +////} +// @Filename: mymodule.ts +////import * as mod from "/dist/index"; +////const instance = new mod.Foo(); +////instance.[|/*1*/methodName|]({member: 12}); + +verify.baselineGetEmitOutput(/*insertResultIntoVfs*/ true); +verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan +verify.goToType("1", "2"); // getTypeDefinitionAtPosition +goTo.marker("1"); +verify.goToDefinitionIs("2"); // getDefinitionAtPosition +goTo.implementation(); // getImplementationAtPosition +verify.caretAtMarker("2"); diff --git a/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping2.ts b/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping2.ts new file mode 100644 index 0000000000000..261122c1e8e7b --- /dev/null +++ b/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping2.ts @@ -0,0 +1,35 @@ +/// +// @BaselineFile: declarationMapsGeneratedMapsEnableMapping2.baseline +// @outDir: ./dist +// @sourceMap: true +// @sourceRoot: /tests/cases/fourslash/ +// @declaration: true +// @declarationMap: true +// @Filename: index.ts +// @emitThisFile: true +////export class Foo { +//// member: string; +//// /*2*/methodName(propName: SomeType): void {} +//// otherMethod() { +//// if (Math.random() > 0.5) { +//// return {x: 42}; +//// } +//// return {y: "yes"}; +//// } +////} +//// +////export interface SomeType { +//// member: number; +////} +// @Filename: mymodule.ts +////import * as mod from "/dist/index"; +////const instance = new mod.Foo(); +////instance.[|/*1*/methodName|]({member: 12}); + +verify.baselineGetEmitOutput(/*insertResultIntoVfs*/ true); +verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan +verify.goToType("1", "2"); // getTypeDefinitionAtPosition +goTo.marker("1"); +verify.goToDefinitionIs("2"); // getDefinitionAtPosition +goTo.implementation(); // getImplementationAtPosition +verify.caretAtMarker("2"); diff --git a/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping3.ts b/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping3.ts new file mode 100644 index 0000000000000..cd90793358e5c --- /dev/null +++ b/tests/cases/fourslash/declarationMapsGeneratedMapsEnableMapping3.ts @@ -0,0 +1,34 @@ +/// +// @BaselineFile: declarationMapsGeneratedMapsEnableMapping3.baseline +// @outDir: ./dist +// @sourceRoot: /tests/cases/fourslash/ +// @declaration: true +// @declarationMap: true +// @Filename: index.ts +// @emitThisFile: true +////export class Foo { +//// member: string; +//// /*2*/methodName(propName: SomeType): void {} +//// otherMethod() { +//// if (Math.random() > 0.5) { +//// return {x: 42}; +//// } +//// return {y: "yes"}; +//// } +////} +//// +////export interface SomeType { +//// member: number; +////} +// @Filename: mymodule.ts +////import * as mod from "/dist/index"; +////const instance = new mod.Foo(); +////instance.[|/*1*/methodName|]({member: 12}); + +verify.baselineGetEmitOutput(/*insertResultIntoVfs*/ true); +verify.goToDefinition("1", "2"); // getDefinitionAndBoundSpan +verify.goToType("1", "2"); // getTypeDefinitionAtPosition +goTo.marker("1"); +verify.goToDefinitionIs("2"); // getDefinitionAtPosition +goTo.implementation(); // getImplementationAtPosition +verify.caretAtMarker("2"); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index ed239d64f2e38..14d89cc418f7c 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -284,7 +284,7 @@ declare namespace FourSlashInterface { numberOfErrorsInCurrentFile(expected: number): void; baselineCurrentFileBreakpointLocations(): void; baselineCurrentFileNameOrDottedNameSpans(): void; - baselineGetEmitOutput(): void; + baselineGetEmitOutput(insertResultsIntoVfs?: boolean): void; baselineQuickInfo(): void; nameOrDottedNameSpanTextIs(text: string): void; outliningSpansInCurrentFile(spans: Range[]): void;