diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-05-23 16:57:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-23 23:57:44 +0800 |
commit | 5d4e6e3bdc4b37d9430470f6d794bec87a467ba3 (patch) | |
tree | 4dfb81054a7b48fd1347ed9a9e3ed41f09097cd2 | |
parent | d2a45ba441ed6975021b3524215c01a011dfb46a (diff) | |
download | tracifyjs-5d4e6e3bdc4b37d9430470f6d794bec87a467ba3.tar.gz tracifyjs-5d4e6e3bdc4b37d9430470f6d794bec87a467ba3.zip |
enhance `sourceMap` (#4953)
-rw-r--r-- | lib/ast.js | 2 | ||||
-rw-r--r-- | lib/output.js | 6 | ||||
-rw-r--r-- | test/mocha/sourcemaps.js | 13 |
3 files changed, 19 insertions, 2 deletions
@@ -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); diff --git a/lib/output.js b/lib/output.js index c82d2d84..4f530038 100644 --- a/lib/output.js +++ b/lib/output.js @@ -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); }); })(); diff --git a/test/mocha/sourcemaps.js b/test/mocha/sourcemaps.js index 59642068..32017565 100644 --- a/test/mocha/sourcemaps.js +++ b/test/mocha/sourcemaps.js @@ -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 = {};", |