ast-types
Advanced tools
Comparing version 0.3.9 to 0.3.10
@@ -6,5 +6,7 @@ var assert = require("assert"); | ||
var each = Ap.forEach; | ||
var objToStr = Object.prototype.toString; | ||
var Op = Object.prototype; | ||
var objToStr = Op.toString; | ||
var funObjStr = objToStr.call(function(){}); | ||
var strObjStr = objToStr.call(""); | ||
var hasOwn = Op.hasOwnProperty; | ||
@@ -250,3 +252,3 @@ // A type is an object with a .check method that takes a value and returns | ||
isString.assert(typeName); | ||
return defCache.hasOwnProperty(typeName) | ||
return hasOwn.call(defCache, typeName) | ||
? defCache[typeName] | ||
@@ -283,4 +285,4 @@ : defCache[typeName] = new Def(typeName); | ||
if (isObject.check(value) && | ||
value.hasOwnProperty("type") && | ||
defCache.hasOwnProperty(value.type)) | ||
hasOwn.call(value, "type") && | ||
hasOwn.call(defCache, value.type)) | ||
{ | ||
@@ -299,3 +301,3 @@ var vDef = defCache[value.type]; | ||
assert.strictEqual(that.finalized, true); | ||
return that.allSupertypes.hasOwnProperty(this.typeName); | ||
return hasOwn.call(that.allSupertypes, this.typeName); | ||
} else { | ||
@@ -429,7 +431,7 @@ assert.ok(false, that + " is not a Def"); | ||
function add(param, i) { | ||
if (built.hasOwnProperty(param)) | ||
if (hasOwn.call(built, param)) | ||
return; | ||
var all = self.allFields; | ||
assert.ok(all.hasOwnProperty(param), param); | ||
assert.ok(hasOwn.call(all, param), param); | ||
@@ -548,2 +550,13 @@ var field = all[param]; | ||
}, context); | ||
} else { | ||
assert.strictEqual( | ||
"type" in object, false, | ||
"did not recognize object of type " + JSON.stringify(object.type) | ||
); | ||
// If we could not infer a Def type for this object, just | ||
// iterate over its keys in the normal way. | ||
Object.keys(object).forEach(function(name) { | ||
callback.call(this, name, object[name]); | ||
}, context); | ||
} | ||
@@ -571,5 +584,12 @@ } | ||
// If the object has no fields, then of course no field satisified | ||
// the predicate. | ||
return false; | ||
assert.strictEqual( | ||
"type" in object, false, | ||
"did not recognize object of type " + JSON.stringify(object.type) | ||
); | ||
// If we could not infer a Def type for this object, just iterate | ||
// over its keys in the normal way. | ||
return Object.keys(object).some(function(name) { | ||
return callback.call(this, name, object[name]); | ||
}, context); | ||
} | ||
@@ -576,0 +596,0 @@ }); |
@@ -21,3 +21,3 @@ { | ||
], | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"homepage": "http://github.com/benjamn/ast-types", | ||
@@ -24,0 +24,0 @@ "repository": { |
@@ -252,4 +252,11 @@ var types = require("../main"); | ||
check({ type: "asdf" }, []); | ||
assert.throws(function() { | ||
check({ type: "asdf" }, ["type"]); | ||
}, "did not recognize object of type " + JSON.stringify("asdf")); | ||
check({ | ||
line: 10, | ||
column: 37 | ||
}, ["line", "column"]); | ||
t.finish(); | ||
@@ -256,0 +263,0 @@ }; |
409935
11470