Skip to content

Commit 3ea564b

Browse files
committed
fix vuejs#626 Math not recognized as global in simple path
1 parent 19d56bd commit 3ea564b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/parsers/expression.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ exports.parse = function (exp, needSet) {
215215
// we do a simple path check to optimize for them.
216216
// the check fails valid paths with unusal whitespaces,
217217
// but that's too rare and we don't care.
218-
var res = pathTestRE.test(exp)
218+
// also skip paths that start with global "Math"
219+
var res = pathTestRE.test(exp) && exp.slice(0, 5) !== 'Math.'
219220
? compilePathFns(exp)
220221
: compileExpFns(exp, needSet)
221222
expressionCache.put(exp, res)

test/unit/specs/parsers/expression_spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ var testCases = [
175175
},
176176
expected: 8,
177177
paths: ['$a', 'b', 'c', 'e']
178+
},
179+
{
180+
// Math global, simple path
181+
exp: 'Math.PI',
182+
scope: {},
183+
expected: Math.PI,
184+
paths: []
185+
},
186+
{
187+
// Math global, exp
188+
exp: 'Math.sin(a)',
189+
scope: {
190+
a: 1
191+
},
192+
expected: Math.sin(1),
193+
paths: ['a']
178194
}
179195
]
180196

0 commit comments

Comments
 (0)