about summary refs log tree commit diff
path: root/src/tools/rustdoc-js/tester.js
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2021-08-11 20:14:26 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2021-08-11 20:20:17 +0200
commitcc319f88a7481e951064f87114584d7daebb0d5f (patch)
treeb784d87c7821ed10b22ce53439622dbef1e6bdee /src/tools/rustdoc-js/tester.js
parent0cd0709f19d316c4796fa71c5f52c8612a5f3771 (diff)
downloadrust-cc319f88a7481e951064f87114584d7daebb0d5f.tar.gz
rust-cc319f88a7481e951064f87114584d7daebb0d5f.zip
Fix rustdoc-js tool string "parsing"
Improve tool: add support for multiline comments
Diffstat (limited to 'src/tools/rustdoc-js/tester.js')
-rw-r--r--src/tools/rustdoc-js/tester.js33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js
index 86b16f8b0e6..bb9cd00f3f5 100644
--- a/src/tools/rustdoc-js/tester.js
+++ b/src/tools/rustdoc-js/tester.js
@@ -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;
         }
@@ -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);
                 }
             }