Skip to content

Commit

Permalink
progress?
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Nov 7, 2024
1 parent 14ca443 commit 1c3725b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{CodeMapPair, Options, Preprocessor as CorePreprocessor};
use crate::{Options, Preprocessor as CorePreprocessor};
use js_sys::Reflect;
use serde_wasm_bindgen::to_value;
use std::{fmt, path::PathBuf, str};
Expand Down Expand Up @@ -55,6 +55,20 @@ impl Options {
}
}

#[wasm_bindgen]
pub struct CodeMapPair {
pub code: String,
pub map: String,
}

#[wasm_bindgen]
impl CodeMapPair {
#[wasm_bindgen(constructor)]
pub fn new(code: String, map: String) -> Self {
Self { code, map }
}
}

#[wasm_bindgen]
pub struct Preprocessor {
// TODO: reusing this between calls result in incorrect spans; there may
Expand Down Expand Up @@ -130,7 +144,7 @@ impl Preprocessor {
let result = preprocessor.process(&src, options);

match result {
Ok(output) => Ok(to_value(&output).unwrap()),
Ok(output) => Ok(CodeMapPair::new(output.code, output.map)),
Err(err) => Err(as_javascript_error(err, preprocessor.source_map()).into()),
}
}
Expand Down

0 comments on commit 1c3725b

Please sign in to comment.