Skip to content

Commit 297f12e

Browse files
authored
Add bailout case to sourcemap searching code (#25212)
* Add bailout case to sourcemap searching code * Also skip sourcemappy comments like sourceURL
1 parent 3a023ed commit 297f12e

File tree

3 files changed

+583721
-4
lines changed

3 files changed

+583721
-4
lines changed

src/services/services.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,8 @@ namespace ts {
15101510
}
15111511

15121512
// Sometimes tools can sometimes see the following line as a source mapping url comment, so we mangle it a bit (the [M])
1513-
const sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)$/gm;
1513+
const sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)$/;
1514+
const whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/;
15141515
const base64UrlRegExp = /^data:(?:application\/json(?:;charset=[uU][tT][fF]-8);base64,([A-Za-z0-9+\/=]+)$)?/;
15151516
function scanForSourcemapURL(fileName: string) {
15161517
const mappedFile = sourcemappedFileCache.get(toPath(fileName, currentDirectory, getCanonicalFileName));
@@ -1519,11 +1520,15 @@ namespace ts {
15191520
}
15201521
const starts = getLineStarts(mappedFile);
15211522
for (let index = starts.length - 1; index >= 0; index--) {
1522-
sourceMapCommentRegExp.lastIndex = starts[index];
1523-
const comment = sourceMapCommentRegExp.exec(mappedFile.text);
1523+
const lineText = mappedFile.text.substring(starts[index], starts[index + 1]);
1524+
const comment = sourceMapCommentRegExp.exec(lineText);
15241525
if (comment) {
15251526
return comment[1];
15261527
}
1528+
// If we see a nonwhitespace/map comment-like line, break, to avoid scanning up the entire file
1529+
else if (!lineText.match(whitespaceOrMapCommentRegExp)) {
1530+
break;
1531+
}
15271532
}
15281533
}
15291534

0 commit comments

Comments
 (0)