[Pkg-javascript-commits] [node-astw] 15/30: retry parsing for json

Bastien Roucariès rouca at moszumanska.debian.org
Tue Sep 26 12:55:04 UTC 2017


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

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

commit bca36cda556f9b014a878ec18d43de1ff2d1cc1d
Author: James Halliday <mail at substack.net>
Date:   Thu Mar 20 01:04:52 2014 -0700

    retry parsing for json
---
 index.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js
index 231ec99..07409f4 100644
--- a/index.js
+++ b/index.js
@@ -1,7 +1,11 @@
 var parse = require('esprima-fb').parse;
 
 module.exports = function (src) {
-    var ast = typeof src === 'string' ? parse(src) : src;
+    var ast = src;
+    if (typeof src === 'string') {
+        try { ast = parse(src) }
+        catch (err) { ast = parse('(' + src + ')') }
+    }
     return function (cb) {
         walk(ast, undefined, cb);
     };

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



More information about the Pkg-javascript-commits mailing list