Crate tsrun

Crate tsrun 

Source
Expand description

TypeScript interpreter for config/manifest generation

§Example

use tsrun::{Runtime, StepResult};

let mut runtime = Runtime::new();
runtime.prepare("1 + 2 * 3", None).unwrap();

// Step until completion
loop {
    match runtime.step().unwrap() {
        StepResult::Continue => continue,
        StepResult::Complete(value) => {
            assert_eq!(value.as_number(), Some(7.0));
            break;
        }
        _ => panic!("Unexpected result"),
    }
}

Re-exports§

pub use error::JsError;
pub use gc::Gc;
pub use gc::GcStats;
pub use gc::Guard;
pub use gc::Heap;
pub use gc::Reset;
pub use string_dict::StringDict;
pub use value::CheapClone;
pub use value::EnvRef;
pub use value::Guarded;
pub use value::JsObject;
pub use value::JsString;
pub use value::JsValue;

Modules§

api
Public API for interacting with JavaScript values from Rust.
ast
Abstract Syntax Tree types for TypeScript
compiler
Bytecode compiler for TypeScript/JavaScript
error
Error types for the TypeScript interpreter
gc
Mark-and-sweep garbage collection system.
lexer
Lexer for TypeScript source code
parser
Parser for TypeScript source code
string_dict
String dictionary for deduplicating JsString instances.
value
JavaScript value representation

Structs§

ImportRequest
A pending import request with context about where it was requested from.
InternalModule
Definition of an internal module
Interpreter
The interpreter state
ModulePath
A normalized, absolute module path.
NativeModuleBuilder
Builder for creating native internal modules
Order
An order is a request for an external effect. The payload is a RuntimeValue that the host interprets to perform side effects. The RuntimeValue keeps the payload alive until the order is fulfilled or dropped.
OrderId
Unique identifier for an order
OrderResponse
Response to fulfill an order from the host
Runtime
The main runtime for executing TypeScript code
RuntimeConfig
Configuration for creating a Runtime
RuntimeValue
A JS value with an attached guard that keeps it alive until dropped.

Enums§

InternalExport
Definition of an export from an internal module
InternalModuleKind
How an internal module is defined
StepResult
Result of executing a single step.

Functions§

create_eval_internal_module
Create the eval:internal module
js_value_to_json
Convert a JsValue to JSON, with public API for external callers (without circular detection)
json_to_js_value_with_guard
Convert a serde_json value to a JsValue using a provided guard. The guard keeps any created objects alive until it is dropped. This is the preferred method when you need to control the lifetime of the result.
json_to_js_value_with_interp
Convert a serde_json value to a JsValue using the interpreter’s GC space

Type Aliases§

InternalFn
A native function that can be exported from an internal module