From bfc332c2666585e9f354bc6ea7e41f50d664b37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Sun, 27 Jun 2021 14:32:14 +0100 Subject: [PATCH] fix broken names output. Closes #994 --- lib/output.js | 6 +++++- test/mocha/sourcemaps.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/output.js b/lib/output.js index 3780edcf1..3df00704e 100644 --- a/lib/output.js +++ b/lib/output.js @@ -349,11 +349,15 @@ function OutputStream(options) { var do_add_mapping = mappings ? function() { mappings.forEach(function(mapping) { try { + let name = !mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name; + if (name instanceof AST_Symbol) { + name = name.name; + } options.source_map.add( mapping.token.file, mapping.line, mapping.col, mapping.token.line, mapping.token.col, - !mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name + is_basic_identifier_string(name) ? name : undefined ); } catch(ex) { // Ignore bad mapping diff --git a/test/mocha/sourcemaps.js b/test/mocha/sourcemaps.js index 7cabe593e..44d811b38 100644 --- a/test/mocha/sourcemaps.js +++ b/test/mocha/sourcemaps.js @@ -134,6 +134,29 @@ describe("sourcemaps", function() { assert.deepStrictEqual(result.map, {"version":3,"sources":["0"],"names":["console","log"],"mappings":"AAAAA,QAAQC,IAAI"}); }); + it("Should grab names from methods and properties correctly", async () => { + const code = `class Foo { + property = 6 + #private = 4 + method () {} + 404() {} + "quoted method name" () {} + get getter(){} + set setter(){} + }`; + const result = await minify(code, { + sourceMap: {asObject: true}, + }); + assert.deepStrictEqual(result.map.names, [ + "Foo", + "property", + "private", + "method", + "getter", + "setter" + ]); + }); + describe("inSourceMap", function() { it("Should read the given string filename correctly when sourceMapIncludeSources is enabled", async function() { var result = await minify(read("./test/input/issue-1236/simple.js"), {