Fix to cache correct PathToNode in artifact graph (#6632)
* Add NodePath to artifact graph Since this is cached, this should make PathToNode computation correct even when code is formatted, whitespace changes, and source ranges are different. * Remove dead code * Add unit tests * Add tests for PathToNode conversion * Remove unused parameter * Add missing PathToNode cases * Fix to handle unlabeled arg * Cherry pick unlabeled arg fix * Change PathToNode comment to match TS implementation
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
//! Wasm bindings for `kcl`.
|
||||
|
||||
use gloo_utils::format::JsValueSerdeExt;
|
||||
use kcl_lib::{pretty::NumericSuffix, CoreDump, Program};
|
||||
use kcl_lib::{pretty::NumericSuffix, CoreDump, Program, SourceRange};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// wasm_bindgen wrapper for execute
|
||||
// wasm_bindgen wrapper for lint
|
||||
#[wasm_bindgen]
|
||||
pub async fn kcl_lint(program_ast_json: &str) -> Result<JsValue, JsValue> {
|
||||
console_error_panic_hook::set_once();
|
||||
@ -18,6 +18,17 @@ pub async fn kcl_lint(program_ast_json: &str) -> Result<JsValue, JsValue> {
|
||||
Ok(JsValue::from_serde(&findings).map_err(|e| e.to_string())?)
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub async fn node_path_from_range(program_ast_json: &str, range_json: &str) -> Result<JsValue, String> {
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
let program: Program = serde_json::from_str(program_ast_json).map_err(|e| e.to_string())?;
|
||||
let range: SourceRange = serde_json::from_str(range_json).map_err(|e| e.to_string())?;
|
||||
let node_path = program.node_path_from_range(range);
|
||||
|
||||
JsValue::from_serde(&node_path).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn parse_wasm(kcl_program_source: &str) -> Result<JsValue, String> {
|
||||
console_error_panic_hook::set_once();
|
||||
|
Reference in New Issue
Block a user