[Pkg-javascript-commits] [node-acorn-jsx] 66/484: Fixes sourceFile option.

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:06 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 f6e0182a3a5036699191d0dbf443073b1fcb6993
Author: Arian Stolwijk <stolwijk.arian at gmail.com>
Date:   Fri Jan 4 03:01:26 2013 +0100

    Fixes sourceFile option.
    
    When setting the .prototype.source the sourceFile variable is undefined, and
    setting the sourceFile option doesn't change the .source property on the
    prototype anymore.
    
    By setting the .source property inside the node_loc_t constructor, the correct
    sourceFile is set in the loc object.
---
 acorn.js      |  2 +-
 test/tests.js | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/acorn.js b/acorn.js
index 1769204..1c7ec8f 100644
--- a/acorn.js
+++ b/acorn.js
@@ -895,8 +895,8 @@
   var node_loc_t = function(s) {
     this.start=tokStartLoc;
     this.end=null;
+    if (sourceFile !== null) this.source=sourceFile;
   };
-  node_loc_t.prototype.source=sourceFile;
 
   function startNode() {
     var node = new node_t();
diff --git a/test/tests.js b/test/tests.js
index 5bd87c2..247decc 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -26065,6 +26065,100 @@ test("foo: 10; foo: 20;", {
   ]
 });
 
+// option tests
+
+test("var a = 1;", {
+  "type": "Program",
+  "start": 0,
+  "end": 10,
+  "loc": {
+    "start": {
+      "line": 1,
+      "column": 0
+    },
+    "end": {
+      "line": 1,
+      "column": 10
+    },
+    "source": "test.js"
+  },
+  "body": [
+    {
+      "type": "VariableDeclaration",
+      "start": 0,
+      "end": 9,
+      "loc": {
+        "start": {
+          "line": 1,
+          "column": 0
+        },
+        "end": {
+          "line": 1,
+          "column": 9
+        },
+        "source": "test.js"
+      },
+      "declarations": [
+        {
+          "type": "VariableDeclarator",
+          "start": 4,
+          "end": 9,
+          "loc": {
+            "start": {
+              "line": 1,
+              "column": 4
+            },
+            "end": {
+              "line": 1,
+              "column": 9
+            },
+            "source": "test.js"
+          },
+          "id": {
+            "type": "Identifier",
+            "start": 4,
+            "end": 5,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 4
+              },
+              "end": {
+                "line": 1,
+                "column": 5
+              },
+              "source": "test.js"
+            },
+            "name": "a"
+          },
+          "init": {
+            "type": "Literal",
+            "start": 8,
+            "end": 9,
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 8
+              },
+              "end": {
+                "line": 1,
+                "column": 9
+              },
+              "source": "test.js"
+            },
+            "value": 1,
+            "raw": "1"
+          }
+        }
+      ],
+      "kind": "var"
+    }
+  ]
+}, {
+  locations: true,
+  sourceFile: "test.js"
+})
+
 // Failure tests
 
 testFail("{",

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