Sfoglia il codice sorgente

fix #242 expressions with object literals

Evan You 12 anni fa
parent
commit
e422d95945
2 ha cambiato i file con 11 aggiunte e 1 eliminazioni
  1. 1 1
      src/exp-parser.js
  2. 10 0
      test/unit/specs/exp-parser.js

+ 1 - 1
src/exp-parser.js

@@ -23,7 +23,7 @@ var KEYWORDS =
         ',Math',
         
     KEYWORDS_RE = new RegExp(["\\b" + KEYWORDS.replace(/,/g, '\\b|\\b') + "\\b"].join('|'), 'g'),
-    REMOVE_RE   = /\/\*(?:.|\n)*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|'[^']*'|"[^"]*"|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,
+    REMOVE_RE   = /\/\*(?:.|\n)*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|'[^']*'|"[^"]*"|[\s\t\n]*\.[\s\t\n]*[$\w\.]+|[\{,]\s*[\w\$_]+\s*:/g,
     SPLIT_RE    = /[^\w$]+/g,
     NUMBER_RE   = /\b\d[^,]*/g,
     BOUNDARY_RE = /^,+|,+$/g

+ 10 - 0
test/unit/specs/exp-parser.js

@@ -82,6 +82,16 @@ describe('Expression Parser', function () {
                 hi: 2
             },
             expectedValue: '"test"1\'hi\'2'
+        },
+        {
+            // expressions with inline object literals
+            exp: "sortRows({ column: 'name', test: 'haha', durrr: 123 })",
+            vm: {
+                sortRows: function (params) {
+                    return params.column + params.durrr
+                }
+            },
+            expectedValue: 'name123'
         }
     ]