mirror of
https://github.com/storytold/craft-anything.git
synced 2026-11-19 05:50:53 +01:00
A module keyed by `0x10` and a loader call written as `16` produced different identities. Numeric separators and exponent notation caused the same problem, including dangling `requires` targets in the application graph. Different spellings of one numeric dependency could also occupy separate list entries. Use the existing syntax library's JavaScript number conversion for numeric module keys, loader arguments, browserify mappings and chunk IDs. Explicitly enable its already-present `to_js_string` feature. String identifiers retain their literal spelling, including strings such as `"0x10"` that identify a different property from numeric `0x10`.
26 lines
1.1 KiB
Rust
26 lines
1.1 KiB
Rust
use craft_anything_analysis::js_app::{AppFile, AppInput, AppOptions, analyze_application};
|
|
|
|
#[test]
|
|
fn application_graph_connects_equivalent_numeric_module_ids() {
|
|
let source = r#"
|
|
var __webpack_modules__ = {
|
|
1: function(module, exports, r) { r(16); r(1_000); },
|
|
0x10: function() {},
|
|
1000: 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#1000"), ("bundle-module:bundle.js#1", "bundle-module:bundle.js#16"),]);
|
|
for (_, target) in edges {
|
|
assert!(graph.nodes.iter().any(|node| node.id == target), "dependency target must be a module node: {target}");
|
|
}
|
|
}
|