diff options
| author | kennytm <kennytm@gmail.com> | 2018-12-23 02:04:44 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-12-23 02:12:30 +0800 |
| commit | 628c6d89e16cc00ecccb83129f30eaa9d89af9ff (patch) | |
| tree | f3c99f0c4260087b900046ac613919b92e99a788 /src/tools/rustdoc-js/tester.js | |
| parent | 26842aeac6645320a1241f6236e975f09ff34281 (diff) | |
| parent | 5056669fc83b256cef39927d51b67f320ab1f325 (diff) | |
| download | rust-628c6d89e16cc00ecccb83129f30eaa9d89af9ff.tar.gz rust-628c6d89e16cc00ecccb83129f30eaa9d89af9ff.zip | |
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.
Diffstat (limited to 'src/tools/rustdoc-js/tester.js')
| -rw-r--r-- | src/tools/rustdoc-js/tester.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index f7c30df9f3e..65ed86742e7 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -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 + "("; @@ -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 { @@ -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] === '}') { |
