11import * as path from "path" ;
2-
3- import { Mapping , SourceNode , SourceMapGenerator } from "source-map" ;
4-
5- import * as tstl from "./LuaAST" ;
2+ import { Mapping , SourceMapGenerator , SourceNode } from "source-map" ;
63import { CompilerOptions , LuaLibImportKind } from "./CompilerOptions" ;
7- import { LuaLib , LuaLibFeature } from "./LuaLib" ;
8- import { TSHelper as tsHelper } from "./TSHelper" ;
4+ import * as tstl from "./LuaAST" ;
95import { luaKeywords } from "./LuaKeywords" ;
6+ import { LuaLib , LuaLibFeature } from "./LuaLib" ;
7+ import * as tsHelper from "./TSHelper" ;
108
119type SourceChunk = string | SourceNode ;
1210
@@ -157,12 +155,12 @@ export class LuaPrinter {
157155 return this . concatNodes ( this . currentIndent , input ) ;
158156 }
159157
160- protected createSourceNode ( node : tstl . Node , chunks : SourceChunk | SourceChunk [ ] ) : SourceNode {
158+ protected createSourceNode ( node : tstl . Node , chunks : SourceChunk | SourceChunk [ ] , name ?: string ) : SourceNode {
161159 const originalPos = tstl . getOriginalPos ( node ) ;
162160
163161 return originalPos !== undefined && originalPos . line !== undefined && originalPos . column !== undefined
164- ? new SourceNode ( originalPos . line + 1 , originalPos . column , this . sourceFile , chunks )
165- : new SourceNode ( null , null , this . sourceFile , chunks ) ; // tslint:disable-line:no-null-keyword
162+ ? new SourceNode ( originalPos . line + 1 , originalPos . column , this . sourceFile , chunks , name )
163+ : new SourceNode ( null , null , this . sourceFile , chunks , name ) ; // tslint:disable-line:no-null-keyword
166164 }
167165
168166 protected concatNodes ( ...chunks : SourceChunk [ ] ) : SourceNode {
@@ -274,7 +272,7 @@ export class LuaPrinter {
274272 }
275273 }
276274
277- return this . concatNodes ( ... chunks ) ;
275+ return this . createSourceNode ( statement , chunks ) ;
278276 }
279277
280278 public printVariableAssignmentStatement ( statement : tstl . AssignmentStatement ) : SourceNode {
@@ -516,13 +514,13 @@ export class LuaPrinter {
516514 ...this . joinChunks ( ", " , returnStatement . expressions . map ( e => this . printExpression ( e ) ) ) ,
517515 ] ;
518516 chunks . push ( this . createSourceNode ( returnStatement , returnNode ) ) ;
519- chunks . push ( " end" ) ;
517+ chunks . push ( this . createSourceNode ( expression , " end" ) ) ;
520518 } else {
521519 chunks . push ( "\n" ) ;
522520 this . pushIndent ( ) ;
523521 chunks . push ( this . printBlock ( expression . body ) ) ;
524522 this . popIndent ( ) ;
525- chunks . push ( this . indent ( "end" ) ) ;
523+ chunks . push ( this . indent ( this . createSourceNode ( expression , "end" ) ) ) ;
526524 }
527525
528526 return this . createSourceNode ( expression , chunks ) ;
@@ -541,7 +539,7 @@ export class LuaPrinter {
541539 this . pushIndent ( ) ;
542540 chunks . push ( this . printBlock ( expression . body ) ) ;
543541 this . popIndent ( ) ;
544- chunks . push ( this . indent ( "end" ) ) ;
542+ chunks . push ( this . indent ( this . createSourceNode ( statement , "end" ) ) ) ;
545543
546544 return this . createSourceNode ( expression , chunks ) ;
547545 }
@@ -655,7 +653,11 @@ export class LuaPrinter {
655653 }
656654
657655 public printIdentifier ( expression : tstl . Identifier ) : SourceNode {
658- return this . createSourceNode ( expression , expression . text ) ;
656+ return this . createSourceNode (
657+ expression ,
658+ expression . text ,
659+ expression . originalName !== expression . text ? expression . originalName : undefined
660+ ) ;
659661 }
660662
661663 public printTableIndexExpression ( expression : tstl . TableIndexExpression ) : SourceNode {
@@ -784,12 +786,15 @@ export class LuaPrinter {
784786 }
785787 if (
786788 currentMapping . generated . line === generatedLine &&
787- currentMapping . generated . column === generatedColumn
789+ currentMapping . generated . column === generatedColumn &&
790+ currentMapping . name === sourceNode . name
788791 ) {
789792 return false ;
790793 }
791794 return (
792- currentMapping . original . line !== sourceNode . line || currentMapping . original . column !== sourceNode . column
795+ currentMapping . original . line !== sourceNode . line ||
796+ currentMapping . original . column !== sourceNode . column ||
797+ currentMapping . name !== sourceNode . name
793798 ) ;
794799 } ;
795800
@@ -799,6 +804,7 @@ export class LuaPrinter {
799804 source : sourceNode . source ,
800805 original : { line : sourceNode . line , column : sourceNode . column } ,
801806 generated : { line : generatedLine , column : generatedColumn } ,
807+ name : sourceNode . name ,
802808 } ;
803809 map . addMapping ( currentMapping ) ;
804810 }
0 commit comments