Explorar o código

allow use of global Date & new keyword inside expressions (fix #784)

Evan You %!s(int64=11) %!d(string=hai) anos
pai
achega
1a36e39b62
Modificáronse 2 ficheiros con 9 adicións e 2 borrados
  1. 2 2
      src/parsers/expression.js
  2. 7 0
      test/unit/specs/parsers/expression_spec.js

+ 2 - 2
src/parsers/expression.js

@@ -4,7 +4,7 @@ var Cache = require('../cache')
 var expressionCache = new Cache(1000)
 
 var keywords =
-  'Math,break,case,catch,continue,debugger,default,' +
+  'Math,Date,break,case,catch,continue,debugger,default,' +
   'delete,do,else,false,finally,for,function,if,in,' +
   'instanceof,new,null,return,switch,this,throw,true,try,' +
   'typeof,var,void,while,with,undefined,abstract,boolean,' +
@@ -16,7 +16,7 @@ var keywords =
 
 var wsRE = /\s/g
 var newlineRE = /\n/g
-var saveRE = /[\{,]\s*[\w\$_]+\s*:|('[^']*'|"[^"]*")/g
+var saveRE = /[\{,]\s*[\w\$_]+\s*:|('[^']*'|"[^"]*")|new /g
 var restoreRE = /"(\d+)"/g
 var pathTestRE = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\])*$/
 var pathReplaceRE = /[^\w$\.]([A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*)/g

+ 7 - 0
test/unit/specs/parsers/expression_spec.js

@@ -197,6 +197,13 @@ var testCases = [
     },
     expected: true,
     paths: []
+  },
+  {
+    // Date global
+    exp: 'Date.now() > new Date("2000-01-01")',
+    scope: {},
+    expected: true,
+    paths: []
   }
 ]