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

This commit is contained in:
Evan You 2015-04-15 13:37:50 -04:00
parent 85799dfd35
commit 1a36e39b62
2 changed files with 9 additions and 2 deletions

View File

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

View File

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