|
| 1 | +/// <reference path="./assemblyscript.generated.d.ts" /> |
| 2 | +declare module "types:assemblyscript/util/options" { |
| 3 | + /** |
| 4 | + * @fileoverview Command line options utility definitions. |
| 5 | + * @license Apache-2.0 |
| 6 | + */ |
| 7 | + /** A set of options. */ |
| 8 | + export interface OptionSet { |
| 9 | + [key: string]: number | string; |
| 10 | + } |
| 11 | + /** Command line option description. */ |
| 12 | + export interface OptionDescription { |
| 13 | + /** Textual description. */ |
| 14 | + description?: string | string[]; |
| 15 | + /** Data type. One of (b)oolean [default], (i)nteger, (f)loat or (s)tring. Uppercase means multiple values. */ |
| 16 | + type?: "b" | "i" | "f" | "s" | "I" | "F" | "S"; |
| 17 | + /** Substituted options, if any. */ |
| 18 | + value?: OptionSet; |
| 19 | + /** Short alias, if any. */ |
| 20 | + alias?: string; |
| 21 | + /** The default value, if any. */ |
| 22 | + default?: string | number | boolean | string[] | number[]; |
| 23 | + /** The category this option belongs in. */ |
| 24 | + category?: string; |
| 25 | + } |
| 26 | + /** Configuration object. */ |
| 27 | + export interface Config { |
| 28 | + [key: string]: OptionDescription; |
| 29 | + } |
| 30 | + /** Parsing result. */ |
| 31 | + export interface Result { |
| 32 | + /** Parsed options. */ |
| 33 | + options: OptionSet; |
| 34 | + /** Unknown options. */ |
| 35 | + unknown: string[]; |
| 36 | + /** Normal arguments. */ |
| 37 | + arguments: string[]; |
| 38 | + /** Trailing arguments. */ |
| 39 | + trailing: string[]; |
| 40 | + } |
| 41 | + /** Parses the specified command line arguments according to the given configuration. */ |
| 42 | + export function parse(argv: string[], config: Config, propagateDefaults?: boolean): Result; |
| 43 | + /** Help formatting options. */ |
| 44 | + export interface HelpOptions { |
| 45 | + /** Leading indent. Defaults to 2. */ |
| 46 | + indent?: number; |
| 47 | + /** Table padding. Defaults to 24. */ |
| 48 | + padding?: number; |
| 49 | + /** End of line character. Defaults to "\n". */ |
| 50 | + eol?: string; |
| 51 | + } |
| 52 | + /** Generates the help text for the specified configuration. */ |
| 53 | + export function help(config: Config, options?: HelpOptions): string; |
| 54 | + /** Merges two sets of options into one, preferring the current over the parent set. */ |
| 55 | + export function merge(config: Config, currentOptions: OptionSet, parentOptions: OptionSet, parentBaseDir: string): OptionSet; |
| 56 | + /** Normalizes a path. */ |
| 57 | + export function normalizePath(path: string): string; |
| 58 | + /** Resolves a single relative path. Keeps absolute paths, otherwise prepends baseDir. */ |
| 59 | + export function resolvePath(path: string, baseDir: string, useNodeResolution?: boolean): string; |
| 60 | + /** Populates default values on a parsed options result. */ |
| 61 | + export function addDefaults(config: Config, options: OptionSet): void; |
| 62 | +} |
| 63 | +declare module "types:assemblyscript/cli/index" { |
| 64 | + /** |
| 65 | + * @fileoverview Definitions for asc. |
| 66 | + * @license Apache-2.0 |
| 67 | + */ |
| 68 | + import { OptionDescription } from "types:assemblyscript/util/options"; |
| 69 | + export { OptionDescription }; |
| 70 | + /** AssemblyScript version. */ |
| 71 | + export const version: string; |
| 72 | + /** Available CLI options. */ |
| 73 | + export const options: { |
| 74 | + [key: string]: OptionDescription; |
| 75 | + }; |
| 76 | + /** Prefix used for library files. */ |
| 77 | + export const libraryPrefix: string; |
| 78 | + /** Bundled library files. */ |
| 79 | + export const libraryFiles: { |
| 80 | + [key: string]: string; |
| 81 | + }; |
| 82 | + /** Bundled definition files. */ |
| 83 | + export const definitionFiles: { |
| 84 | + assembly: string; |
| 85 | + portable: string; |
| 86 | + }; |
| 87 | + /** Default Binaryen optimization level. */ |
| 88 | + export const defaultOptimizeLevel: number; |
| 89 | + /** Default Binaryen shrink level. */ |
| 90 | + export const defaultShrinkLevel: number; |
| 91 | + /** A compatible output stream. */ |
| 92 | + export interface OutputStream { |
| 93 | + /** Writes a chunk of data to the stream. */ |
| 94 | + write(chunk: Uint8Array | string): void; |
| 95 | + } |
| 96 | + /** An in-memory output stream. */ |
| 97 | + export interface MemoryStream extends OutputStream { |
| 98 | + /** Resets the stream to offset zero. */ |
| 99 | + reset(): void; |
| 100 | + /** Converts the output to a buffer. */ |
| 101 | + toBuffer(): Uint8Array; |
| 102 | + /** Converts the output to a string. */ |
| 103 | + toString(): string; |
| 104 | + } |
| 105 | + /** Relevant subset of the Source class for diagnostic reporting. */ |
| 106 | + export interface Source { |
| 107 | + /** Normalized path with file extension. */ |
| 108 | + normalizedPath: string; |
| 109 | + } |
| 110 | + /** Relevant subset of the Range class for diagnostic reporting. */ |
| 111 | + export interface Range { |
| 112 | + /** Start offset within the source file. */ |
| 113 | + start: number; |
| 114 | + /** End offset within the source file. */ |
| 115 | + end: number; |
| 116 | + /** Respective source file. */ |
| 117 | + source: Source; |
| 118 | + } |
| 119 | + /** Relevant subset of the DiagnosticMessage class for diagnostic reporting. */ |
| 120 | + export interface DiagnosticMessage { |
| 121 | + /** Message code. */ |
| 122 | + code: number; |
| 123 | + /** Message category. */ |
| 124 | + category: number; |
| 125 | + /** Message text. */ |
| 126 | + message: string; |
| 127 | + /** Respective source range, if any. */ |
| 128 | + range: Range | null; |
| 129 | + /** Related range, if any. */ |
| 130 | + relatedRange: Range | null; |
| 131 | + } |
| 132 | + /** A function handling diagnostic messages. */ |
| 133 | + type DiagnosticReporter = (diagnostic: DiagnosticMessage) => void; |
| 134 | + /** Compiler options. */ |
| 135 | + export interface CompilerOptions { |
| 136 | + /** Prints just the compiler's version and exits. */ |
| 137 | + version?: boolean; |
| 138 | + /** Prints the help message and exits. */ |
| 139 | + help?: boolean; |
| 140 | + /** Optimizes the module. */ |
| 141 | + optimize?: boolean; |
| 142 | + /** How much to focus on optimizing code. */ |
| 143 | + optimizeLevel?: number; |
| 144 | + /** How much to focus on shrinking code size. */ |
| 145 | + shrinkLevel?: number; |
| 146 | + /** Re-optimizes until no further improvements can be made. */ |
| 147 | + converge?: boolean; |
| 148 | + /** Specifies the base directory of input and output files. */ |
| 149 | + baseDir?: string; |
| 150 | + /** Specifies the WebAssembly output file (.wasm). */ |
| 151 | + outFile?: string; |
| 152 | + /** Specifies the WebAssembly text output file (.wat). */ |
| 153 | + textFile?: string; |
| 154 | + /** Specified the bindings to generate. */ |
| 155 | + bindings?: string[]; |
| 156 | + /** Enables source map generation. Optionally takes the URL. */ |
| 157 | + sourceMap?: boolean | string; |
| 158 | + /** Specifies the runtime variant to include in the program. */ |
| 159 | + runtime?: string; |
| 160 | + /** Disallows the use of unsafe features in user code. */ |
| 161 | + noUnsafe?: boolean; |
| 162 | + /** Enables debug information in emitted binaries. */ |
| 163 | + debug?: boolean; |
| 164 | + /** Replaces assertions with just their value without trapping. */ |
| 165 | + noAssert?: boolean; |
| 166 | + /** Performs compilation as usual but does not emit code. */ |
| 167 | + noEmit?: boolean; |
| 168 | + /** Imports the memory provided as 'env.memory'. */ |
| 169 | + importMemory?: boolean; |
| 170 | + /** Does not export the memory as 'memory'. */ |
| 171 | + noExportMemory?: boolean; |
| 172 | + /** Sets the initial memory size in pages. */ |
| 173 | + initialMemory?: number; |
| 174 | + /** Sets the maximum memory size in pages. */ |
| 175 | + maximumMemory?: number; |
| 176 | + /** Declare memory as shared. Requires maximumMemory. */ |
| 177 | + sharedMemory?: boolean; |
| 178 | + /** Assume that imported memory is zero filled. Requires importMemory. */ |
| 179 | + zeroFilledMemory?: boolean; |
| 180 | + /** Sets the start offset of compiler-generated static memory. */ |
| 181 | + memoryBase?: number; |
| 182 | + /** Imports the function table provided as 'env.table'. */ |
| 183 | + importTable?: boolean; |
| 184 | + /** Exports the function table as 'table'. */ |
| 185 | + exportTable?: boolean; |
| 186 | + /** Exports the start function instead of calling it implicitly. */ |
| 187 | + exportStart?: string; |
| 188 | + /** "Adds one or multiple paths to custom library components. */ |
| 189 | + lib?: string | string[]; |
| 190 | + /** Adds one or multiple paths to package resolution. */ |
| 191 | + path?: string | string[]; |
| 192 | + /** Aliases a global object under another name. */ |
| 193 | + use?: string | string[]; |
| 194 | + /** Sets the trap mode to use. */ |
| 195 | + trapMode?: "allow" | "clamp" | "js"; |
| 196 | + /** Specifies additional Binaryen passes to run. */ |
| 197 | + runPasses?: string | string[]; |
| 198 | + /** Skips validating the module using Binaryen. */ |
| 199 | + noValidate?: boolean; |
| 200 | + /** Enables WebAssembly features that are disabled by default. */ |
| 201 | + enable?: string | string[]; |
| 202 | + /** Disables WebAssembly features that are enabled by default. */ |
| 203 | + disable?: string | string[]; |
| 204 | + /** Specifies the path to a custom transform to 'require'. */ |
| 205 | + transform?: string | string[]; |
| 206 | + /** Make yourself sad for no good reason. */ |
| 207 | + pedantic?: boolean; |
| 208 | + /** Prints measuring information on I/O and compile times. */ |
| 209 | + stats?: boolean; |
| 210 | + /** Disables terminal colors. */ |
| 211 | + noColors?: boolean; |
| 212 | + } |
| 213 | + /** Compiler API options. */ |
| 214 | + export interface APIOptions { |
| 215 | + /** Standard output stream to use. */ |
| 216 | + stdout?: OutputStream; |
| 217 | + /** Standard error stream to use. */ |
| 218 | + stderr?: OutputStream; |
| 219 | + /** Reads a file from disk (or memory). */ |
| 220 | + readFile?: (filename: string, baseDir: string) => (string | null) | Promise<string | null>; |
| 221 | + /** Writes a file to disk (or memory). */ |
| 222 | + writeFile?: (filename: string, contents: Uint8Array, baseDir: string) => void | Promise<void>; |
| 223 | + /** Lists all files within a directory. */ |
| 224 | + listFiles?: (dirname: string, baseDir: string) => (string[] | null) | Promise<string[] | null>; |
| 225 | + /** Handler for diagnostic messages. */ |
| 226 | + reportDiagnostic?: DiagnosticReporter; |
| 227 | + /** Additional transforms to apply. */ |
| 228 | + transforms?: Transform[]; |
| 229 | + } |
| 230 | + /** Compiler API result. */ |
| 231 | + export interface APIResult { |
| 232 | + /** Encountered error, if any. */ |
| 233 | + error: Error | null; |
| 234 | + /** Standard output stream. */ |
| 235 | + stdout: OutputStream; |
| 236 | + /** Standard error stream. */ |
| 237 | + stderr: OutputStream; |
| 238 | + /** Statistics. */ |
| 239 | + stats: Stats; |
| 240 | + } |
| 241 | + /** Runs the command line utility using the specified arguments array. */ |
| 242 | + export function main(argv: string[] | CompilerOptions, options?: APIOptions): Promise<APIResult>; |
| 243 | + /** Convenience function that parses and compiles source strings directly. */ |
| 244 | + export function compileString(sources: { |
| 245 | + [key: string]: string; |
| 246 | + } | string, options?: CompilerOptions): Promise<APIResult & { |
| 247 | + /** Emitted binary. */ |
| 248 | + binary: Uint8Array | null; |
| 249 | + /** Emitted text format. */ |
| 250 | + text: string | null; |
| 251 | + }>; |
| 252 | + /** Checks diagnostics emitted so far for errors. */ |
| 253 | + export function checkDiagnostics(emitter: Record<string, unknown>, stderr?: OutputStream, reportDiagnostic?: DiagnosticReporter, useColors?: boolean): boolean; |
| 254 | + /** Statistics for the current task. */ |
| 255 | + export class Stats { |
| 256 | + /** Number of files read. */ |
| 257 | + readCount: number; |
| 258 | + /** Number of files written. */ |
| 259 | + writeCount: number; |
| 260 | + /** Time taken to parse files. */ |
| 261 | + parseTime: number; |
| 262 | + /** Number of files parsed. */ |
| 263 | + parseCount: number; |
| 264 | + /** Time taken to compile programs. */ |
| 265 | + compileTime: number; |
| 266 | + /** Number of programs compiled. */ |
| 267 | + compileCount: number; |
| 268 | + /** Time taken to emit files. */ |
| 269 | + emitTime: number; |
| 270 | + /** Number of emitted files. */ |
| 271 | + emitCount: number; |
| 272 | + /** Time taken to validate modules. */ |
| 273 | + validateTime: number; |
| 274 | + /** Number of modules validated. */ |
| 275 | + validateCount: number; |
| 276 | + /** Time taken to optimize modules. */ |
| 277 | + optimizeTime: number; |
| 278 | + /** Number of modules optimized. */ |
| 279 | + optimizeCount: number; |
| 280 | + /** Begins measuring execution time. */ |
| 281 | + begin(): number; |
| 282 | + /** Ends measuring execution time since `begin`. */ |
| 283 | + end(begin: number): number; |
| 284 | + /** Returns a string representation. */ |
| 285 | + toString(): string; |
| 286 | + } |
| 287 | + /** Creates a memory stream that can be used in place of stdout/stderr. */ |
| 288 | + export function createMemoryStream(fn?: (chunk: Uint8Array | string) => void): MemoryStream; |
| 289 | + /** Compatible TypeScript compiler options for syntax highlighting etc. */ |
| 290 | + export const tscOptions: Record<string, unknown>; |
| 291 | + import { Program, Parser, Module } from "types:assemblyscript/src/index"; |
| 292 | + /** Compiler transform base class. */ |
| 293 | + export abstract class Transform { |
| 294 | + /** Program reference. */ |
| 295 | + readonly program: Program; |
| 296 | + /** Base directory. */ |
| 297 | + readonly baseDir: string; |
| 298 | + /** Output stream used by the compiler. */ |
| 299 | + readonly stdout: OutputStream; |
| 300 | + /** Error stream used by the compiler. */ |
| 301 | + readonly stderr: OutputStream; |
| 302 | + /** Logs a message to console. */ |
| 303 | + readonly log: typeof console.log; |
| 304 | + /** Reads a file from disk. */ |
| 305 | + readFile(filename: string, baseDir: string): (string | null) | Promise<string | null>; |
| 306 | + /** Writes a file to disk. */ |
| 307 | + writeFile(filename: string, contents: string | Uint8Array, baseDir: string): void | Promise<void>; |
| 308 | + /** Lists all files in a directory. */ |
| 309 | + listFiles(dirname: string, baseDir: string): (string[] | null) | Promise<string[] | null>; |
| 310 | + /** Called when parsing is complete, before a program is instantiated from the AST. */ |
| 311 | + afterParse?(parser: Parser): void | Promise<void>; |
| 312 | + /** Called after the program is instantiated. */ |
| 313 | + afterInitialize?(program: Program): void | Promise<void>; |
| 314 | + /** Called when compilation is complete, before the module is being validated. */ |
| 315 | + afterCompile?(module: Module): void | Promise<void>; |
| 316 | + } |
| 317 | +} |
0 commit comments