Skip to content

Commit

Permalink
🤖 Pick PR #59337 (Allow declarationMap to be emitted ...) into releas…
Browse files Browse the repository at this point in the history
…e-5.5 (#59344)

Co-authored-by: Sheetal Nandi <[email protected]>
  • Loading branch information
TypeScript Bot and sheetalkamat authored Jul 19, 2024
1 parent 9dd6f91 commit b075332
Show file tree
Hide file tree
Showing 16 changed files with 955 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/compiler/builderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
computeSignatureWithDiagnostics,
CustomTransformers,
Debug,
EmitOnly,
EmitOutput,
emptyArray,
GetCanonicalFileName,
Expand Down Expand Up @@ -418,7 +419,7 @@ export namespace BuilderState {
);
},
cancellationToken,
/*emitOnly*/ true,
EmitOnly.BuilderSignature,
/*customTransformers*/ undefined,
/*forceDtsEmit*/ true,
);
Expand Down
1 change: 0 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ export const commonOptionsWithBuild: CommandLineOption[] = [
affectsBuildInfo: true,
showInSimplifiedHelpView: true,
category: Diagnostics.Emit,
transpileOptionValue: undefined,
defaultValueDescription: false,
description: Diagnostics.Create_sourcemaps_for_d_ts_files,
},
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
noEmitHelpers: true,
module: compilerOptions.module,
target: compilerOptions.target,
sourceMap: !forceDtsEmit && compilerOptions.declarationMap,
sourceMap: emitOnly !== EmitOnly.BuilderSignature && compilerOptions.declarationMap,
inlineSourceMap: compilerOptions.inlineSourceMap,
extendedDiagnostics: compilerOptions.extendedDiagnostics,
onlyPrintJsDocStyle: true,
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4641,6 +4641,7 @@ export type FilePreprocessingDiagnostics = FilePreprocessingLibReferenceDiagnost
export const enum EmitOnly {
Js,
Dts,
BuilderSignature,
}

/** @internal */
Expand Down
13 changes: 12 additions & 1 deletion src/testRunner/transpileRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ enum TranspileKind {
}

class TranspileTestCase {
static varyBy = [];
static varyBy = [
"declarationMap",
"sourceMap",
"inlineSourceMap",
];

static getConfigurations(file: string): TranspileTestCase[] {
const ext = vpath.extname(file);
Expand Down Expand Up @@ -104,6 +108,13 @@ class TranspileTestCase {
if (!result.outputText.endsWith("\n")) {
baselineText += "\r\n";
}
if (result.sourceMapText) {
baselineText += `//// [${ts.changeExtension(unit.name, kind === TranspileKind.Module ? this.getJsOutputExtension(unit.name) : ts.getDeclarationEmitExtensionForPath(unit.name))}.map] ////\r\n`;
baselineText += result.sourceMapText;
if (!result.outputText.endsWith("\n")) {
baselineText += "\r\n";
}
}
if (result.diagnostics && result.diagnostics.length) {
baselineText += "\r\n\r\n//// [Diagnostics reported]\r\n";
baselineText += Compiler.getErrorBaseline([{ content: unit.content, unitName: unit.name }], result.diagnostics, !!opts.pretty);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//// [variables.ts] ////
export const a = 1;
export let b = 2;
export var c = 3;
using d = undefined;
export { d };
await using e = undefined;
export { e };
//// [interface.ts] ////
export interface Foo {
a: string;
readonly b: string;
c?: string;
}
//// [class.ts] ////
const i = Symbol();
export class Bar {
a: string;
b?: string;
declare c: string;
#d: string;
public e: string;
protected f: string;
private g: string;
["h"]: string;
[i]: string;
}

export abstract class Baz {
abstract a: string;
abstract method(): void;
}
//// [namespace.ts] ////
export namespace ns {
namespace internal {
export class Foo {}
}
export namespace nested {
export import inner = internal;
}
}
//// [alias.ts] ////
export type A<T> = { x: T };
//// [variables.d.ts] ////
export declare const a = 1;
export declare let b: number;
export declare var c: number;
declare const d: any;
export { d };
declare const e: any;
export { e };
//# sourceMappingURL=variables.d.ts.map
//// [variables.d.ts.map] ////
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["variables.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,CAAC,IAAI,CAAC;AACnB,eAAO,IAAI,CAAC,QAAI,CAAC;AACjB,eAAO,IAAI,CAAC,QAAI,CAAC;AACjB,QAAA,MAAM,CAAC,KAAY,CAAC;AACpB,OAAO,EAAE,CAAC,EAAE,CAAC;AACb,QAAA,MAAY,CAAC,KAAY,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,CAAC"}
//// [interface.d.ts] ////
export interface Foo {
a: string;
readonly b: string;
c?: string;
}
//# sourceMappingURL=interface.d.ts.map
//// [interface.d.ts.map] ////
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,CAAC,EAAE,MAAM,CAAC;CACd"}
//// [class.d.ts] ////
export declare class Bar {
#private;
a: string;
b?: string;
c: string;
e: string;
protected f: string;
private g;
["h"]: string;
}
export declare abstract class Baz {
abstract a: string;
abstract method(): void;
}
//# sourceMappingURL=class.d.ts.map
//// [class.d.ts.map] ////
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["class.ts"],"names":[],"mappings":"AACA,qBAAa,GAAG;;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,CAAC,EAAE,MAAM,CAAC;IACH,CAAC,EAAE,MAAM,CAAC;IAEX,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,CAAC,CAAS;IAClB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CAEjB;AAED,8BAAsB,GAAG;IACrB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,MAAM,IAAI,IAAI;CAC1B"}


//// [Diagnostics reported]
class.ts(11,5): error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.


==== class.ts (1 errors) ====
const i = Symbol();
export class Bar {
a: string;
b?: string;
declare c: string;
#d: string;
public e: string;
protected f: string;
private g: string;
["h"]: string;
[i]: string;
~~~
!!! error TS9038: Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.
}

export abstract class Baz {
abstract a: string;
abstract method(): void;
}
//// [namespace.d.ts] ////
export declare namespace ns {
namespace internal {
class Foo {
}
}
export namespace nested {
export import inner = internal;
}
export {};
}
//# sourceMappingURL=namespace.d.ts.map
//// [namespace.d.ts.map] ////
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["namespace.ts"],"names":[],"mappings":"AAAA,yBAAiB,EAAE,CAAC;IAChB,UAAU,QAAQ,CAAC;QACf,MAAa,GAAG;SAAG;KACtB;IACD,MAAM,WAAW,MAAM,CAAC;QACpB,MAAM,QAAQ,KAAK,GAAG,QAAQ,CAAC;KAClC;;CACJ"}
//// [alias.d.ts] ////
export type A<T> = {
x: T;
};
//# sourceMappingURL=alias.d.ts.map
//// [alias.d.ts.map] ////
{"version":3,"file":"alias.d.ts","sourceRoot":"","sources":["alias.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,CAAC,CAAC,CAAC,IAAI;IAAE,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//// [variables.ts] ////
export const a = 1;
export let b = 2;
export var c = 3;
using d = undefined;
export { d };
await using e = undefined;
export { e };
//// [interface.ts] ////
export interface Foo {
a: string;
readonly b: string;
c?: string;
}
//// [class.ts] ////
const i = Symbol();
export class Bar {
a: string;
b?: string;
declare c: string;
#d: string;
public e: string;
protected f: string;
private g: string;
["h"]: string;
[i]: string;
}

export abstract class Baz {
abstract a: string;
abstract method(): void;
}
//// [namespace.ts] ////
export namespace ns {
namespace internal {
export class Foo {}
}
export namespace nested {
export import inner = internal;
}
}
//// [alias.ts] ////
export type A<T> = { x: T };
//// [variables.js] ////
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
if (value !== null && value !== void 0) {
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
var dispose, inner;
if (async) {
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
dispose = value[Symbol.asyncDispose];
}
if (dispose === void 0) {
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
dispose = value[Symbol.dispose];
if (async) inner = dispose;
}
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
env.stack.push({ value: value, dispose: dispose, async: async });
}
else if (async) {
env.stack.push({ async: true });
}
return value;
};
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
return function (env) {
function fail(e) {
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
env.hasError = true;
}
function next() {
while (env.stack.length) {
var rec = env.stack.pop();
try {
var result = rec.dispose && rec.dispose.call(rec.value);
if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
}
catch (e) {
fail(e);
}
}
if (env.hasError) throw env.error;
}
return next();
};
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
});
export const a = 1;
export let b = 2;
export var c = 3;
export { d };
export { e };
var d, e;
const env_1 = { stack: [], error: void 0, hasError: false };
try {
d = __addDisposableResource(env_1, undefined, false);
e = __addDisposableResource(env_1, undefined, true);
}
catch (e_1) {
env_1.error = e_1;
env_1.hasError = true;
}
finally {
const result_1 = __disposeResources(env_1);
if (result_1)
await result_1;
}
//// [interface.js] ////
export {};
//// [class.js] ////
var _Bar_d;
const i = Symbol();
export class Bar {
constructor() {
_Bar_d.set(this, void 0);
}
}
_Bar_d = new WeakMap();
export class Baz {
}
//// [namespace.js] ////
export var ns;
(function (ns) {
let internal;
(function (internal) {
class Foo {
}
internal.Foo = Foo;
})(internal || (internal = {}));
let nested;
(function (nested) {
nested.inner = internal;
})(nested = ns.nested || (ns.nested = {}));
})(ns || (ns = {}));
//// [alias.js] ////
export {};
Loading

0 comments on commit b075332

Please sign in to comment.