Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 7 additions & 6 deletions internal/compiler/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ func (e *emitter) emitDeclarationFile(sourceFile *ast.SourceFile, declarationFil
// !!! strada skipped emit if there were diagnostics

printerOptions := printer.PrinterOptions{
RemoveComments: options.RemoveComments.IsTrue(),
NewLine: options.NewLine,
NoEmitHelpers: options.NoEmitHelpers.IsTrue(),
SourceMap: options.DeclarationMap.IsTrue(),
InlineSourceMap: options.InlineSourceMap.IsTrue(),
InlineSources: options.InlineSources.IsTrue(),
RemoveComments: options.RemoveComments.IsTrue(),
OnlyPrintJSDocStyle: true, // For declaration files, only emit JSDoc-style comments
NewLine: options.NewLine,
NoEmitHelpers: options.NoEmitHelpers.IsTrue(),
SourceMap: options.DeclarationMap.IsTrue(),
InlineSourceMap: options.InlineSourceMap.IsTrue(),
InlineSources: options.InlineSources.IsTrue(),
// !!!
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//// [tests/cases/compiler/declarationEmitCommentsPreservation.ts] ////

//// [declarationEmitCommentsPreservation.ts]
// Comment
export class DbObject {
// Comment
id: string = ""; // Comment
// Comment
method() { }
}

//// [declarationEmitCommentsPreservation.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DbObject = void 0;
// Comment
class DbObject {
// Comment
id = ""; // Comment
// Comment
method() { }
}
exports.DbObject = DbObject;


//// [declarationEmitCommentsPreservation.d.ts]
export declare class DbObject {
id: string;
method(): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/compiler/declarationEmitCommentsPreservation.ts] ////

=== declarationEmitCommentsPreservation.ts ===
// Comment
export class DbObject {
>DbObject : Symbol(DbObject, Decl(declarationEmitCommentsPreservation.ts, 0, 0))

// Comment
id: string = ""; // Comment
>id : Symbol(DbObject.id, Decl(declarationEmitCommentsPreservation.ts, 1, 23))

// Comment
method() { }
>method : Symbol(DbObject.method, Decl(declarationEmitCommentsPreservation.ts, 3, 20))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/declarationEmitCommentsPreservation.ts] ////

=== declarationEmitCommentsPreservation.ts ===
// Comment
export class DbObject {
>DbObject : DbObject

// Comment
id: string = ""; // Comment
>id : string
>"" : ""

// Comment
method() { }
>method : () => void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//// [tests/cases/compiler/declarationEmitCommentsWithJSDoc.ts] ////

//// [declarationEmitCommentsWithJSDoc.ts]
// Regular comment - should be removed
/**
* JSDoc comment - should be preserved
*/
export class DbObject {
// Regular comment - should be removed
/**
* JSDoc property comment
*/
id: string = ""; // Trailing comment - should be removed

// Regular comment - should be removed
/**
* JSDoc method comment
* @returns void
*/
method() { }
}

//// [declarationEmitCommentsWithJSDoc.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DbObject = void 0;
// Regular comment - should be removed
/**
* JSDoc comment - should be preserved
*/
class DbObject {
// Regular comment - should be removed
/**
* JSDoc property comment
*/
id = ""; // Trailing comment - should be removed
// Regular comment - should be removed
/**
* JSDoc method comment
* @returns void
*/
method() { }
}
exports.DbObject = DbObject;


//// [declarationEmitCommentsWithJSDoc.d.ts]
/**
* JSDoc comment - should be preserved
*/
export declare class DbObject {
/**
* JSDoc property comment
*/
id: string;
/**
* JSDoc method comment
* @returns void
*/
method(): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/declarationEmitCommentsWithJSDoc.ts] ////

=== declarationEmitCommentsWithJSDoc.ts ===
// Regular comment - should be removed
/**
* JSDoc comment - should be preserved
*/
export class DbObject {
>DbObject : Symbol(DbObject, Decl(declarationEmitCommentsWithJSDoc.ts, 0, 0))

// Regular comment - should be removed
/**
* JSDoc property comment
*/
id: string = ""; // Trailing comment - should be removed
>id : Symbol(DbObject.id, Decl(declarationEmitCommentsWithJSDoc.ts, 4, 23))

// Regular comment - should be removed
/**
* JSDoc method comment
* @returns void
*/
method() { }
>method : Symbol(DbObject.method, Decl(declarationEmitCommentsWithJSDoc.ts, 9, 20))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//// [tests/cases/compiler/declarationEmitCommentsWithJSDoc.ts] ////

=== declarationEmitCommentsWithJSDoc.ts ===
// Regular comment - should be removed
/**
* JSDoc comment - should be preserved
*/
export class DbObject {
>DbObject : DbObject

// Regular comment - should be removed
/**
* JSDoc property comment
*/
id: string = ""; // Trailing comment - should be removed
>id : string
>"" : ""

// Regular comment - should be removed
/**
* JSDoc method comment
* @returns void
*/
method() { }
>method : () => void
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,22 @@ export class PublicWithDefault {


//// [parameterPropertyWithDefaultValueExtended.d.ts]
// Test with default value - should not have undefined
export declare class WithDefault {
readonly timestamp: Date;
constructor(timestamp?: Date);
}
// Test without default value but optional - should have undefined
export declare class WithoutDefault {
readonly timestamp?: Date | undefined;
constructor(timestamp?: Date | undefined);
}
// Test with explicit undefined type - should keep it
export declare class ExplicitUndefined {
readonly timestamp: Date | undefined;
constructor(timestamp?: Date | undefined);
}
// Test private parameter property with default value
export declare class PrivateWithDefault {
private timestamp;
constructor(timestamp?: Date);
}
// Test public parameter property with default value
export declare class PublicWithDefault {
timestamp: Date;
constructor(timestamp?: Date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export type ControllerClass = Constructor<any>;
//// [usage.d.ts]
import { ControllerClass } from './application';
import { BindingKey } from '@loopback/context';
export declare const CONTROLLER_CLASS: BindingKey<ControllerClass>; // line in question
export declare const CONTROLLER_CLASS: BindingKey<ControllerClass>;
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ p.use(x, y, z);


//// [typeTagForMultipleVariableDeclarations.d.ts]
// based on code from unifiedjs/unified
declare class Node {
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ declare const _default: {
};
};
export default _default;
// Simple class
export declare class User {
name: string;
}
Expand All @@ -99,7 +98,6 @@ declare const TimestampedUser_base: {
timestamp: number;
};
} & typeof User;
// User that is Timestamped
export declare class TimestampedUser extends TimestampedUser_base {
constructor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,4 @@
+ name = '';
}
exports.User = User;
// User that is Timestamped
@@= skipped -47, +42 lines =@@
};
};
export default _default;
+// Simple class
export declare class User {
name: string;
}
@@= skipped -8, +9 lines =@@
timestamp: number;
};
} & typeof User;
+// User that is Timestamped
export declare class TimestampedUser extends TimestampedUser_base {
constructor();
}
// User that is Timestamped
13 changes: 4 additions & 9 deletions testdata/baselines/reference/submodule/compiler/bigintWithLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,14 @@ new Intl.NumberFormat("fr").format(bigintVal);


//// [bigintWithLib.d.ts]
// Test BigInt functions
declare let bigintVal: bigint;
declare let stringVal: string;
// Test BigInt64Array
declare let bigIntArray: BigInt64Array;
declare let len: number;
declare let arrayBufferLike: ArrayBufferView;
// Test BigUint64Array
declare let bigUintArray: BigUint64Array;
// Test added DataView methods
declare const dataView: DataView<ArrayBuffer>;
// Test emitted declarations files
declare const w = 12n; // should emit as const w = 12n
declare const x = -12n; // should emit as const x = -12n
declare const y: 12n; // should emit type 12n
declare let z: bigint; // should emit type bigint in declaration file
declare const w = 12n;
declare const x = -12n;
declare const y: 12n;
declare let z: bigint;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ function f(m) {


//// [circularBaseTypes.d.ts]
// Repro from #38098
type M<T> = {
value: T;
};
interface M2 extends M<M3> {
}
type M3 = M2[keyof M2]; // Error
type M3 = M2[keyof M2];
declare function f(m: M3): any;
// Repro from #32581
type X<T> = {
[K in keyof T]: string;
} & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,4 @@
-// Repro from #38098
; // Error
function f(m) {
return m.value;
@@= skipped -9, +7 lines =@@


//// [circularBaseTypes.d.ts]
+// Repro from #38098
type M<T> = {
value: T;
};
interface M2 extends M<M3> {
}
-type M3 = M2[keyof M2];
+type M3 = M2[keyof M2]; // Error
declare function f(m: M3): any;
+// Repro from #32581
type X<T> = {
[K in keyof T]: string;
} & {
return m.value;
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class e {

//// [classdecl.d.ts]
declare class a {
//constructor ();
constructor(n: number);
constructor(s: string);
pgF(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,4 @@
+ pv3;
foo(ns) {
return ns.toString();
}
@@= skipped -44, +45 lines =@@

//// [classdecl.d.ts]
declare class a {
+ //constructor ();
constructor(n: number);
constructor(s: string);
pgF(): void;
}
Loading
Loading