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 rustdoc-js tests #56945

Merged
merged 1 commit into from
Dec 23, 2018
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
16 changes: 14 additions & 2 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function getNextStep(content, pos, stop) {
return pos;
}

// Stupid function extractor based on indent.
// Stupid function extractor based on indent. Doesn't support block
// comments. If someone puts a ' or an " in a block comment this
// will blow up. Template strings are not tested and might also be
// broken.
function extractFunction(content, functionName) {
var indent = 0;
var splitter = "function " + functionName + "(";
Expand All @@ -51,7 +54,14 @@ function extractFunction(content, functionName) {
continue;
}
while (pos < content.length) {
if (content[pos] === '"' || content[pos] === "'") {
// Eat single-line comments
if (content[pos] === '/' && pos > 0 && content[pos-1] === '/') {
do {
pos += 1;
} while (pos < content.length && content[pos] !== '\n');

// Eat quoted strings
} else if (content[pos] === '"' || content[pos] === "'" || content[pos] === "`") {
var stop = content[pos];
var is_escaped = false;
do {
Expand All @@ -62,6 +72,8 @@ function extractFunction(content, functionName) {
}
} while (pos < content.length &&
(content[pos] !== stop || content[pos - 1] === '\\'));

// Otherwise, check for indent
} else if (content[pos] === '{') {
indent += 1;
} else if (content[pos] === '}') {
Expand Down