pub struct WasmProgram { /* private fields */ }Expand description
Multi-file TypeScript program for cross-file type checking.
This struct provides an API for compiling multiple TypeScript files together, enabling proper module resolution and cross-file type checking.
§Example (JavaScript)
const program = new WasmProgram();
program.addFile("a.ts", "export const x = 1;");
program.addFile("b.ts", "import { x } from './a'; const y = x + 1;");
const result = program.checkAll();
console.log(result);Implementations§
Source§impl WasmProgram
impl WasmProgram
Sourcepub fn add_file(&mut self, file_name: String, source_text: String)
pub fn add_file(&mut self, file_name: String, source_text: String)
Add a file to the program.
Files are accumulated and compiled together when checkAll is called.
The file_name should be a relative path like “src/a.ts”.
For TypeScript library files (lib.d.ts, lib.dom.d.ts, etc.), use addLibFile instead.
Sourcepub fn add_lib_file(&mut self, file_name: String, source_text: String)
pub fn add_lib_file(&mut self, file_name: String, source_text: String)
Add a TypeScript library file (lib.d.ts, lib.dom.d.ts, etc.) to the program.
Lib files are used for global symbol resolution and are merged into the symbol table before user files are processed.
Use this method explicitly instead of relying on automatic file name detection. This makes the API behavior predictable and explicit.
§Example (JavaScript)
const program = new WasmProgram();
program.addLibFile("lib.d.ts", libContent);
program.addFile("src/a.ts", userCode);Sourcepub fn get_file_count(&self) -> usize
pub fn get_file_count(&self) -> usize
Get the number of files in the program.
Sourcepub fn check_all(&mut self) -> String
pub fn check_all(&mut self) -> String
Compile all files and return diagnostics as JSON.
This performs:
- Load lib files for global symbol resolution
- Parallel parsing of all files
- Parallel binding of all files with lib symbols merged
- Symbol merging (sequential)
- Parallel type checking
Returns a JSON object with diagnostics per file.
Sourcepub fn get_diagnostic_codes(&mut self) -> String
pub fn get_diagnostic_codes(&mut self) -> String
Get diagnostic codes for all files (for conformance testing).
Returns a JSON object mapping file names to arrays of error codes.
Sourcepub fn get_all_diagnostic_codes(&mut self) -> Vec<u32>
pub fn get_all_diagnostic_codes(&mut self) -> Vec<u32>
Get all diagnostic codes as a flat array (for simple conformance comparison).
This combines all parse and check diagnostics from all files into a single array of error codes, which can be compared against tsc output.
Trait Implementations§
Source§impl Default for WasmProgram
impl Default for WasmProgram
Source§impl From<WasmProgram> for JsValue
impl From<WasmProgram> for JsValue
Source§fn from(value: WasmProgram) -> Self
fn from(value: WasmProgram) -> Self
Source§impl FromWasmAbi for WasmProgram
impl FromWasmAbi for WasmProgram
Source§impl IntoWasmAbi for WasmProgram
impl IntoWasmAbi for WasmProgram
Source§impl LongRefFromWasmAbi for WasmProgram
impl LongRefFromWasmAbi for WasmProgram
Source§impl OptionFromWasmAbi for WasmProgram
impl OptionFromWasmAbi for WasmProgram
Source§impl OptionIntoWasmAbi for WasmProgram
impl OptionIntoWasmAbi for WasmProgram
Source§impl RefFromWasmAbi for WasmProgram
impl RefFromWasmAbi for WasmProgram
Source§type Anchor = RcRef<WasmProgram>
type Anchor = RcRef<WasmProgram>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for WasmProgram
impl RefMutFromWasmAbi for WasmProgram
Source§impl TryFromJsValue for WasmProgram
impl TryFromJsValue for WasmProgram
Source§impl VectorFromWasmAbi for WasmProgram
impl VectorFromWasmAbi for WasmProgram
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[WasmProgram]>
Source§impl VectorIntoWasmAbi for WasmProgram
impl VectorIntoWasmAbi for WasmProgram
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[WasmProgram]>) -> Self::Abi
Source§impl WasmDescribeVector for WasmProgram
impl WasmDescribeVector for WasmProgram
impl SupportsConstructor for WasmProgram
impl SupportsInstanceProperty for WasmProgram
impl SupportsStaticProperty for WasmProgram
Auto Trait Implementations§
impl !Freeze for WasmProgram
impl !RefUnwindSafe for WasmProgram
impl Send for WasmProgram
impl Sync for WasmProgram
impl Unpin for WasmProgram
impl UnsafeUnpin for WasmProgram
impl UnwindSafe for WasmProgram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.