Files
scriptc/packages/compiler/ambient/node-fallback/string_decoder.d.ts
T
Chris Tate f0f91ac1ff Load a Node module's fallback declarations only when the program names it
Without @types/node, every program loaded scriptc-node-fallback.d.ts whole:
the console and process globals and 47 Node modules, about 8,100 lines,
parsed, bound and checked in every cold build whether or not the program
imported them.

- The fallback file keeps the globals and the modules they name (console,
  readline, readline/promises, perf_hooks, tty). Every other module, under
  both spellings, has its own file in ambient/node-fallback/, which
  references the files of the modules its declarations name.
- A module's file joins the program when one of the program's files names
  the module in a string literal: imports, requires, import types and JSDoc
  types all name modules that way. The entry is read before the first
  program; the program-root discovery passes add modules that other files
  name. Files are read as tsgo reads them, and the TypeScript libraries and
  scriptc's own declarations are skipped.
- The checks that recognized the fallback file by its path recognize every
  fallback file.
2026-10-25 15:36:08 -05:00

21 lines
833 B
TypeScript

/* node:string_decoder — StringDecoder over Node's whole encoding set:
* write() decodes complete sequences and buffers a trailing partial one
* across chunk boundaries (utf8's truncated sequence, base64's mod-3
* remainder, utf16le's odd byte / trailing lead surrogate; latin1, ascii
* and hex are stateless); end() flushes the buffered partial. `encoding`
* answers the normalized name. Node's exact algorithms (SEMANTICS.md);
* the encoding must be a literal, and end(buffer) fences — write the
* buffer, then end(). */
declare module "string_decoder" {
export class StringDecoder {
constructor(encoding?: BufferEncoding);
readonly encoding: string;
write(buffer: Uint8Array): string;
end(buffer?: Uint8Array): string;
}
}
declare module "node:string_decoder" {
export * from "string_decoder";
}