Skip to content

Commit 46909e0

Browse files
committed
Merge pull request #113 from tivac/source-map-names
Generate names array for sourcemaps
2 parents d6673ed + 79c3705 commit 46909e0

File tree

2 files changed

+169
-2
lines changed

2 files changed

+169
-2
lines changed

escodegen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,9 @@
617617
}
618618
}
619619
if (node.loc == null) {
620-
return new SourceNode(null, null, sourceMap, generated);
620+
return new SourceNode(null, null, sourceMap, generated, node.name || null);
621621
}
622-
return new SourceNode(node.loc.start.line, node.loc.start.column, (sourceMap === true ? node.loc.source || null : sourceMap), generated);
622+
return new SourceNode(node.loc.start.line, node.loc.start.column, (sourceMap === true ? node.loc.source || null : sourceMap), generated, node.name || null);
623623
}
624624

625625
function join(left, right) {

test/source-map.js

+167
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,171 @@ describe('source map test', function () {
305305
x.original.column == 6;
306306
}).length).to.be.equal(1);
307307
});
308+
309+
it('names array test', function() {
310+
var ast = {
311+
"type": "Program",
312+
"body": [
313+
{
314+
"type": "VariableDeclaration",
315+
"declarations": [
316+
{
317+
"type": "VariableDeclarator",
318+
"id": {
319+
"type": "Identifier",
320+
"name": "fooga",
321+
"loc": {
322+
"start": {
323+
"line": 1,
324+
"column": 4
325+
},
326+
"end": {
327+
"line": 1,
328+
"column": 9
329+
}
330+
}
331+
},
332+
"init": {
333+
"type": "Literal",
334+
"value": "wooga",
335+
"raw": "\"wooga\"",
336+
"loc": {
337+
"start": {
338+
"line": 1,
339+
"column": 12
340+
},
341+
"end": {
342+
"line": 1,
343+
"column": 19
344+
}
345+
}
346+
},
347+
"loc": {
348+
"start": {
349+
"line": 1,
350+
"column": 4
351+
},
352+
"end": {
353+
"line": 1,
354+
"column": 19
355+
}
356+
}
357+
}
358+
],
359+
"kind": "var",
360+
"loc": {
361+
"start": {
362+
"line": 1,
363+
"column": 0
364+
},
365+
"end": {
366+
"line": 1,
367+
"column": 20
368+
}
369+
}
370+
},
371+
{
372+
"type": "ExpressionStatement",
373+
"expression": {
374+
"type": "CallExpression",
375+
"callee": {
376+
"type": "MemberExpression",
377+
"computed": false,
378+
"object": {
379+
"type": "Identifier",
380+
"name": "console",
381+
"loc": {
382+
"start": {
383+
"line": 3,
384+
"column": 0
385+
},
386+
"end": {
387+
"line": 3,
388+
"column": 7
389+
}
390+
}
391+
},
392+
"property": {
393+
"type": "Identifier",
394+
"name": "log",
395+
"loc": {
396+
"start": {
397+
"line": 3,
398+
"column": 8
399+
},
400+
"end": {
401+
"line": 3,
402+
"column": 11
403+
}
404+
}
405+
},
406+
"loc": {
407+
"start": {
408+
"line": 3,
409+
"column": 0
410+
},
411+
"end": {
412+
"line": 3,
413+
"column": 11
414+
}
415+
}
416+
},
417+
"arguments": [
418+
{
419+
"type": "Identifier",
420+
"name": "fooga",
421+
"loc": {
422+
"start": {
423+
"line": 3,
424+
"column": 12
425+
},
426+
"end": {
427+
"line": 3,
428+
"column": 17
429+
}
430+
}
431+
}
432+
],
433+
"loc": {
434+
"start": {
435+
"line": 3,
436+
"column": 0
437+
},
438+
"end": {
439+
"line": 3,
440+
"column": 18
441+
}
442+
}
443+
},
444+
"loc": {
445+
"start": {
446+
"line": 3,
447+
"column": 0
448+
},
449+
"end": {
450+
"line": 3,
451+
"column": 19
452+
}
453+
}
454+
}
455+
],
456+
"loc": {
457+
"start": {
458+
"line": 1,
459+
"column": 0
460+
},
461+
"end": {
462+
"line": 3,
463+
"column": 19
464+
}
465+
}
466+
};
467+
468+
var result = escodegen.generate(ast, {
469+
sourceMap: "Names",
470+
sourceMapWithCode: true
471+
});
472+
473+
expect(result.map._names._array.length).to.be.equal(3);
474+
});
308475
});

0 commit comments

Comments
 (0)