diff --git a/.gitignore b/.gitignore index d8f63cd..4f282fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store /target +.idea \ No newline at end of file diff --git a/tests/fixtures/private-method/minified.js b/tests/fixtures/private-method/minified.js new file mode 100644 index 0000000..f6a4f9f --- /dev/null +++ b/tests/fixtures/private-method/minified.js @@ -0,0 +1 @@ +export class ApiConnector{#e="https://api.example.com/";async#t(e){let t=await fetch(e);if(!t.ok)throw new Error("Failed to fetch!");return t}#r(e){return this.#e+e}async get(e){return this.#t({url:this.#r(e),method:"GET"})}} \ No newline at end of file diff --git a/tests/fixtures/private-method/minified.js.map b/tests/fixtures/private-method/minified.js.map new file mode 100644 index 0000000..43a4e9b --- /dev/null +++ b/tests/fixtures/private-method/minified.js.map @@ -0,0 +1 @@ +{"version":3,"names":["ApiConnector","baseUrl","makeRequest","options","response","fetch","ok","Error","buildUrl","path","this","get","url","method"],"sources":["tests/fixtures/private-method/original.js"],"sourcesContent":["// terser -c -m --module tests/fixtures/private-method/original.js --source-map includeSources -o tests/fixtures/private-method/minified.js\nexport class ApiConnector {\n\n #baseUrl = \"https://api.example.com/\";\n\n async #makeRequest(options) {\n let response = await fetch(options);\n if (!response.ok) {\n throw new Error(\"Failed to fetch!\");\n }\n return response;\n }\n\n #buildUrl(path) {\n return this.#baseUrl + path;\n }\n\n async get(url) {\n return this.#makeRequest({\n url: this.#buildUrl(url),\n method: \"GET\"\n });\n }\n}\n"],"mappings":"OACO,MAAMA,aAETC,GAAW,2BAEX,OAAMC,CAAaC,GACf,IAAIC,QAAiBC,MAAMF,GAC3B,IAAKC,EAASE,GACV,MAAM,IAAIC,MAAM,oBAEpB,OAAOH,CACX,CAEA,EAAAI,CAAUC,GACN,OAAOC,MAAKT,EAAWQ,CAC3B,CAEA,SAAME,CAAIC,GACN,OAAOF,MAAKR,EAAa,CACrBU,IAAKF,MAAKF,EAAUI,GACpBC,OAAQ,OAEhB","ignoreList":[]} \ No newline at end of file diff --git a/tests/fixtures/private-method/original.js b/tests/fixtures/private-method/original.js new file mode 100644 index 0000000..1ff1e18 --- /dev/null +++ b/tests/fixtures/private-method/original.js @@ -0,0 +1,24 @@ +// terser -c -m --module tests/fixtures/private-method/original.js --source-map includeSources -o tests/fixtures/private-method/minified.js +export class ApiConnector { + + #baseUrl = "https://api.example.com/"; + + async #makeRequest(options) { + let response = await fetch(options); + if (!response.ok) { + throw new Error("Failed to fetch!"); + } + return response; + } + + #buildUrl(path) { + return this.#baseUrl + path; + } + + async get(url) { + return this.#makeRequest({ + url: this.#buildUrl(url), + method: "GET" + }); + } +} diff --git a/tests/integration.rs b/tests/integration.rs index 121f080..abcd44e 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -44,6 +44,26 @@ fn resolves_scopes_simple() { ); } +#[test] +fn resolves_private_method() { + let minified = fixture("private-method/minified.js"); + let map = fixture("private-method/minified.js.map"); + + let scopes = extract_scope_names(&minified).unwrap(); + + let resolved_scopes = resolve_original_scopes(&minified, &map, scopes); + + assert_eq!( + resolved_scopes, + [ + (7..225, Some("new ApiConnector".into()), Some("new ApiConnector".into())), + (56..142, Some("ApiConnector.#t".into()), Some("ApiConnector.#makeRequest".into())), + (142..165, Some("ApiConnector.#r".into()), Some("ApiConnector.#buildUrl".into())), + (165..224, Some("ApiConnector.get".into()), Some("ApiConnector.get".into())), + ] + ); +} + #[test] fn resolves_scope_names() { let src = std::fs::read_to_string("tests/fixtures/trace/sync.mjs").unwrap();