summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/type-check/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/type-check/lib')
-rw-r--r--tools/node_modules/eslint/node_modules/type-check/lib/check.js126
-rw-r--r--tools/node_modules/eslint/node_modules/type-check/lib/index.js16
-rw-r--r--tools/node_modules/eslint/node_modules/type-check/lib/parse-type.js196
3 files changed, 338 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/type-check/lib/check.js b/tools/node_modules/eslint/node_modules/type-check/lib/check.js
new file mode 100644
index 0000000000..0504c8d2f4
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/type-check/lib/check.js
@@ -0,0 +1,126 @@
+// Generated by LiveScript 1.4.0
+(function(){
+ var ref$, any, all, isItNaN, types, defaultType, customTypes, toString$ = {}.toString;
+ ref$ = require('prelude-ls'), any = ref$.any, all = ref$.all, isItNaN = ref$.isItNaN;
+ types = {
+ Number: {
+ typeOf: 'Number',
+ validate: function(it){
+ return !isItNaN(it);
+ }
+ },
+ NaN: {
+ typeOf: 'Number',
+ validate: isItNaN
+ },
+ Int: {
+ typeOf: 'Number',
+ validate: function(it){
+ return !isItNaN(it) && it % 1 === 0;
+ }
+ },
+ Float: {
+ typeOf: 'Number',
+ validate: function(it){
+ return !isItNaN(it);
+ }
+ },
+ Date: {
+ typeOf: 'Date',
+ validate: function(it){
+ return !isItNaN(it.getTime());
+ }
+ }
+ };
+ defaultType = {
+ array: 'Array',
+ tuple: 'Array'
+ };
+ function checkArray(input, type){
+ return all(function(it){
+ return checkMultiple(it, type.of);
+ }, input);
+ }
+ function checkTuple(input, type){
+ var i, i$, ref$, len$, types;
+ i = 0;
+ for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
+ types = ref$[i$];
+ if (!checkMultiple(input[i], types)) {
+ return false;
+ }
+ i++;
+ }
+ return input.length <= i;
+ }
+ function checkFields(input, type){
+ var inputKeys, numInputKeys, k, numOfKeys, key, ref$, types;
+ inputKeys = {};
+ numInputKeys = 0;
+ for (k in input) {
+ inputKeys[k] = true;
+ numInputKeys++;
+ }
+ numOfKeys = 0;
+ for (key in ref$ = type.of) {
+ types = ref$[key];
+ if (!checkMultiple(input[key], types)) {
+ return false;
+ }
+ if (inputKeys[key]) {
+ numOfKeys++;
+ }
+ }
+ return type.subset || numInputKeys === numOfKeys;
+ }
+ function checkStructure(input, type){
+ if (!(input instanceof Object)) {
+ return false;
+ }
+ switch (type.structure) {
+ case 'fields':
+ return checkFields(input, type);
+ case 'array':
+ return checkArray(input, type);
+ case 'tuple':
+ return checkTuple(input, type);
+ }
+ }
+ function check(input, typeObj){
+ var type, structure, setting, that;
+ type = typeObj.type, structure = typeObj.structure;
+ if (type) {
+ if (type === '*') {
+ return true;
+ }
+ setting = customTypes[type] || types[type];
+ if (setting) {
+ return setting.typeOf === toString$.call(input).slice(8, -1) && setting.validate(input);
+ } else {
+ return type === toString$.call(input).slice(8, -1) && (!structure || checkStructure(input, typeObj));
+ }
+ } else if (structure) {
+ if (that = defaultType[structure]) {
+ if (that !== toString$.call(input).slice(8, -1)) {
+ return false;
+ }
+ }
+ return checkStructure(input, typeObj);
+ } else {
+ throw new Error("No type defined. Input: " + input + ".");
+ }
+ }
+ function checkMultiple(input, types){
+ if (toString$.call(types).slice(8, -1) !== 'Array') {
+ throw new Error("Types must be in an array. Input: " + input + ".");
+ }
+ return any(function(it){
+ return check(input, it);
+ }, types);
+ }
+ module.exports = function(parsedType, input, options){
+ options == null && (options = {});
+ customTypes = options.customTypes || {};
+ return checkMultiple(input, parsedType);
+ };
+}).call(this);
diff --git a/tools/node_modules/eslint/node_modules/type-check/lib/index.js b/tools/node_modules/eslint/node_modules/type-check/lib/index.js
new file mode 100644
index 0000000000..f3316bab49
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/type-check/lib/index.js
@@ -0,0 +1,16 @@
+// Generated by LiveScript 1.4.0
+(function(){
+ var VERSION, parseType, parsedTypeCheck, typeCheck;
+ VERSION = '0.3.2';
+ parseType = require('./parse-type');
+ parsedTypeCheck = require('./check');
+ typeCheck = function(type, input, options){
+ return parsedTypeCheck(parseType(type), input, options);
+ };
+ module.exports = {
+ VERSION: VERSION,
+ typeCheck: typeCheck,
+ parsedTypeCheck: parsedTypeCheck,
+ parseType: parseType
+ };
+}).call(this);
diff --git a/tools/node_modules/eslint/node_modules/type-check/lib/parse-type.js b/tools/node_modules/eslint/node_modules/type-check/lib/parse-type.js
new file mode 100644
index 0000000000..5baf661fae
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/type-check/lib/parse-type.js
@@ -0,0 +1,196 @@
+// Generated by LiveScript 1.4.0
+(function(){
+ var identifierRegex, tokenRegex;
+ identifierRegex = /[\$\w]+/;
+ function peek(tokens){
+ var token;
+ token = tokens[0];
+ if (token == null) {
+ throw new Error('Unexpected end of input.');
+ }
+ return token;
+ }
+ function consumeIdent(tokens){
+ var token;
+ token = peek(tokens);
+ if (!identifierRegex.test(token)) {
+ throw new Error("Expected text, got '" + token + "' instead.");
+ }
+ return tokens.shift();
+ }
+ function consumeOp(tokens, op){
+ var token;
+ token = peek(tokens);
+ if (token !== op) {
+ throw new Error("Expected '" + op + "', got '" + token + "' instead.");
+ }
+ return tokens.shift();
+ }
+ function maybeConsumeOp(tokens, op){
+ var token;
+ token = tokens[0];
+ if (token === op) {
+ return tokens.shift();
+ } else {
+ return null;
+ }
+ }
+ function consumeArray(tokens){
+ var types;
+ consumeOp(tokens, '[');
+ if (peek(tokens) === ']') {
+ throw new Error("Must specify type of Array - eg. [Type], got [] instead.");
+ }
+ types = consumeTypes(tokens);
+ consumeOp(tokens, ']');
+ return {
+ structure: 'array',
+ of: types
+ };
+ }
+ function consumeTuple(tokens){
+ var components;
+ components = [];
+ consumeOp(tokens, '(');
+ if (peek(tokens) === ')') {
+ throw new Error("Tuple must be of at least length 1 - eg. (Type), got () instead.");
+ }
+ for (;;) {
+ components.push(consumeTypes(tokens));
+ maybeConsumeOp(tokens, ',');
+ if (')' === peek(tokens)) {
+ break;
+ }
+ }
+ consumeOp(tokens, ')');
+ return {
+ structure: 'tuple',
+ of: components
+ };
+ }
+ function consumeFields(tokens){
+ var fields, subset, ref$, key, types;
+ fields = {};
+ consumeOp(tokens, '{');
+ subset = false;
+ for (;;) {
+ if (maybeConsumeOp(tokens, '...')) {
+ subset = true;
+ break;
+ }
+ ref$ = consumeField(tokens), key = ref$[0], types = ref$[1];
+ fields[key] = types;
+ maybeConsumeOp(tokens, ',');
+ if ('}' === peek(tokens)) {
+ break;
+ }
+ }
+ consumeOp(tokens, '}');
+ return {
+ structure: 'fields',
+ of: fields,
+ subset: subset
+ };
+ }
+ function consumeField(tokens){
+ var key, types;
+ key = consumeIdent(tokens);
+ consumeOp(tokens, ':');
+ types = consumeTypes(tokens);
+ return [key, types];
+ }
+ function maybeConsumeStructure(tokens){
+ switch (tokens[0]) {
+ case '[':
+ return consumeArray(tokens);
+ case '(':
+ return consumeTuple(tokens);
+ case '{':
+ return consumeFields(tokens);
+ }
+ }
+ function consumeType(tokens){
+ var token, wildcard, type, structure;
+ token = peek(tokens);
+ wildcard = token === '*';
+ if (wildcard || identifierRegex.test(token)) {
+ type = wildcard
+ ? consumeOp(tokens, '*')
+ : consumeIdent(tokens);
+ structure = maybeConsumeStructure(tokens);
+ if (structure) {
+ return structure.type = type, structure;
+ } else {
+ return {
+ type: type
+ };
+ }
+ } else {
+ structure = maybeConsumeStructure(tokens);
+ if (!structure) {
+ throw new Error("Unexpected character: " + token);
+ }
+ return structure;
+ }
+ }
+ function consumeTypes(tokens){
+ var lookahead, types, typesSoFar, typeObj, type;
+ if ('::' === peek(tokens)) {
+ throw new Error("No comment before comment separator '::' found.");
+ }
+ lookahead = tokens[1];
+ if (lookahead != null && lookahead === '::') {
+ tokens.shift();
+ tokens.shift();
+ }
+ types = [];
+ typesSoFar = {};
+ if ('Maybe' === peek(tokens)) {
+ tokens.shift();
+ types = [
+ {
+ type: 'Undefined'
+ }, {
+ type: 'Null'
+ }
+ ];
+ typesSoFar = {
+ Undefined: true,
+ Null: true
+ };
+ }
+ for (;;) {
+ typeObj = consumeType(tokens), type = typeObj.type;
+ if (!typesSoFar[type]) {
+ types.push(typeObj);
+ }
+ typesSoFar[type] = true;
+ if (!maybeConsumeOp(tokens, '|')) {
+ break;
+ }
+ }
+ return types;
+ }
+ tokenRegex = RegExp('\\.\\.\\.|::|->|' + identifierRegex.source + '|\\S', 'g');
+ module.exports = function(input){
+ var tokens, e;
+ if (!input.length) {
+ throw new Error('No type specified.');
+ }
+ tokens = input.match(tokenRegex) || [];
+ if (in$('->', tokens)) {
+ throw new Error("Function types are not supported.\ To validate that something is a function, you may use 'Function'.");
+ }
+ try {
+ return consumeTypes(tokens);
+ } catch (e$) {
+ e = e$;
+ throw new Error(e.message + " - Remaining tokens: " + JSON.stringify(tokens) + " - Initial input: '" + input + "'");
+ }
+ };
+ function in$(x, xs){
+ var i = -1, l = xs.length >>> 0;
+ while (++i < l) if (x === xs[i]) return true;
+ return false;
+ }
+}).call(this);