diff --git a/nix-js/runtime-ts/tsconfig.json b/nix-js/runtime-ts/tsconfig.json index 3bd1cc1..b4bb5e7 100644 --- a/nix-js/runtime-ts/tsconfig.json +++ b/nix-js/runtime-ts/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "target": "ES2020", + "target": "ES2022", "module": "ESNext", - "lib": ["ES2020", "DOM"], + "lib": ["ES2022", "DOM"], "moduleResolution": "bundler", "strict": true, "noUnusedLocals": false, diff --git a/nix-js/src/codegen.rs b/nix-js/src/codegen.rs index 5634993..bfe6c30 100644 --- a/nix-js/src/codegen.rs +++ b/nix-js/src/codegen.rs @@ -65,7 +65,11 @@ impl Compile for Ir { Ir::Builtin(_) => "Nix.builtins".to_string(), Ir::ConcatStrings(x) => x.compile(ctx), Ir::HasAttr(x) => x.compile(ctx), - ir => todo!("{ir:?}"), + &Ir::Assert(Assert { assertion, expr }) => { + let assertion = ctx.get_ir(assertion).compile(ctx); + let expr = ctx.get_ir(expr).compile(ctx); + format!("({assertion})?({expr}):(()=>{{throw \"assertion failed\"}})()") + } } } } diff --git a/nix-js/src/ir.rs b/nix-js/src/ir.rs index d9ddbd2..c231245 100644 --- a/nix-js/src/ir.rs +++ b/nix-js/src/ir.rs @@ -50,7 +50,6 @@ ir! { Select, If, Call, - With, Assert, ConcatStrings, Const, @@ -59,7 +58,6 @@ ir! { Func, Let, Arg(ArgId), - PrimOp(PrimOpId), ExprRef(ExprId), Thunk(ExprId), Builtin, @@ -150,10 +148,6 @@ pub struct ExprId(pub usize); pub type SymId = SymbolU32; -#[repr(transparent)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct PrimOpId(pub usize); - #[repr(transparent)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct ArgId(pub usize); @@ -342,15 +336,6 @@ pub struct Call { pub arg: ExprId, } -/// Represents a `with` expression. -#[derive(Debug)] -pub struct With { - /// The namespace to bring into scope. - pub namespace: ExprId, - /// The expression to be evaluated within the new scope. - pub expr: ExprId, -} - /// Represents an `assert` expression. #[derive(Debug)] pub struct Assert { diff --git a/nix-js/src/runtime.rs b/nix-js/src/runtime.rs index dc2b3ab..28c9a2c 100644 --- a/nix-js/src/runtime.rs +++ b/nix-js/src/runtime.rs @@ -353,7 +353,7 @@ fn to_value<'a, 'b>(val: v8::Local<'a, v8::Value>, ctx: &RuntimeContext<'a, 'b>) .collect(); Value::AttrSet(AttrSet::new(attrs)) } - _ => todo!("{}", val.type_repr()), + _ => unimplemented!("can not convert {} to NixValue", val.type_repr()), } }