feat: NamedSource

This commit is contained in:
2026-01-20 18:54:19 +08:00
parent e310133421
commit 2cb85529c9
19 changed files with 225 additions and 292 deletions

View File

@@ -1,16 +1,25 @@
#![allow(dead_code)]
use nix_js::context::Context;
use nix_js::error::{Result, Source};
use nix_js::value::Value;
pub fn eval(expr: &str) -> Value {
Context::new().unwrap().eval_code(expr).unwrap()
Context::new()
.unwrap()
.eval_code(Source::new_eval(expr.into()).unwrap())
.unwrap()
}
pub fn eval_result(expr: &str) -> Result<Value, nix_js::error::Error> {
Context::new().unwrap().eval_code(expr)
pub fn eval_result(expr: &str) -> Result<Value> {
Context::new()
.unwrap()
.eval_code(Source::new_eval(expr.into()).unwrap())
}
pub fn compile(expr: &str) -> String {
Context::new().unwrap().compile_code(expr).unwrap()
Context::new()
.unwrap()
.compile_code(Source::new_eval(expr.into()).unwrap())
.unwrap()
}