Skip to content

Commit

Permalink
Allow specifying the original name of nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
iBelieve committed May 3, 2020
1 parent a3b6718 commit 53eea79
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions escodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 5 additions & 3 deletions test/source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ describe('source map test', function () {
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "fooga",
"name": "a",
"originalName": "fooga",
"loc": {
"start": {
"line": 1,
Expand Down Expand Up @@ -413,7 +414,8 @@ describe('source map test', function () {
"arguments": [
{
"type": "Identifier",
"name": "fooga",
"name": "a",
"originalName": "fooga",
"loc": {
"start": {
"line": 3,
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 53eea79

Please sign in to comment.