1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Real `TypeScript` type-stripping for guest functions.
//!
//! `deno_ast` (`swc` underneath) parses the guest as `TypeScript` and emits plain
//! `JavaScript` with the `TypeScript`-only constructs removed or lowered, so an
//! author can write ordinary `.ts` — `interface`, `: Type`, generics, `as`,
//! `enum`, parameter properties — instead of restricting themselves to the
//! type-annotation-free subset that V8 accepts directly.
//!
//! This is a real `AST` transpile, not a string munge: `enum`s become runtime
//! objects, parameter properties expand to assignments, and the emitted code
//! carries an inline source map so a runtime stack trace still points back into
//! the author's original source. It is only reached when
//! [`DenoConfig::enable_typescript`](super::DenoConfig::enable_typescript) is
//! set (the default); with it off the `JavaScript` is executed byte-for-byte
//! unchanged.
use ;
/// The synthetic specifier the guest source is parsed under. It surfaces in
/// syntax-error messages and the inline source map as
/// `file:///fraiseql-function.ts:<line>:<col>`.
const GUEST_SPECIFIER: &str = "file:///fraiseql-function.ts";
/// Strip `TypeScript` types from `source`, returning executable `JavaScript`.
///
/// The returned `JavaScript` preserves ES module syntax (an author's
/// `export default` survives, so the wrapper can still find the entry point)
/// and carries an inline source map back to the original source.
///
/// # Errors
///
/// Returns a `SyntaxError: …`-prefixed string — including the offending line and
/// column — when the source does not parse or cannot be transpiled. The prefix
/// matches the classification the executor already applies to malformed guests,
/// so an untranspilable function dead-letters as a permanent 4xx rather than
/// being retried.