don't statically evaluate Math.random - fixes babel-plugins/babel-plugin-constant-folding#1

This commit is contained in:
Sebastian McKenzie 2015-08-13 15:32:50 +01:00
parent 2cca81d4a3
commit def1f8823e

View File

@ -1,6 +1,7 @@
/* eslint eqeqeq: 0 */
const VALID_CALLEES = ["String", "Number", "Math"];
const INVALID_METHODS = ["random"];
/**
* Walk the input `node` and statically evaluate if it's truthy.
@ -180,7 +181,7 @@ export function evaluate(): { confident: boolean; value: any } {
var property = callee.get("property");
// Math.min(1, 2)
if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0) {
if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) {
context = global[object.node.name];
func = context[property.node.name];
}