Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying the original name of nodes #411

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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