Skip to content

Commit 628c6d8

Browse files
committed
Rollup merge of #56945 - JohnHeitmann:rustdoc-js-tester-fix, r=GuillaumeGomez
Fix rustdoc-js tests Fixes rustdoc-js tests by teaching tester.js how to handle single-line js comments. Also, added speculative support for template strings, and warnings for future debuggers.
2 parents 26842ae + 5056669 commit 628c6d8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/tools/rustdoc-js/tester.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ function getNextStep(content, pos, stop) {
2626
return pos;
2727
}
2828

29-
// Stupid function extractor based on indent.
29+
// Stupid function extractor based on indent. Doesn't support block
30+
// comments. If someone puts a ' or an " in a block comment this
31+
// will blow up. Template strings are not tested and might also be
32+
// broken.
3033
function extractFunction(content, functionName) {
3134
var indent = 0;
3235
var splitter = "function " + functionName + "(";
@@ -51,7 +54,14 @@ function extractFunction(content, functionName) {
5154
continue;
5255
}
5356
while (pos < content.length) {
54-
if (content[pos] === '"' || content[pos] === "'") {
57+
// Eat single-line comments
58+
if (content[pos] === '/' && pos > 0 && content[pos-1] === '/') {
59+
do {
60+
pos += 1;
61+
} while (pos < content.length && content[pos] !== '\n');
62+
63+
// Eat quoted strings
64+
} else if (content[pos] === '"' || content[pos] === "'" || content[pos] === "`") {
5565
var stop = content[pos];
5666
var is_escaped = false;
5767
do {
@@ -62,6 +72,8 @@ function extractFunction(content, functionName) {
6272
}
6373
} while (pos < content.length &&
6474
(content[pos] !== stop || content[pos - 1] === '\\'));
75+
76+
// Otherwise, check for indent
6577
} else if (content[pos] === '{') {
6678
indent += 1;
6779
} else if (content[pos] === '}') {

0 commit comments

Comments
 (0)