Skip to content

Commit

Permalink
fix broken names output. Closes #994
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Jun 27, 2021
1 parent 2835581 commit bfc332c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/output.js
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/mocha/sourcemaps.js
Expand Up @@ -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"), {
Expand Down

0 comments on commit bfc332c

Please sign in to comment.