Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/improve rustdoc-js tool #87941

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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