Skip to content

Commit

Permalink
enhance sourceMap (#4953)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored May 23, 2021
1 parent d2a45ba commit 5d4e6e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ var AST_ObjectMethod = DEFNODE("ObjectMethod", null, {
_validate: function() {
if (!(this.value instanceof AST_LambdaExpression)) throw new Error("value must be AST_LambdaExpression");
if (is_arrow(this.value)) throw new Error("value cannot be AST_Arrow or AST_AsyncArrow");
if (this.value.name != null) throw new Error("name of class method's lambda must be null");
if (this.value.name != null) throw new Error("name of object method's lambda must be null");
},
}, AST_ObjectKeyVal);

Expand Down
6 changes: 5 additions & 1 deletion lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,11 @@ function OutputStream(options) {
output.add_mapping(this.start);
});

DEFMAP([ AST_DestructuredKeyVal, AST_ObjectProperty ], function(output) {
DEFMAP([
AST_ClassProperty,
AST_DestructuredKeyVal,
AST_ObjectProperty,
], function(output) {
if (typeof this.key == "string") output.add_mapping(this.start, this.key);
});
})();
13 changes: 13 additions & 0 deletions test/mocha/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ describe("sourcemaps", function() {
var map = JSON.parse(result.map);
assert.deepEqual(map.names, []);
});
it("Should mark class properties", function() {
var result = UglifyJS.minify([
"class A {",
" static P = 42",
" set #q(v) {}",
"}",
].join("\n"), {
sourceMap: true,
});
if (result.error) throw result.error;
assert.strictEqual(result.code, "class A{static P=42;set#q(s){}}");
assert.strictEqual(result.map, '{"version":3,"sources":["0"],"names":["A","P","#q","v"],"mappings":"MAAMA,EACFC,SAAW,GACXC,MAAOC"}');
});
it("Should mark array/object literals", function() {
var result = UglifyJS.minify([
"var obj = {};",
Expand Down

0 comments on commit 5d4e6e3

Please sign in to comment.