From 53eea79c9de29952c402c6ac7538466ab7bcae9a Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Sun, 3 May 2020 07:35:43 -0500 Subject: [PATCH] Allow specifying the original name of nodes See #118, https://github.com/estools/esmangle/issues/85 --- escodegen.js | 4 ++-- test/source-map.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/escodegen.js b/escodegen.js index 6fe6646d..c862052d 100644 --- a/escodegen.js +++ b/escodegen.js @@ -526,9 +526,9 @@ } } if (node.loc == null) { - return new SourceNode(null, null, sourceMap, generated, node.name || null); + return new SourceNode(null, null, sourceMap, generated, node.originalName || node.name || null); } - return new SourceNode(node.loc.start.line, node.loc.start.column, (sourceMap === true ? node.loc.source || null : sourceMap), generated, node.name || null); + return new SourceNode(node.loc.start.line, node.loc.start.column, (sourceMap === true ? node.loc.source || null : sourceMap), generated, node.originalName || node.name || null); } function noEmptySpace() { diff --git a/test/source-map.js b/test/source-map.js index 8f6f2150..261ee184 100644 --- a/test/source-map.js +++ b/test/source-map.js @@ -313,7 +313,8 @@ describe('source map test', function () { "type": "VariableDeclarator", "id": { "type": "Identifier", - "name": "fooga", + "name": "a", + "originalName": "fooga", "loc": { "start": { "line": 1, @@ -413,7 +414,8 @@ describe('source map test', function () { "arguments": [ { "type": "Identifier", - "name": "fooga", + "name": "a", + "originalName": "fooga", "loc": { "start": { "line": 3, @@ -466,7 +468,7 @@ describe('source map test', function () { sourceMapWithCode: true }); - expect(result.map._names._array.length).to.be.equal(3); + expect(result.map._names._array).to.be.eql(["fooga", "console", "log"]); }); it('sourceContent support', function() {