Skip to content

Name remapping support for lambda functions #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion tests/test_namemap.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ fn test_basic_name_mapping() {
let name = sm.get_original_function_name(0, 107, "e", &sv);
assert_eq!(name, Some("onFailure"));

// a stacktrae
// a stacktrace
let locs = &[
(0, 107, "e", "onFailure"),
(0, 179, "i", "invoke"),
@@ -43,3 +43,23 @@ fn test_unicode_mapping() {
assert_eq!(name, original_name_match);
}
}

#[test]
fn test_lambda_function_name_mapping() {
let input: &[_] = br#"{"version":3,"sources":["source.js"],"sourcesContent":["const SOME_CONST = 3;\n\nfunction outer() {\n const aFunctionAsConst = function() {\n console.log(\"A function as const\");\n aFunctionAsConst();\n };\n\n const aLambdaAsConst = () => {\n console.log(\"A lambda as const\");\n aLambdaAsConst();\n };\n\n function aRegularFunction() {\n console.log(\"A regular function\");\n aRegularFunction();\n }\n\n aFunctionAsConst();\n aLambdaAsConst();\n aRegularFunction();\n}\n\nouter();\n"],"names":["SOME_CONST","outer","aFunctionAsConst","console","log","aLambdaAsConst","aRegularFunction"],"mappings":"AAAA,IAAMA,WAAa,EAEnB,SAASC,QACoB,SAAnBC,IACFC,QAAQC,IAAI,qBAAqB,EACjCF,EAAiB,CACrB,CAHA,IAKMG,EAAiB,KACnBF,QAAQC,IAAI,mBAAmB,EAC/BC,EAAe,CACnB,EAOAH,EAAiB,EACjBG,EAAe,EANf,SAASC,IACLH,QAAQC,IAAI,oBAAoB,EAChCE,EAAiB,CACrB,EAIiB,CACrB,CAEAL,MAAM"}"#;
let minified_file = r#"let SOME_CONST=3;function outer(){function o(){console.log("A function as const"),o()}let n=()=>{console.log("A lambda as const"),n()};o(),n(),function o(){console.log("A regular function"),o()}()}outer();"#;
let sv = SourceView::new(minified_file.into());
let sm = SourceMap::from_reader(input).unwrap();

// a stacktrace
let locs = &[
(0, 56, "o", "aFunctionAsConst"),
(0, 106, "n", "aLambdaAsConst"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently failing, but the two other work just fine

(0, 165, "o", "aRegularFunction"),
];

for &(line, col, minified_name, original_name) in locs {
let name = sm.get_original_function_name(line, col, minified_name, &sv);
assert_eq!(name, Some(original_name));
}
}