Skip to content

Commit 7b5e81d

Browse files
authored
Merge pull request #1481 from microsoft/complex-sourcemap-names
Support more complex sourcemap renames
2 parents 6130f21 + cf48bd5 commit 7b5e81d

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/common/sourceMaps/renameProvider.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*--------------------------------------------------------*/
44

55
import { inject, injectable } from 'inversify';
6+
import { MappingItem } from 'source-map';
67
import { ISourceWithMap, Source, SourceFromMap } from '../../adapter/sources';
78
import { StackFrame } from '../../adapter/stackTrace';
89
import { 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-9A-Z_$]*/iy;
22-
2321
export 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

Comments
 (0)