[Pkg-javascript-commits] [node-acorn-jsx] 114/484: [loose parser] Fix a whole bunch of issues in the options.locations support

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:12 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 cc12062b9ca4a503fcdbf579aa70c9ee36deec6e
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Tue Apr 2 13:47:50 2013 +0200

    [loose parser] Fix a whole bunch of issues in the options.locations support
    
    Closes #40
---
 acorn_loose.js | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index e91bad3..2cde405 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -110,8 +110,14 @@
           throw e;
         }
         resetTo(pos);
-        if (replace === true) replace = {start: pos, end: pos, type: tt.name, value: "✖", loc: getDummyLoc()};
-        if (replace) return replace;
+        if (replace === true) replace = {start: pos, end: pos, type: tt.name, value: "✖"};
+        if (replace) {
+          if (options.locations) {
+            replace.startLoc = acorn.getLineInfo(input, replace.start);
+            replace.endLoc = acorn.getLineInfo(input, replace.end);
+          }
+          return replace;
+        }
       }
     }
   }
@@ -123,15 +129,22 @@
     fetchToken.jumpTo(pos, reAllowed);
   }
 
+  function copyToken(token) {
+    var copy = {start: token.start, end: token.end, type: token.type, value: token.value};
+    if (options.locations) {
+      copy.startLoc = token.startLoc;
+      copy.endLoc = token.endLoc;
+    }
+    return copy;
+  }
+
   function lookAhead(n) {
     // Copy token objects, because fetchToken will overwrite the one
     // it returns, and in this case we still need it
     if (!ahead.length)
-      token = {start: token.start, end: token.end, type: token.type, value: token.value};
-    while (n > ahead.length) {
-      var tok = readToken();
-      ahead.push({start: tok.from, end: tok.end, type: tok.type, value: tok.value});
-    }
+      token = copyToken(token);
+    while (n > ahead.length)
+      ahead.push(copyToken(readToken()));
     return ahead[n-1];
   }
 
@@ -190,8 +203,8 @@
     this.end = null;
   }
 
-  function node_loc_t() {
-    this.start = token.startLoc;
+  function node_loc_t(start) {
+    this.start = start || token.startLoc || {line: 1, column: 0};
     this.end = null;
     if (sourceFile !== null) this.source = sourceFile;
   }
@@ -205,10 +218,8 @@
 
   function startNodeFrom(other) {
     var node = new node_t(other.start);
-    if (options.locations) {
-      node.loc = new node_loc_t();
-      node.loc.start = other.loc.start;
-    }
+    if (options.locations)
+      node.loc = new node_loc_t(other.loc.start);
     return node;
   }
 
@@ -220,21 +231,18 @@
     return node;
   }
 
-  function getDummyLoc(dummy) {
+  function getDummyLoc() {
     if (options.locations) {
       var loc = new node_loc_t();
-      loc.end = {
-        line: loc.start.line,
-        column: loc.start.column + 1
-      };
+      loc.end = loc.start;
       return loc;
     }
   };
 
   function dummyIdent() {
-    var dummy = new node_t(0);
+    var dummy = new node_t(token.start);
     dummy.type = "Identifier";
-    dummy.end = 0;
+    dummy.end = token.start;
     dummy.name = "✖";
     dummy.loc = getDummyLoc();
     return dummy;

-- 
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