From 3204092732f38483f8a45fd500a6531511c602f7 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 25 Sep 2020 16:21:34 +0200 Subject: [PATCH] refactor: class instead of var+interface in d.ts (#7514) --- .dprintrc.json | 7 +- cli/dts/lib.deno.shared_globals.d.ts | 328 ++++++++++++--------------- op_crates/fetch/lib.deno_fetch.d.ts | 189 ++++++++++----- 3 files changed, 278 insertions(+), 246 deletions(-) diff --git a/.dprintrc.json b/.dprintrc.json index 204bbd1f63..4cdfdc6fa4 100644 --- a/.dprintrc.json +++ b/.dprintrc.json @@ -13,7 +13,12 @@ "includes": ["**/*.{ts,tsx,js,jsx,json,md}"], "excludes": [ ".cargo_home", - "cli/dts", + "cli/dts/lib.d.ts", + "cli/dts/lib.dom*", + "cli/dts/lib.es*", + "cli/dts/lib.scripthost.d.ts", + "cli/dts/lib.webworker*.d.ts", + "cli/dts/typescript.d.ts", "cli/tests/encoding", "cli/tsc/*typescript.js", "gh-pages", diff --git a/cli/dts/lib.deno.shared_globals.d.ts b/cli/dts/lib.deno.shared_globals.d.ts index 0d55b84a20..9f40e2521f 100644 --- a/cli/dts/lib.deno.shared_globals.d.ts +++ b/cli/dts/lib.deno.shared_globals.d.ts @@ -8,128 +8,111 @@ /// declare namespace WebAssembly { - interface CompileError { - } + export class CompileError { + constructor(); + } - var CompileError: { - prototype: CompileError; - new(): CompileError; - }; + export class Global { + constructor(descriptor: GlobalDescriptor, v?: any); - interface Global { - value: any; - valueOf(): any; - } + value: any; + valueOf(): any; + } - var Global: { - prototype: Global; - new(descriptor: GlobalDescriptor, v?: any): Global; - }; + export class Instance { + constructor(module: Module, importObject?: Imports); + readonly exports: Exports; + } - interface Instance { - readonly exports: Exports; - } + export class LinkError { + constructor(); + } - var Instance: { - prototype: Instance; - new(module: Module, importObject?: Imports): Instance; - }; + export class Memory { + constructor(descriptor: MemoryDescriptor); + readonly buffer: ArrayBuffer; + grow(delta: number): number; + } - interface LinkError { - } + export class Module { + constructor(bytes: BufferSource); + static customSections( + moduleObject: Module, + sectionName: string, + ): ArrayBuffer[]; + static exports(moduleObject: Module): ModuleExportDescriptor[]; + static imports(moduleObject: Module): ModuleImportDescriptor[]; + } - var LinkError: { - prototype: LinkError; - new(): LinkError; - }; + export class RuntimeError { + constructor(); + } - interface Memory { - readonly buffer: ArrayBuffer; - grow(delta: number): number; - } + export class Table { + constructor(descriptor: TableDescriptor); + readonly length: number; + get(index: number): Function | null; + grow(delta: number): number; + set(index: number, value: Function | null): void; + } - var Memory: { - prototype: Memory; - new(descriptor: MemoryDescriptor): Memory; - }; + export interface GlobalDescriptor { + mutable?: boolean; + value: ValueType; + } - interface Module { - } + export interface MemoryDescriptor { + initial: number; + maximum?: number; + } - var Module: { - prototype: Module; - new(bytes: BufferSource): Module; - customSections(moduleObject: Module, sectionName: string): ArrayBuffer[]; - exports(moduleObject: Module): ModuleExportDescriptor[]; - imports(moduleObject: Module): ModuleImportDescriptor[]; - }; + export interface ModuleExportDescriptor { + kind: ImportExportKind; + name: string; + } - interface RuntimeError { - } + export interface ModuleImportDescriptor { + kind: ImportExportKind; + module: string; + name: string; + } - var RuntimeError: { - prototype: RuntimeError; - new(): RuntimeError; - }; + export interface TableDescriptor { + element: TableKind; + initial: number; + maximum?: number; + } - interface Table { - readonly length: number; - get(index: number): Function | null; - grow(delta: number): number; - set(index: number, value: Function | null): void; - } + export interface WebAssemblyInstantiatedSource { + instance: Instance; + module: Module; + } - var Table: { - prototype: Table; - new(descriptor: TableDescriptor): Table; - }; - - interface GlobalDescriptor { - mutable?: boolean; - value: ValueType; - } - - interface MemoryDescriptor { - initial: number; - maximum?: number; - } - - interface ModuleExportDescriptor { - kind: ImportExportKind; - name: string; - } - - interface ModuleImportDescriptor { - kind: ImportExportKind; - module: string; - name: string; - } - - interface TableDescriptor { - element: TableKind; - initial: number; - maximum?: number; - } - - interface WebAssemblyInstantiatedSource { - instance: Instance; - module: Module; - } - - type ImportExportKind = "function" | "global" | "memory" | "table"; - type TableKind = "anyfunc"; - type ValueType = "f32" | "f64" | "i32" | "i64"; - type ExportValue = Function | Global | Memory | Table; - type Exports = Record; - type ImportValue = ExportValue | number; - type ModuleImports = Record; - type Imports = Record; - function compile(bytes: BufferSource): Promise; - function compileStreaming(source: Response | Promise): Promise; - function instantiate(bytes: BufferSource, importObject?: Imports): Promise; - function instantiate(moduleObject: Module, importObject?: Imports): Promise; - function instantiateStreaming(response: Response | PromiseLike, importObject?: Imports): Promise; - function validate(bytes: BufferSource): boolean; + export type ImportExportKind = "function" | "global" | "memory" | "table"; + export type TableKind = "anyfunc"; + export type ValueType = "f32" | "f64" | "i32" | "i64"; + export type ExportValue = Function | Global | Memory | Table; + export type Exports = Record; + export type ImportValue = ExportValue | number; + export type ModuleImports = Record; + export type Imports = Record; + export function compile(bytes: BufferSource): Promise; + export function compileStreaming( + source: Response | Promise, + ): Promise; + export function instantiate( + bytes: BufferSource, + importObject?: Imports, + ): Promise; + export function instantiate( + moduleObject: Module, + importObject?: Imports, + ): Promise; + export function instantiateStreaming( + response: Response | PromiseLike, + importObject?: Imports, + ): Promise; + export function validate(bytes: BufferSource): boolean; } /** Sets a timer which executes a function once after the timer expires. Returns @@ -286,35 +269,12 @@ declare interface Crypto { ): T; } +declare class URLSearchParams { + constructor( + init?: string[][] | Record | string | URLSearchParams, + ); + static toString(): string; -interface ResponseInit { - headers?: HeadersInit; - status?: number; - statusText?: string; -} - -type ResponseType = - | "basic" - | "cors" - | "default" - | "error" - | "opaque" - | "opaqueredirect"; - -/** This Fetch API interface represents the response to a request. */ -interface Response extends Body { - readonly headers: Headers; - readonly ok: boolean; - readonly redirected: boolean; - readonly status: number; - readonly statusText: string; - readonly trailer: Promise; - readonly type: ResponseType; - readonly url: string; - clone(): Response; -} - -interface URLSearchParams { /** Appends a specified key/value pair as a new search parameter. * * ```ts @@ -456,16 +416,12 @@ interface URLSearchParams { toString(): string; } -declare const URLSearchParams: { - prototype: URLSearchParams; - new ( - init?: string[][] | Record | string | URLSearchParams, - ): URLSearchParams; - toString(): string; -}; - /** The URL interface represents an object providing static methods used for creating object URLs. */ -interface URL { +declare class URL { + constructor(url: string, base?: string | URL); + createObjectURL(object: any): string; + revokeObjectURL(url: string): void; + hash: string; host: string; hostname: string; @@ -482,13 +438,6 @@ interface URL { toJSON(): string; } -declare const URL: { - prototype: URL; - new (url: string, base?: string | URL): URL; - createObjectURL(object: any): string; - revokeObjectURL(url: string): void; -}; - interface MessageEventInit extends EventInit { data?: any; origin?: string; @@ -593,7 +542,9 @@ declare class Worker extends EventTarget { declare type PerformanceEntryList = PerformanceEntry[]; -declare interface Performance { +declare class Performance { + constructor(); + /** Removes the stored timestamp with the associated name. */ clearMarks(markName?: string): void; @@ -633,11 +584,6 @@ declare interface Performance { now(): number; } -declare const Performance: { - prototype: Performance; - new (): Performance; -}; - declare const performance: Performance; declare interface PerformanceMarkOptions { @@ -697,19 +643,15 @@ declare class PerformanceMeasure extends PerformanceEntry { /** Events measuring progress of an underlying process, like an HTTP request * (for an XMLHttpRequest, or the loading of the underlying resource of an * ,