@@ -71,6 +71,15 @@ Debug.DebugEvent = { Break: 1,
7171 AsyncTaskEvent: 8,
7272 BreakForCommand: 9 };
7373
74+
75+ TypeScript TODOs:
76+
77+ - stuff with inheritance and auto-generated code have no corresponding
78+ lines in the .ts file, so maybe the conservative thing to do is to
79+ *SKIP* those steps, since we have nothing sensible to render for them
80+ anyhow? e.g., see demo2.ts Inheritance example from
81+ http://www.typescriptlang.org/Playground)
82+
7483*/
7584
7685
@@ -553,6 +562,27 @@ function listener(event, execState, eventData, data) {
553562 curTraceEntry . globals = { } ;
554563 curTraceEntry . ordered_globals = [ ] ;
555564
565+ // apply the source map to get the right line numbers:
566+ if ( isTypescript ) {
567+ // source map doesn't seem to work for 'return' lines since the
568+ // column is 0. hack: set the column to the FIRST column of the text
569+ // in the line to get the source map to detect it ...
570+ // (actually if it's more reliable, do this for EVERY kind of event,
571+ // since we really don't care about column numbers, we care only
572+ // about line numbers)
573+ if ( logEventType === 'return' ) {
574+ var retline = allCodLines [ line - 1 ] ;
575+ var retlineTrimmed = retline . trim ( ) ;
576+ var firstInd = retline . indexOf ( retlineTrimmed ) ;
577+ assert ( firstInd >= 0 ) ;
578+ col = firstInd ;
579+ }
580+ var tsPos = tsSourceMap . originalPositionFor ( { line : line , column : col } ) ;
581+ //log('TS:', tsPos.line, tsPos.column);
582+ line = tsPos . line ;
583+ col = tsPos . column ;
584+ }
585+
556586 curTraceEntry . line = line ;
557587 curTraceEntry . col = col ;
558588 curTraceEntry . event = logEventType ;
@@ -843,10 +873,13 @@ if (argv._.length === 1) {
843873var isTypescript = false ;
844874var sm = require ( 'source-map' ) ;
845875
876+ var originalTsCod ;
877+
846878if ( argv . typescript ) {
847879 isTypescript = true ;
880+ originalTsCod = cod ; // stash this away!
848881 var tscCompilerOutput = typescriptCompile ( cod ) ;
849- console . log ( tscCompilerOutput ) ;
882+ // console.log(tscCompilerOutput);
850883
851884 var tsSourceMap , compiledJsCod ;
852885 tscCompilerOutput . outputs . forEach ( function ( e , i ) {
@@ -864,10 +897,18 @@ if (argv.typescript) {
864897 // TODO: handle displaying multiple errors at once
865898 process . exit ( ) ;
866899 } else {
867- cod = compiledJsCod ; // woohoo, this is just JavaScript, so proceed
900+ // strip off the final line, which should say something like:
901+ // '//# sourceMappingURL=file.js.map'
902+ // since that screws up line numbers when executing, and looks ugly too
903+ var idx = compiledJsCod . indexOf ( '//# sourceMappingURL=file.js.map' ) ;
904+ assert ( idx >= 0 ) ;
905+ cod = compiledJsCod . substr ( 0 , idx - 1 ) ;
868906 }
869907}
870908
909+ assert ( cod ) ;
910+ var allCodLines = cod . split ( '\n' ) ;
911+
871912var wrappedCod = wrapUserscript ( cod ) ;
872913
873914try {
@@ -945,7 +986,9 @@ function finalize() {
945986 }
946987 }
947988
948- var blob = { code : cod , trace : curTrace } ;
989+ // very important to display the ORIGINAL TypeScript code in the
990+ // trace, not the auto-generated JS code
991+ var blob = { code : isTypescript ? originalTsCod : cod , trace : curTrace } ;
949992 if ( argv . jsfile ) {
950993 fs . writeFileSync ( argv . jsfile , 'var trace = ' + JSON . stringify ( blob ) + ';\n' ) ;
951994 log ( 'Wrote trace to' , argv . jsfile ) ;
0 commit comments