Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fast_check_dts): ensure top level non-exported functions have declare keyword #423

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 66 additions & 62 deletions src/fast_check/transform_dts.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/DynamicImport.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/a.ts:
export class Test {
}
--- DTS ---
export declare class Test {
export class Test {
}

Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
Expand Down
10 changes: 5 additions & 5 deletions tests/specs/graph/jsr/FastCheck.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ Fast check https://jsr.io/@scope/a/1.0.0/a.ts:
export { A4 } from "./a4.ts";
export * from "./a6.ts";
--- DTS ---
export declare class A1 {
export class A1 {
}
export declare class A3 {
export class A3 {
}
export { A4 } from "./a4.ts";
export * from "./a6.ts";
Expand All @@ -224,15 +224,15 @@ Fast check https://jsr.io/@scope/a/1.0.0/a4.ts:
export class A4 {
}
--- DTS ---
export declare class A4 {
export class A4 {
}

Fast check https://jsr.io/@scope/a/1.0.0/a6.ts:
{}
export class A6 {
}
--- DTS ---
export declare class A6 {
export class A6 {
}

Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
Expand Down Expand Up @@ -269,7 +269,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
}
--- DTS ---
import { A1, A3 as RenamedA3, A4, A6 } from "./a.ts";
export declare class Test {
export class Test {
/** Testing */ noReturnTypeVoid(param?: number, param2?: string): void;
noReturnTypeAsync(): Promise<void>;
returnTypeGenerator(): Generator<unknown, any, any>;
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/graph/jsr/FastCheck_AutoAccessors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
#private!: unknown;
}
--- DTS ---
export declare class AutoAccessor {
export class AutoAccessor {
/** Some comment */ public_accessor: string;
private private_accessor: any;
static static_accessor: number;
private static private_static: any;
private static private_static_unanalyzable: any;
}
export declare class PrivateAccessor {
export class PrivateAccessor {
}
24 changes: 12 additions & 12 deletions tests/specs/graph/jsr/FastCheck_ClassCtors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,47 +176,47 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
class Public5 {
}
--- DTS ---
/** A */ export declare class ClassBasic {
/** A */ export class ClassBasic {
/** B */ constructor(prop: string, other?: number);
}
export declare class ClassPrivateCtor {
export class ClassPrivateCtor {
private constructor();
}
export declare class ClassPrivateCtorWithOverloads {
export class ClassPrivateCtorWithOverloads {
private constructor();
}
export declare class ClassDeclarePrivateCtor {
export class ClassDeclarePrivateCtor {
private constructor(prop: string, other: Private1);
}
export declare class ClassProtectedCtor {
export class ClassProtectedCtor {
protected constructor(prop: string, other?: number);
}
export declare class ClassProtectedCtorWithOverloads {
export class ClassProtectedCtorWithOverloads {
protected constructor(prop: Public1);
}
export declare class ClassCtorWithOverloads {
export class ClassCtorWithOverloads {
constructor(prop: Public1);
}
export declare class ClassPrivateCtorPublicParamProp {
export class ClassPrivateCtorPublicParamProp {
param1: Public2;
private param2: any;
private constructor();
}
export declare class ClassCtorPublicParamProp {
export class ClassCtorPublicParamProp {
param1: Public3;
private param2: any;
private param3: any;
constructor(param1: Public3, param2: Public4, param3?: Public5);
}
export declare class ClassCtorPublicParamPropInit {
export class ClassCtorPublicParamPropInit {
param1: Public3;
constructor(param1?: Public3);
}
export declare class ClassCtorPublicParamPropOptional {
export class ClassCtorPublicParamPropOptional {
param1?: string;
constructor(param1?: string);
}
export declare class AmbientClassCtor {
export class AmbientClassCtor {
constructor(public param: string, private value: number);
constructor(public param: string);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/FastCheck_ClassGettersAndSetters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
set value(_value: string) {}
}
--- DTS ---
export declare class MyClass {
export class MyClass {
get value(): string;
set value(_value: string);
}
2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/FastCheck_ClassMemberRefFound.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
declare prop: string;
}
--- DTS ---
export declare class Export {
export class Export {
prop: typeof Public1.prototype.prop;
}
declare class Public1 {
Expand Down
8 changes: 4 additions & 4 deletions tests/specs/graph/jsr/FastCheck_ClassMethodsWithTsPrivate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
private override test!: any;
}
--- DTS ---
export declare class PrivateMethodOverloadable {
export class PrivateMethodOverloadable {
private constructor();
private method: any;
private methodWithOverload: any;
private "stringAndIdent": any;
private "stringOnly": any;
}
export declare class AmbientPrivateMethodOverloadable {
export class AmbientPrivateMethodOverloadable {
private constructor(value: string);
private constructor(private: Private);
private method(value: string): string;
Expand All @@ -187,14 +187,14 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
private "stringOnly"(value: string): string;
private "stringOnly"(): string;
}
export declare module Test {
export module Test {
export class AmbientClassInModule {
private constructor(value: string);
private constructor(private: Private);
}
}
declare class Base {
}
export declare class TsPrivateMethodWithOverrideKeyword extends Base {
export class TsPrivateMethodWithOverrideKeyword extends Base {
private override test: any;
}
8 changes: 4 additions & 4 deletions tests/specs/graph/jsr/FastCheck_ClassProperties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
override foo!: string;
}
--- DTS ---
export declare class RedBlackNode<T> extends BinarySearchNode<T> {
export class RedBlackNode<T> extends BinarySearchNode<T> {
parent: RedBlackNode<T> | null;
left: RedBlackNode<T> | null;
right: RedBlackNode<T> | null;
Expand All @@ -132,14 +132,14 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
}
declare const isSecure: Symbol;
declare const public2: Symbol;
export declare class CookieMapBase {
export class CookieMapBase {
[isSecure]: boolean;
[public2](): number;
}
export declare class Bar {
export class Bar {
abstract foo: string;
bar: number;
}
export declare class Baz extends Bar {
export class Baz extends Bar {
override foo: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
}
--- DTS ---
import type { Foo, Bar } from "./b.ts";
export declare class Foo {
export class Foo {
fizz: (a: string) => string;
foo: () => Foo;
bar: (b: Bar) => number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
--- DTS ---
declare class Base {
}
export declare class WithTsPrivate extends Base {
export class WithTsPrivate extends Base {
private regular: any;
private override withOverride: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
declare static prop: string;
}
--- DTS ---
export declare class Export {
export class Export {
prop: typeof Public1.prop;
}
declare class Public1 {
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/graph/jsr/FastCheck_ClassSuper.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
declare class Base {
constructor(a: number, b: number);
}
export declare class Child extends Base {
export class Child extends Base {
constructor();
}
declare class SpreadBase {
constructor(...params: string[]);
}
export declare class SpreadChild extends SpreadBase {
export class SpreadChild extends SpreadBase {
constructor();
}
2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/FastCheck_Comments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
export const value1: number = {} as any;
--- DTS ---
// @ts-ignore broken line
export declare const value1: number;
export const value1: number;
4 changes: 2 additions & 2 deletions tests/specs/graph/jsr/FastCheck_CrossFileRefAliased.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/a.ts:
declare member: string;
}
--- DTS ---
export declare class A {
export class A {
member: string;
}

Expand Down Expand Up @@ -191,6 +191,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
}
--- DTS ---
import { B } from "./b.ts";
export declare class Export {
export class Export {
prop: typeof B.prototype.member;
}
2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/FastCheck_CrossFileRefImportType.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/a.ts:
--- DTS ---
export default class Test {
}
export declare class A {
export class A {
}

Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/graph/jsr/FastCheck_CrossFileRefModule.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/a.ts:
declare member2: string;
}
--- DTS ---
export declare class A {
export class A {
member: string;
member2: string;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
}
--- DTS ---
import * as mod from "./b.ts";
export declare class Export {
export class Export {
prop: typeof mod.B.prototype.member;
prop2: typeof mod.B.prototype.member2;
}
2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/FastCheck_DefaultExportExprVar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
export interface $Type {
prop: boolean;
}
export declare const $: $Type;
export const $: $Type;
export default $;
2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/FastCheck_Dts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.d.ts:
declare function random(): number;
declare var public: number;
--- DTS ---
export declare class Test {
export class Test {
prop: typeof random;
method(): typeof public;
static prop: number;
Expand Down
10 changes: 5 additions & 5 deletions tests/specs/graph/jsr/FastCheck_Enums.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
I = 1 + NUM
}
--- DTS ---
export declare enum EnumWithNoInits {
export enum EnumWithNoInits {
Value1,
Value2
}
export declare enum EnumWithNumInits {
export enum EnumWithNumInits {
Value1 = 1,
Value2 = 2
}
export declare enum EnumWithStringInits {
export enum EnumWithStringInits {
Value1 = "a",
Value2 = "b"
}
declare const value: number;
export declare enum EnumWithNonConstInits {
export enum EnumWithNonConstInits {
Value1,
Value2
}
Expand All @@ -157,7 +157,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
Value
}
declare const NUM: any;
export declare enum Foo1 {
export enum Foo1 {
A = 1,
B = "2",
C = 1 << 2,
Expand Down
12 changes: 6 additions & 6 deletions tests/specs/graph/jsr/FastCheck_Functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
export function test6<T = PublicOther>(param?: number): T;
export function test7(param?: number): number;
export function test7(param?: number, param2?: PublicOther2): number;
function test8(param: number): number;
function test8(param: string): string;
function test8(param0?: any): any;
declare function test8(param: number): number;
declare function test8(param: string): string;
declare function test8(param0?: any): any;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main fix is here
image

export { test8 };
export default function test9(param: number): number;
export default function test9(param: string): string;
Expand All @@ -214,6 +214,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
}
declare class PublicDeclareFunc {
}
export declare function declareFunc(param: number): number;
export declare function declareFunc(param: string): string;
export declare function declareFunc(param: PublicDeclareFunc): string;
export function declareFunc(param: number): number;
export function declareFunc(param: string): string;
export function declareFunc(param: PublicDeclareFunc): string;
2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/FastCheck_InferredUniqueSymbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
--- DTS ---
declare const key: unique symbol;
declare const key2: unique symbol;
export declare class MyClass {
export class MyClass {
[key]: number;
[key2]: string;
}
2 changes: 1 addition & 1 deletion tests/specs/graph/jsr/FastCheck_InitIdentsAndMembers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
export class A {
}
}
export declare const handlers: {
export const handlers: {
readonly Private;
readonly C;
};
Expand Down
Loading