Skip to content

Commit

Permalink
Rollup merge of rust-lang#87941 - GuillaumeGomez:fix-rustdoc-js-tool,…
Browse files Browse the repository at this point in the history
… r=notriddle

Fix/improve rustdoc-js tool

This tool is run when testing `src/test/rustdoc-js*`.

r? `@notriddle`
  • Loading branch information
GuillaumeGomez authored Aug 12, 2021
2 parents 3d733f6 + cc319f8 commit faf7fb9
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ function getNextStep(content, pos, stop) {
// will blow up. Template strings are not tested and might also be
// broken.
function extractFunction(content, functionName) {
var indent = 0;
var level = 0;
var splitter = "function " + functionName + "(";
var stop;
var pos, start;

while (true) {
var start = content.indexOf(splitter);
start = content.indexOf(splitter);
if (start === -1) {
break;
}
var pos = start;
pos = start;
while (pos < content.length && content[pos] !== ')') {
pos += 1;
}
Expand All @@ -44,30 +46,33 @@ function extractFunction(content, functionName) {
}
while (pos < content.length) {
// Eat single-line comments
if (content[pos] === '/' && pos > 0 && content[pos-1] === '/') {
if (content[pos] === '/' && pos > 0 && content[pos - 1] === '/') {
do {
pos += 1;
} while (pos < content.length && content[pos] !== '\n');

// Eat multiline comment.
} else if (content[pos] === '*' && pos > 0 && content[pos - 1] === '/') {
do {
pos += 1;
} while (pos < content.length && content[pos] !== '/' && content[pos - 1] !== '*');

// Eat quoted strings
} else if (content[pos] === '"' || content[pos] === "'" || content[pos] === "`") {
var stop = content[pos];
var is_escaped = false;
stop = content[pos];
do {
if (content[pos] === '\\') {
pos += 2;
} else {
pos += 1;
}
} while (pos < content.length &&
(content[pos] !== stop || content[pos - 1] === '\\'));
pos += 1;
} while (pos < content.length && content[pos] !== stop);

// Otherwise, check for indent
// Otherwise, check for block level.
} else if (content[pos] === '{') {
indent += 1;
level += 1;
} else if (content[pos] === '}') {
indent -= 1;
if (indent === 0) {
level -= 1;
if (level === 0) {
return content.slice(start, pos + 1);
}
}
Expand Down

0 comments on commit faf7fb9

Please sign in to comment.