33 *--------------------------------------------------------*/
44
55import { inject , injectable } from 'inversify' ;
6+ import { MappingItem } from 'source-map' ;
67import { ISourceWithMap , Source , SourceFromMap } from '../../adapter/sources' ;
78import { StackFrame } from '../../adapter/stackTrace' ;
89import { AnyLaunchConfiguration } from '../../configuration' ;
@@ -17,9 +18,6 @@ interface IRename {
1718 position : Base01Position ;
1819}
1920
20- /** Very approximate regex for JS identifiers */
21- const identifierRe = / [ $ a - z _ ] [ $ 0 - 9 A - Z _ $ ] * / iy;
22-
2321export interface IRenameProvider {
2422 /**
2523 * Provides renames at the given stackframe.
@@ -104,23 +102,36 @@ export class RenameProvider implements IRenameProvider {
104102 const renames : IRename [ ] = [ ] ;
105103
106104 // todo: may eventually want to be away
105+ let pendingName : MappingItem | undefined ;
107106 sourceMap . eachMapping ( mapping => {
108- if ( ! mapping . name ) {
109- return ;
107+ if ( pendingName ) {
108+ const startPos = new Base01Position ( pendingName . generatedLine , pendingName . generatedColumn ) ;
109+ const start = toOffset . convert ( startPos ) ;
110+ const end = toOffset . convert (
111+ new Base01Position ( mapping . generatedLine , mapping . generatedColumn ) ,
112+ ) ;
113+ renames . push ( {
114+ compiled : content . slice ( start , end ) ,
115+ original : pendingName . name ,
116+ position : startPos ,
117+ } ) ;
118+ pendingName = undefined ;
110119 }
111120
112- // convert to base 0 columns
113- const position = new Base01Position ( mapping . generatedLine , mapping . generatedColumn ) ;
114- const start = toOffset . convert ( position ) ;
115- identifierRe . lastIndex = start ;
116- const match = identifierRe . exec ( content ) ;
117- if ( ! match ) {
118- return ;
121+ if ( mapping . name ) {
122+ pendingName = mapping ;
119123 }
120-
121- renames . push ( { compiled : match [ 0 ] , original : mapping . name , position } ) ;
122124 } ) ;
123125
126+ if ( pendingName ) {
127+ const position = new Base01Position ( pendingName . generatedLine , pendingName . generatedColumn ) ;
128+ renames . push ( {
129+ compiled : content . slice ( toOffset . convert ( position ) ) ,
130+ original : pendingName . name ,
131+ position,
132+ } ) ;
133+ }
134+
124135 renames . sort ( ( a , b ) => a . position . compare ( b . position ) ) ;
125136
126137 return new RenameMapping ( renames ) ;
0 commit comments