@@ -3,24 +3,29 @@ var Path = require('./path')
3
3
var Cache = require ( '../cache' )
4
4
var expressionCache = new Cache ( 1000 )
5
5
6
- var keywords =
7
- 'Math,Date,break,case,catch,continue,debugger,default,' +
8
- 'delete,do,else,false,finally,for,function,if,in,' +
9
- 'instanceof,new,null,return,switch,this,throw,true,try,' +
10
- 'typeof,var,void,while,with,undefined,abstract,boolean,' +
11
- 'byte,char,class,const,double,enum,export,extends,' +
12
- 'final,float,goto,implements,import,int,interface,long,' +
13
- 'native,package,private,protected,public,short,static,' +
14
- 'super,synchronized,throws,transient,volatile,' +
15
- 'arguments,let,yield'
6
+ var allowedKeywords =
7
+ 'Math,Date,this,true,false,null,undefined,Infinity,NaN,' +
8
+ 'isNaN,isFinite,decodeURI,decodeURIComponent,encodeURI,' +
9
+ 'encodeURIComponent,parseInt,parseFloat'
10
+ var allowedKeywordsRE =
11
+ new RegExp ( '^(' + allowedKeywords . replace ( / , / g, '\\b|' ) + '\\b)' )
12
+
13
+ // keywords that don't make sense inside expressions
14
+ var imporperKeywords =
15
+ 'break,case,class,catch,const,continue,debugger,default,' +
16
+ 'delete,do,else,export,extends,finally,for,function,if,' +
17
+ 'import,in,instanceof,let,return,super,switch,throw,try,' +
18
+ 'var,while,with,yield,enum,await,implements,package,' +
19
+ 'proctected,static,interface,private,public'
20
+ var imporoperKeywordsRE =
21
+ new RegExp ( '^(' + imporperKeywords . replace ( / , / g, '\\b|' ) + '\\b)' )
16
22
17
23
var wsRE = / \s / g
18
24
var newlineRE = / \n / g
19
- var saveRE = / [ \{ , ] \s * [ \w \$ _ ] + \s * : | ( ' [ ^ ' ] * ' | " [ ^ " ] * " ) | n e w / g
25
+ var saveRE = / [ \{ , ] \s * [ \w \$ _ ] + \s * : | ( ' [ ^ ' ] * ' | " [ ^ " ] * " ) | n e w | t y p e o f | v o i d / g
20
26
var restoreRE = / " ( \d + ) " / g
21
27
var pathTestRE = / ^ [ A - Z a - z _ $ ] [ \w $ ] * ( \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' .* ?' \] | \[ " .* ?" \] | \[ \d + \] ) * $ /
22
28
var pathReplaceRE = / [ ^ \w $ \. ] ( [ A - Z a - z _ $ ] [ \w $ ] * ( \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' .* ?' \] | \[ " .* ?" \] ) * ) / g
23
- var keywordsRE = new RegExp ( '^(' + keywords . replace ( / , / g, '\\b|' ) + '\\b)' )
24
29
var booleanLiteralRE = / ^ ( t r u e | f a l s e ) $ /
25
30
26
31
/**
@@ -68,7 +73,7 @@ function save (str, isString) {
68
73
function rewrite ( raw ) {
69
74
var c = raw . charAt ( 0 )
70
75
var path = raw . slice ( 1 )
71
- if ( keywordsRE . test ( path ) ) {
76
+ if ( allowedKeywordsRE . test ( path ) ) {
72
77
return raw
73
78
} else {
74
79
path = path . indexOf ( '"' ) > - 1
@@ -100,6 +105,12 @@ function restore (str, i) {
100
105
*/
101
106
102
107
function compileExpFns ( exp , needSet ) {
108
+ if ( imporoperKeywordsRE . test ( exp ) ) {
109
+ _ . warn (
110
+ 'Avoid using reserved keywords in expression: '
111
+ + exp
112
+ )
113
+ }
103
114
// reset state
104
115
saved . length = 0
105
116
// save strings and object literal keys
@@ -230,7 +241,9 @@ exports.parse = function (exp, needSet) {
230
241
// global "Math"
231
242
var res =
232
243
pathTestRE . test ( exp ) &&
244
+ // don't treat true/false as paths
233
245
! booleanLiteralRE . test ( exp ) &&
246
+ // Math constants e.g. Math.PI, Math.E etc.
234
247
exp . slice ( 0 , 5 ) !== 'Math.'
235
248
? compilePathFns ( exp )
236
249
: compileExpFns ( exp , needSet )
0 commit comments