mirror of
https://github.com/storytold/craft-anything.git
synced 2026-11-19 05:50:53 +01:00
A webpack wrapper can have a loader parameter named `r` while a nested function uses its own unrelated parameter with the same spelling. The dependency visitor treated both calls as module loads, adding false `requires` edges to the application graph. Resolve loader calls against the wrapper parameter's semantic binding. This retains closures that capture the real loader, distinguishes function/arrow parameters, block and catch bindings, and avoids treating the placeholder for a destructured parameter as an actual loader name. First-seen ordering and dependency deduplication stay intact.
28 lines
1.1 KiB
Rust
28 lines
1.1 KiB
Rust
use craft_anything_analysis::js_app::{AppFile, AppInput, AppOptions, analyze_application};
|
|
|
|
#[test]
|
|
fn application_graph_does_not_link_calls_to_shadowed_loader_parameters() {
|
|
let source = r#"
|
|
var __webpack_modules__ = {
|
|
1: function(module, exports, r) {
|
|
function nested(r) { r(3); }
|
|
function captured() { r(2); }
|
|
},
|
|
2: function() {},
|
|
3: function() {}
|
|
};
|
|
"#;
|
|
let input = AppInput {
|
|
label: "bundle".into(),
|
|
format: "file".into(),
|
|
files: vec![AppFile { path: "bundle.js".into(), bytes: source.as_bytes().to_vec() }],
|
|
listing: vec![("bundle.js".into(), source.len() as u64)],
|
|
notes: vec![],
|
|
};
|
|
let graph = analyze_application(&input, &AppOptions::default(), &|| false).unwrap();
|
|
let edges: Vec<_> = graph.edges.iter().filter(|edge| edge.kind == "requires").map(|edge| (edge.from.as_str(), edge.to.as_str())).collect();
|
|
assert_eq!(edges, [("bundle-module:bundle.js#1", "bundle-module:bundle.js#2")]);
|
|
let module = graph.module("bundle.js").unwrap().bundle_modules.iter().find(|module| module.id == "1").unwrap();
|
|
assert_eq!(module.deps, ["2"]);
|
|
}
|