[Pkg-javascript-commits] [node-acorn-jsx] 444/484: fix loc.end info for multi-line JSXAttributeValue

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:21:09 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 a8f5c1e87afb7b5ab512e502d7fc56395001eba2
Author: Jon Jensen <jenseng at gmail.com>
Date:   Sun May 3 22:41:50 2015 -0700

    fix loc.end info for multi-line JSXAttributeValue
    
    on the old code, the updated test would fail since `loc.end` would contain
    `{ line: 1, column: 62 }`
    
    also pull new-line handling code out of jsx_readToken for easy reuse. note
    that we don't do any normalization of `<CR><LF>` in a JSXAttributeValue,
    so as to be consistent with esprima-fb's behavior.
---
 inject.js         | 34 +++++++++++++++++++++++-----------
 test/tests-jsx.js |  4 ++++
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/inject.js b/inject.js
index 2d11285..af51997 100644
--- a/inject.js
+++ b/inject.js
@@ -61,17 +61,7 @@ module.exports = function(acorn) {
       default:
         if (acorn.isNewLine(ch)) {
           out += this.input.slice(chunkStart, this.pos);
-          ++this.pos;
-          if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
-            ++this.pos;
-            out += '\n';
-          } else {
-            out += String.fromCharCode(ch);
-          }
-          if (this.options.locations) {
-            ++this.curLine;
-            this.lineStart = this.pos;
-          }
+          out += this.jsx_readNewLine(true);
           chunkStart = this.pos;
         } else {
           ++this.pos;
@@ -80,6 +70,24 @@ module.exports = function(acorn) {
     }
   };
 
+  pp.jsx_readNewLine = function(normalizeCRLF) {
+    var ch = this.input.charCodeAt(this.pos);
+    var out;
+    ++this.pos;
+    if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
+      ++this.pos;
+      out = normalizeCRLF ? '\n' : '\r\n';
+    } else {
+      out = String.fromCharCode(ch);
+    }
+    if (this.options.locations) {
+      ++this.curLine;
+      this.lineStart = this.pos;
+    }
+
+    return out;
+  };
+
   pp.jsx_readString = function(quote) {
     var out = '', chunkStart = ++this.pos;
     for (;;) {
@@ -91,6 +99,10 @@ module.exports = function(acorn) {
         out += this.input.slice(chunkStart, this.pos);
         out += this.jsx_readEntity();
         chunkStart = this.pos;
+      } else if (acorn.isNewLine(ch)) {
+        out += this.input.slice(chunkStart, this.pos);
+        out += this.jsx_readNewLine(false);
+        chunkStart = this.pos;
       } else {
         ++this.pos;
       }
diff --git a/test/tests-jsx.js b/test/tests-jsx.js
index c9cfa5a..def8d98 100644
--- a/test/tests-jsx.js
+++ b/test/tests-jsx.js
@@ -3607,6 +3607,10 @@ var fbTestFixture = {
               },
               value: {
                 type: "Literal",
+                loc: {
+                  start: { line: 1, column: 8 },
+                  end: { line: 3, column: 15 }
+                },
                 range: [8, 62],
                 value: "M230 80\n\t\tA 45 45, 0, 1, 0, 275 125 \r\n    L 275 80 Z",
                 raw: "\"M230 80\n\t\tA 45 45, 0, 1, 0, 275 125 \r\n    L 275 80 Z\""

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