You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/12/18 18:15:58 UTC

[couchdb-esprima] 09/10: Fix division by "this"

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch 1.x
in repository https://gitbox.apache.org/repos/asf/couchdb-esprima.git

commit 313d012ac65d84c7aaba871925dbedad49119444
Author: Edward Faulkner <ef...@alum.mit.edu>
AuthorDate: Tue Dec 9 16:47:35 2014 -0500

    Fix division by "this"
    
    `this / 100` is legal Javascript, and a variation of it actually appears
    in moment.js.
    
    Without this fix, esprima treats it as an un-terminated regular
    expression.
    
    https://code.google.com/p/esprima/issues/detail?id=616
---
 esprima.js   |  2 +-
 test/test.js | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/esprima.js b/esprima.js
index 2a60ad6..a442276 100644
--- a/esprima.js
+++ b/esprima.js
@@ -1260,7 +1260,7 @@ parseStatement: true, parseSourceElement: true */
             }
             return collectRegex();
         }
-        if (prevToken.type === 'Keyword') {
+        if (prevToken.type === 'Keyword' && prevToken.value !== 'this') {
             return collectRegex();
         }
         return scanPunctuator();
diff --git a/test/test.js b/test/test.js
index 2e5831c..f8c8636 100644
--- a/test/test.js
+++ b/test/test.js
@@ -21840,8 +21840,82 @@ var testFixture = {
             lineNumber: 1,
             column: 8,
             message: 'Error: Line 1: Invalid regular expression: missing /'
-        }
+        },
 
+        'this / 100;': [
+          {
+            "type": "Keyword",
+            "value": "this",
+            "range": [
+              0,
+              4
+            ],
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 0
+              },
+              "end": {
+                "line": 1,
+                "column": 4
+              }
+            }
+          },
+          {
+            "type": "Punctuator",
+            "value": "/",
+            "range": [
+              5,
+              6
+            ],
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 5
+              },
+              "end": {
+                "line": 1,
+                "column": 6
+              }
+            }
+          },
+          {
+            "type": "Numeric",
+            "value": "100",
+            "range": [
+              7,
+              10
+            ],
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 7
+              },
+              "end": {
+                "line": 1,
+                "column": 10
+              }
+            }
+          },
+          {
+            "type": "Punctuator",
+            "value": ";",
+            "range": [
+              10,
+              11
+            ],
+            "loc": {
+              "start": {
+                "line": 1,
+                "column": 10
+              },
+              "end": {
+                "line": 1,
+                "column": 11
+              }
+            }
+          }
+        ]
     },
 
     'API': {