[Pkg-javascript-commits] [node-acorn-jsx] 32/484: Properly parse 10. as a valid number

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:00 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 96d911a30fcaba4546aad0d433c57592eba7d1ee
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Fri Oct 12 23:34:11 2012 +0200

    Properly parse 10. as a valid number
    
    Closes #9
---
 acorn.js      |  2 +-
 index.html    |  2 +-
 test/tests.js | 44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/acorn.js b/acorn.js
index 582d3b3..3aea6da 100644
--- a/acorn.js
+++ b/acorn.js
@@ -643,7 +643,7 @@
     if (isFloat || input.charAt(tokPos) === ".") {
       var next = input.charAt(++tokPos);
       if (next === "-" || next === "+") ++tokPos;
-      if (readInt(10) === null) raise(start, "Invalid number");
+      if (readInt(10) === null && ch === ".") raise(start, "Invalid number");
       isFloat = true;
     }
     if (/e/i.test(input.charAt(tokPos))) {
diff --git a/index.html b/index.html
index a5ed4ad..bdb451f 100644
--- a/index.html
+++ b/index.html
@@ -417,7 +417,7 @@ will return <code>null</code> unless the integer has exactly <code>len</code> di
     <span class="k">if</span> <span class="p">(</span><span class="nx">isFloat</span> <span class="o">||</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">)</span> <span class="o">===</span> <span class="s2">"."</span><span class="p">)</span> <span class="p">{</span>
       <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="o">++</span><span class="nx">tokPos</span><span class="p">);</span>
       <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="s2">"-"</span> <span class="o">||</span> <span class="nx">next</span> <span class="o">===</span> <span class="s2">"+"</span><span class="p">)</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">readInt</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="o">===</span> <span class="kc">null</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Invalid number"</span><span class="p">);</span>
+      <span class="k">if</span> <span class="p">(</span><span class="nx">readInt</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> <span class="o">===</span> <span class="kc">null</span> <span class="o">&&</span> <span class="nx">ch</span> <span class="o">===</span> <span class="s2">"."</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="s2"> [...]
       <span class="nx">isFloat</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
     <span class="p">}</span>
     <span class="k">if</span> <span class="p">(</span><span class="sr">/e/i</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">)))</span> <span class="p">{</span>
diff --git a/test/tests.js b/test/tests.js
index a34b769..5ca91c9 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -25981,6 +25981,50 @@ test("(function () { 'use strict'; '\0'; }())", {
   ]
 });
 
+test("123..toString(10)", {
+  type: "Program",
+  start: 0,
+  end: 17,
+  body: [
+    {
+      type: "ExpressionStatement",
+      start: 0,
+      end: 17,
+      expression: {
+        type: "CallExpression",
+        start: 0,
+        callee: {
+          type: "MemberExpression",
+          start: 0,
+          object: {
+            type: "Literal",
+            start: 0,
+            end: 4,
+            value: 123
+          },
+          property: {
+            type: "Identifier",
+            start: 5,
+            end: 13,
+            name: "toString"
+          },
+          computed: false,
+          end: 13
+        },
+        arguments: [
+          {
+            type: "Literal",
+            start: 14,
+            end: 16,
+            value: 10
+          }
+        ],
+        end: 17
+      }
+    }
+  ]
+});
+
 // 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