Skip to main content

shape_ext_typescript/
lib.rs

1//! Shape TypeScript language runtime extension.
2//!
3//! Provides a `shape.language_runtime` capability that embeds V8 via deno_core
4//! for executing `foreign "typescript" { ... }` blocks in Shape programs.
5//!
6//! # ABI Exports
7//!
8//! All C ABI exports (`shape_plugin_info`, `shape_abi_version`,
9//! `shape_capability_manifest`, `shape_capability_vtable`,
10//! `shape_language_runtime_vtable`) are generated by the
11//! [`shape_abi_v1::language_runtime_plugin!`] macro below.
12
13pub mod error_mapping;
14pub mod marshaling;
15pub mod runtime;
16
17/// Bundled `.shape` module artifact for the `typescript` namespace.
18///
19/// This source is embedded in the extension binary and registered under the
20/// `"typescript"` namespace (NOT `"std::core::typescript"`) when the extension
21/// is loaded. Users import it via `import { eval } from typescript`.
22const TYPESCRIPT_SHAPE_SOURCE: &str = r#"/// @module typescript
23/// TypeScript interop runtime — provides access to the embedded V8 engine.
24///
25/// This module is bundled with the TypeScript language runtime extension and
26/// is only available when the extension is loaded. It does NOT live in `std::*`.
27
28/// Evaluate a TypeScript/JavaScript expression and return its result.
29///
30/// The expression is compiled (TS is transpiled to JS) and executed in the
31/// extension's embedded V8 isolate. The result is marshalled back to a Shape
32/// value.
33pub builtin fn eval(code: string) -> _
34
35/// Import a JavaScript/TypeScript module by specifier and return it.
36///
37/// The module is resolved and loaded in the V8 runtime. The returned handle
38/// provides access to the module's exports.
39pub builtin fn import(specifier: string) -> _
40"#;
41
42shape_abi_v1::language_runtime_plugin! {
43    name: c"typescript",
44    version: c"0.1.0",
45    description: c"TypeScript language runtime for foreign function blocks (V8 via deno_core)",
46    shape_source: TYPESCRIPT_SHAPE_SOURCE,
47    vtable: {
48        init: runtime::ts_init,
49        register_types: runtime::ts_register_types,
50        compile: runtime::ts_compile,
51        invoke: runtime::ts_invoke,
52        dispose_function: runtime::ts_dispose_function,
53        language_id: runtime::ts_language_id,
54        get_lsp_config: runtime::ts_get_lsp_config,
55        free_buffer: runtime::ts_free_buffer,
56        drop: runtime::ts_drop,
57    }
58}