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() {