feat: add extern let declarations for JS FFI
Add support for `extern let name: Type` and `extern let name: Type = "jsName"` syntax for declaring external JavaScript values. This follows the same pattern as extern fn across all compiler passes: parser, typechecker, interpreter (runtime error placeholder), JS backend (emits JS name directly without mangling), formatter, linter, modules, and symbol table. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
15
src/ast.rs
15
src/ast.rs
@@ -223,6 +223,8 @@ pub enum Declaration {
|
||||
Impl(ImplDecl),
|
||||
/// Extern function declaration (FFI): extern fn name(params): ReturnType
|
||||
ExternFn(ExternFnDecl),
|
||||
/// Extern let declaration (FFI): extern let name: Type
|
||||
ExternLet(ExternLetDecl),
|
||||
}
|
||||
|
||||
/// Function declaration
|
||||
@@ -445,6 +447,19 @@ pub struct ExternFnDecl {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Extern let declaration (FFI)
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ExternLetDecl {
|
||||
pub visibility: Visibility,
|
||||
/// Documentation comment
|
||||
pub doc: Option<String>,
|
||||
pub name: Ident,
|
||||
pub typ: TypeExpr,
|
||||
/// Optional JS name override: extern let foo: T = "window.foo"
|
||||
pub js_name: Option<String>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Type expressions
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum TypeExpr {
|
||||
|
||||
Reference in New Issue
Block a user