ast-types
Advanced tools
Comparing version 0.2.4 to 0.2.6
@@ -1,4 +0,5 @@ | ||
var types = require("./types"); | ||
var types = require("../lib/types"); | ||
var Type = types.Type; | ||
var isNumber = types.builtInTypes.number; | ||
var builtin = types.builtInTypes; | ||
var isNumber = builtin.number; | ||
@@ -25,1 +26,17 @@ // An example of constructing a new type with arbitrary constraints from | ||
}; | ||
var naiveIsPrimitive = Type.or( | ||
builtin.string, | ||
builtin.number, | ||
builtin.boolean, | ||
builtin.null, | ||
builtin.undefined | ||
); | ||
exports.isPrimitive = new Type(function(value) { | ||
if (value === null) | ||
return true; | ||
var type = typeof value; | ||
return !(type === "object" || | ||
type === "function"); | ||
}, naiveIsPrimitive.toString()); |
@@ -47,2 +47,11 @@ var assert = require("assert"); | ||
// Like .check, except that failure triggers an AssertionError. | ||
Tp.assert = function(value, deep) { | ||
var result = this.check(value, deep); | ||
assert.ok( | ||
result, | ||
JSON.stringify(value) + " does not match type " + this); | ||
return result; | ||
}; | ||
Tp.toString = function() { | ||
@@ -184,3 +193,3 @@ var name = this.name; | ||
assert.ok(self instanceof Field); | ||
assert.ok(isString.check(name)); | ||
isString.assert(name); | ||
@@ -204,3 +213,3 @@ type = toType(type); | ||
Fp.toString = function() { | ||
return this.name + ": " + this.type; | ||
return JSON.stringify(this.name) + ": " + this.type; | ||
}; | ||
@@ -214,3 +223,3 @@ | ||
Type.def = function(typeName) { | ||
assert.ok(isString.check(typeName)); | ||
isString.assert(typeName); | ||
return defCache.hasOwnProperty(typeName) | ||
@@ -353,3 +362,3 @@ ? defCache[typeName] | ||
each.call(arguments, function(baseName) { | ||
assert.ok(isString.check(baseName)); | ||
isString.assert(baseName); | ||
@@ -380,3 +389,3 @@ // This indexOf lookup may be O(n), but the typical number of base | ||
assert.strictEqual(self.finalized, false); | ||
assert.ok(isString.arrayOf().check(buildParams)); | ||
isString.arrayOf().assert(buildParams); | ||
@@ -429,4 +438,4 @@ // Every buildable type will have its "type" field filled in | ||
JSON.stringify(value) + | ||
" does not match type " + | ||
field.type); | ||
" does not match field " + field + | ||
" of type " + typeName); | ||
@@ -433,0 +442,0 @@ // TODO Could attach getters and setters here to enforce |
10
main.js
@@ -5,10 +5,10 @@ var types = require("./lib/types"); | ||
// git://github.com/ariya/esprima.git#master. | ||
require("./lib/core"); | ||
require("./def/core"); | ||
// Feel free to add to or remove from this list of extension modules to | ||
// configure the precise type hierarchy that you need. | ||
require("./lib/es6"); | ||
require("./lib/mozilla"); | ||
require("./lib/e4x"); | ||
require("./lib/xjs"); | ||
require("./def/es6"); | ||
require("./def/mozilla"); | ||
require("./def/e4x"); | ||
require("./def/xjs"); | ||
@@ -15,0 +15,0 @@ exports.Type = types.Type; |
@@ -21,3 +21,3 @@ { | ||
], | ||
"version": "0.2.4", | ||
"version": "0.2.6", | ||
"homepage": "http://github.com/benjamn/ast-types", | ||
@@ -24,0 +24,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
var types = require("../lib/types"); | ||
var types = require("ast-types"); | ||
var n = types.namedTypes; | ||
@@ -8,4 +8,2 @@ var b = types.builders; | ||
require("../lib/core"); | ||
exports.testBasic = function(t, assert) { | ||
@@ -124,3 +122,3 @@ var fooId = b.identifier("foo"); | ||
validateProgram("lib/shared.js"); | ||
validateProgram("lib/core.js"); | ||
validateProgram("def/core.js"); | ||
validateProgram("lib/types.js"); | ||
@@ -127,0 +125,0 @@ validateProgram("test/run.js"); |
373561
10544