[Pkg-javascript-commits] [node-detective] 62/119: esprima tolerant: true and removing wrapper

Bastien Roucariès rouca at moszumanska.debian.org
Wed Sep 6 09:44:35 UTC 2017


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

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

commit 77db823fb1156c4f6590e12c77ff213b9a3aec45
Author: Thorsten Lorenz <thlorenz at gmx.de>
Date:   Fri Jan 17 11:26:20 2014 -0500

    esprima tolerant: true and removing wrapper
    
    - tolerant parsing does not throw on script level returns
    - enforcing this option for parse makes the function wrapper no longer needed
    - location info for first line is now correct (see test/parseopts.js)
---
 index.js          |  3 ++-
 test/parseopts.js | 12 ++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/index.js b/index.js
index 7855c26..d0c89bf 100644
--- a/index.js
+++ b/index.js
@@ -33,10 +33,11 @@ var exports = module.exports = function (src, opts) {
 exports.find = function (src, opts) {
     if (!opts) opts = {};
     opts.parse = opts.parse || {};
+    opts.parse.tolerant = true;
 
     var word = opts.word === undefined ? 'require' : opts.word;
     if (typeof src !== 'string') src = String(src);
-    src = '(function(){' + src.replace(/^#![^\n]*\n/, '') + '\n})()';
+    src = src.replace(/^#![^\n]*\n/, '');
     
     var isRequire = opts.isRequire || function (node) {
         var c = node.callee;
diff --git a/test/parseopts.js b/test/parseopts.js
index a8cd4d1..ec0da81 100644
--- a/test/parseopts.js
+++ b/test/parseopts.js
@@ -16,8 +16,8 @@ test('nodes specified in opts and parseopts { range: true }', function (t) {
       'has a node for each require');
 
     var range = modules.nodes[0].range;
-    t.equal(range[0], 12, 'includes range start');
-    t.equal(range[1], 24, 'includes range end');
+    t.equal(range[0], 0, 'includes range start');
+    t.equal(range[1], 12, 'includes range end');
     t.end();
 });
 
@@ -50,13 +50,13 @@ test('nodes specified in opts and parseopts { range: true, loc: true }', functio
       'has a node for each require');
 
     var range = modules.nodes[0].range;
-    t.equal(range[0], 12, 'includes range start');
-    t.equal(range[1], 24, 'includes range end');
+    t.equal(range[0], 0, 'includes range start');
+    t.equal(range[1], 12, 'includes range end');
 
     var loc = modules.nodes[0].loc;
     t.equal(loc.start.line, 1, 'includes start line');
-    t.equal(loc.start.column, 12, 'includes start column');
+    t.equal(loc.start.column, 0, 'includes start column');
     t.equal(loc.end.line, 1, 'includes end line');
-    t.equal(loc.end.column, 24, 'includes end column');
+    t.equal(loc.end.column, 12, 'includes end column');
     t.end();
 });

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



More information about the Pkg-javascript-commits mailing list