[Pkg-javascript-commits] [node-acorn-jsx] 344/484: Web-driver support for loose parser + small fixes.

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:53 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-acorn-jsx.

commit 96ccdb05faf175de545ea01085302bac5a590eeb
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Mon Nov 3 20:07:19 2014 +0200

    Web-driver support for loose parser + small fixes.
    
    * Added support for acorn_loose and grouped log to web-driver.
    * Removed unused copy-pasted `parseTemplate` from loose parser.
    * Throw non-SyntaxError errors immediately (as those are generic).
---
 acorn_loose.js  |  29 -----------
 test/driver.js  |   7 ++-
 test/index.html |  21 ++------
 test/run.js     | 152 +++++++++++++++++++++++++++++++++++++-------------------
 4 files changed, 110 insertions(+), 99 deletions(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index 4c5806a..9b739da 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -786,35 +786,6 @@
     return finishNode(node, "NewExpression");
   }
 
-  function parseTemplate() {
-    var node = startNode();
-    node.expressions = [];
-    node.quasis = [];
-    inTemplate = true;
-    next();
-    for (;;) {
-      var elem = startNode();
-      elem.value = {cooked: tokVal, raw: input.slice(tokStart, tokEnd)};
-      elem.tail = false;
-      next();
-      node.quasis.push(finishNode(elem, "TemplateElement"));
-      if (tokType === _bquote) { // '`', end of template
-        elem.tail = true;
-        break;
-      }
-      inTemplate = false;
-      expect(_dollarBraceL);
-      node.expressions.push(parseExpression());
-      inTemplate = true;
-      // hack to include previously skipped space
-      tokPos = tokEnd;
-      expect(_braceR);
-    }
-    inTemplate = false;
-    next();
-    return finishNode(node, "TemplateLiteral");
-  }
-
   function parseObj(isClass, isStatement) {
     var node = startNode();
     if (isClass) {
diff --git a/test/driver.js b/test/driver.js
index cbd6cc3..c76b8f9 100644
--- a/test/driver.js
+++ b/test/driver.js
@@ -52,12 +52,15 @@
           else callback("ok", test.code);
         }
       } catch(e) {
-        if (test.error && e instanceof SyntaxError) {
+        if (!(e instanceof SyntaxError)) {
+          throw e;
+        }
+        if (test.error) {
           if (e.message == test.error) callback("ok", test.code);
           else callback("fail", test.code,
                         "Expected error message: " + test.error + "\nGot error message: " + e.message);
         } else {
-          callback("error", test.code, !(e instanceof SyntaxError) && e.stack || e.message || e.toString());
+          callback("error", test.code, e.message || e.toString());
         }
       }
     }
diff --git a/test/index.html b/test/index.html
index 96a9d95..ef80eb7 100644
--- a/test/index.html
+++ b/test/index.html
@@ -3,23 +3,12 @@
   <meta charset="utf-8">
   <title>Acorn test suite</title>
   <script src="../acorn.js"></script>
+  <script src="../acorn_loose.js"></script>
   <script src="driver.js"></script>
   <script src="tests.js" charset="utf-8"></script>
   <script src="tests-harmony.js" charset="utf-8"></script>
 </head>
-
-<script>
-  var testsRun = 0, failed = 0;
-  function report(state, code, message) {
-    if (state != "ok") {++failed; console.log(code, message);}
-    ++testsRun;
-  }
-  window.onload = function(){
-    var t0 = +new Date;
-    runTests(report);
-    var out = testsRun + " tests run in " + (+new Date - t0) + "ms\n";
-    if (failed) out += failed + " failures.\n";
-    else out += "All passed.\n";
-    document.body.appendChild(document.createElement("pre")).appendChild(document.createTextNode(out));
-  };
-</script>
+<body>
+  <ul id="log"></ul>
+  <script src="run.js"></script>
+</body>
diff --git a/test/run.js b/test/run.js
index 04001c3..fefcaed 100644
--- a/test/run.js
+++ b/test/run.js
@@ -1,56 +1,104 @@
-var driver = require("./driver.js");
-require("./tests.js");
-require("./tests-harmony.js");
-
-var stats, modes = {
-  Normal: {
-    config: {
-      parse: (typeof require === "undefined" ? window.acorn : require("../acorn.js")).parse
+(function() {
+  var driver;
+
+  if (typeof require !== "undefined") {
+    driver = require("./driver.js");
+    require("./tests.js");
+    require("./tests-harmony.js");
+  } else {
+    driver = window;
+  }
+
+  var htmlLog = typeof document === "object" && document.getElementById('log');
+  var htmlGroup;
+
+  function group(name) {
+    if (htmlLog) {
+      htmlGroup = document.createElement("ul");
+      var item = document.createElement("li");
+      item.textContent = name;
+      item.appendChild(htmlGroup);
+      htmlLog.appendChild(item);
+    }
+    if (typeof console === "object" && console.group) {
+      console.group(name);
+    }
+  }
+
+  function groupEnd() {
+    htmlGroup = null;
+    if (typeof console === "object" && console.groupEnd) {
+      console.groupEnd(name);
     }
-  },
-  Loose: {
-    config: {
-      parse: (typeof require === "undefined") ? window.acorn_loose : require("../acorn_loose").parse_dammit,
-      loose: true,
-      filter: function (test) {
-        var opts = test.options || {};
-        if (opts.loose === false) return false;
-        return (opts.ecmaVersion || 5) <= 6;
+  }
+
+  function log(title, message) {
+    if (htmlGroup) {
+      var elem = document.createElement("li");
+      elem.innerHTML = "<b>" + title + "</b> " + message;
+      htmlGroup.appendChild(elem);
+    }
+    if (typeof console === "object") console.log(title, message);
+  }
+
+  var stats, modes = {
+    Normal: {
+      config: {
+        parse: (typeof require === "undefined" ? window.acorn : require("../acorn.js")).parse
+      }
+    },
+    Loose: {
+      config: {
+        parse: (typeof require === "undefined" ? window.acorn : require("../acorn_loose")).parse_dammit,
+        loose: true,
+        filter: function (test) {
+          var opts = test.options || {};
+          if (opts.loose === false) return false;
+          return (opts.ecmaVersion || 5) <= 6;
+        }
       }
     }
+  };
+
+  function report(state, code, message) {
+    if (state != "ok") {++stats.failed; log(code, message);}
+    ++stats.testsRun;
+  }
+
+  group("Errors");
+
+  for (var name in modes) {
+    var mode = modes[name];
+    stats = mode.stats = {testsRun: 0, failed: 0};
+    var t0 = +new Date;
+    driver.runTests(mode.config, report);
+    mode.stats.duration = +new Date - t0;
+  }
+
+  groupEnd();
+
+  function outputStats(name, stats) {
+    log(name + ":", stats.testsRun + " tests run in " + stats.duration + "ms; " +
+      (stats.failed ? stats.failed + " failures." : "all passed."));
+  }
+
+  var total = {testsRun: 0, failed: 0, duration: 0};
+
+  group("Stats");
+
+  for (var name in modes) {
+    var stats = modes[name].stats;
+    outputStats(name + " parser", stats);
+    for (var key in stats) total[key] += stats[key];
+  }
+
+  outputStats("Total", total);
+
+  groupEnd();
+
+  if (total.failed && typeof process === "object") {
+    process.stdout.write("", function() {
+      process.exit(1);
+    });
   }
-};
-
-function report(state, code, message) {
-  if (state != "ok") {++stats.failed; console.log(code, message);}
-  ++stats.testsRun;
-}
-
-for (var name in modes) {
-  var mode = modes[name];
-  stats = mode.stats = {testsRun: 0, failed: 0};
-  var t0 = +new Date;
-  driver.runTests(mode.config, report);
-  mode.stats.duration = +new Date - t0;
-}
-
-function outputStats(name, stats) {
-  console.log(name + ": " + stats.testsRun + " tests run in " + stats.duration + "ms; " +
-    (stats.failed ? stats.failed + " failures." : "all passed."));
-}
-
-var total = {testsRun: 0, failed: 0, duration: 0};
-
-for (var name in modes) {
-  var stats = modes[name].stats;
-  outputStats(name + " parser", stats);
-  for (var key in stats) total[key] += stats[key];
-}
-
-outputStats("Total", total);
-
-if (total.failed) {
-  process.stdout.write("", function() {
-    process.exit(1);
-  });
-}
+})();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git



More information about the Pkg-javascript-commits mailing list