summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/levn/lib/coerce.js
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2017-12-22 16:53:42 +0100
committerMichaël Zasso <targos@protonmail.com>2018-01-11 09:48:05 +0100
commit3dc30632755713179f345f4af024bd904c6162d0 (patch)
treef28c4f6dd6dfc5992edf301449d1a371d229755b /tools/node_modules/eslint/node_modules/levn/lib/coerce.js
parenta2c7085dd4a8e60d1a47572aca8bb6fcb7a32f88 (diff)
downloadandroid-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.gz
android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.bz2
android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.zip
tools: move eslint from tools to tools/node_modules
This is required because we need to add the babel-eslint dependency and it has to be able to resolve "eslint". babel-eslint is required to support future ES features such as async iterators and import.meta. Refs: https://github.com/nodejs/node/pull/17755 PR-URL: https://github.com/nodejs/node/pull/17820 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/node_modules/levn/lib/coerce.js')
-rw-r--r--tools/node_modules/eslint/node_modules/levn/lib/coerce.js285
1 files changed, 285 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/levn/lib/coerce.js b/tools/node_modules/eslint/node_modules/levn/lib/coerce.js
new file mode 100644
index 0000000000..027b6da022
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/levn/lib/coerce.js
@@ -0,0 +1,285 @@
+// Generated by LiveScript 1.2.0
+(function(){
+ var parsedTypeCheck, types, toString$ = {}.toString;
+ parsedTypeCheck = require('type-check').parsedTypeCheck;
+ types = {
+ '*': function(it){
+ switch (toString$.call(it).slice(8, -1)) {
+ case 'Array':
+ return coerceType(it, {
+ type: 'Array'
+ });
+ case 'Object':
+ return coerceType(it, {
+ type: 'Object'
+ });
+ default:
+ return {
+ type: 'Just',
+ value: coerceTypes(it, [
+ {
+ type: 'Undefined'
+ }, {
+ type: 'Null'
+ }, {
+ type: 'NaN'
+ }, {
+ type: 'Boolean'
+ }, {
+ type: 'Number'
+ }, {
+ type: 'Date'
+ }, {
+ type: 'RegExp'
+ }, {
+ type: 'Array'
+ }, {
+ type: 'Object'
+ }, {
+ type: 'String'
+ }
+ ], {
+ explicit: true
+ })
+ };
+ }
+ },
+ Undefined: function(it){
+ if (it === 'undefined' || it === void 8) {
+ return {
+ type: 'Just',
+ value: void 8
+ };
+ } else {
+ return {
+ type: 'Nothing'
+ };
+ }
+ },
+ Null: function(it){
+ if (it === 'null') {
+ return {
+ type: 'Just',
+ value: null
+ };
+ } else {
+ return {
+ type: 'Nothing'
+ };
+ }
+ },
+ NaN: function(it){
+ if (it === 'NaN') {
+ return {
+ type: 'Just',
+ value: NaN
+ };
+ } else {
+ return {
+ type: 'Nothing'
+ };
+ }
+ },
+ Boolean: function(it){
+ if (it === 'true') {
+ return {
+ type: 'Just',
+ value: true
+ };
+ } else if (it === 'false') {
+ return {
+ type: 'Just',
+ value: false
+ };
+ } else {
+ return {
+ type: 'Nothing'
+ };
+ }
+ },
+ Number: function(it){
+ return {
+ type: 'Just',
+ value: +it
+ };
+ },
+ Int: function(it){
+ return {
+ type: 'Just',
+ value: parseInt(it)
+ };
+ },
+ Float: function(it){
+ return {
+ type: 'Just',
+ value: parseFloat(it)
+ };
+ },
+ Date: function(value, options){
+ var that;
+ if (that = /^\#(.*)\#$/.exec(value)) {
+ return {
+ type: 'Just',
+ value: new Date(+that[1] || that[1])
+ };
+ } else if (options.explicit) {
+ return {
+ type: 'Nothing'
+ };
+ } else {
+ return {
+ type: 'Just',
+ value: new Date(+value || value)
+ };
+ }
+ },
+ RegExp: function(value, options){
+ var that;
+ if (that = /^\/(.*)\/([gimy]*)$/.exec(value)) {
+ return {
+ type: 'Just',
+ value: new RegExp(that[1], that[2])
+ };
+ } else if (options.explicit) {
+ return {
+ type: 'Nothing'
+ };
+ } else {
+ return {
+ type: 'Just',
+ value: new RegExp(value)
+ };
+ }
+ },
+ Array: function(it){
+ return coerceArray(it, {
+ of: [{
+ type: '*'
+ }]
+ });
+ },
+ Object: function(it){
+ return coerceFields(it, {
+ of: {}
+ });
+ },
+ String: function(it){
+ var that;
+ if (toString$.call(it).slice(8, -1) !== 'String') {
+ return {
+ type: 'Nothing'
+ };
+ }
+ if (that = it.match(/^'(.*)'$/)) {
+ return {
+ type: 'Just',
+ value: that[1]
+ };
+ } else if (that = it.match(/^"(.*)"$/)) {
+ return {
+ type: 'Just',
+ value: that[1]
+ };
+ } else {
+ return {
+ type: 'Just',
+ value: it
+ };
+ }
+ }
+ };
+ function coerceArray(node, type){
+ var typeOf, element;
+ if (toString$.call(node).slice(8, -1) !== 'Array') {
+ return {
+ type: 'Nothing'
+ };
+ }
+ typeOf = type.of;
+ return {
+ type: 'Just',
+ value: (function(){
+ var i$, ref$, len$, results$ = [];
+ for (i$ = 0, len$ = (ref$ = node).length; i$ < len$; ++i$) {
+ element = ref$[i$];
+ results$.push(coerceTypes(element, typeOf));
+ }
+ return results$;
+ }())
+ };
+ }
+ function coerceTuple(node, type){
+ var result, i$, ref$, len$, i, types, that;
+ if (toString$.call(node).slice(8, -1) !== 'Array') {
+ return {
+ type: 'Nothing'
+ };
+ }
+ result = [];
+ for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
+ i = i$;
+ types = ref$[i$];
+ if (that = coerceTypes(node[i], types)) {
+ result.push(that);
+ }
+ }
+ return {
+ type: 'Just',
+ value: result
+ };
+ }
+ function coerceFields(node, type){
+ var typeOf, key, value;
+ if (toString$.call(node).slice(8, -1) !== 'Object') {
+ return {
+ type: 'Nothing'
+ };
+ }
+ typeOf = type.of;
+ return {
+ type: 'Just',
+ value: (function(){
+ var ref$, results$ = {};
+ for (key in ref$ = node) {
+ value = ref$[key];
+ results$[key] = coerceTypes(value, typeOf[key] || [{
+ type: '*'
+ }]);
+ }
+ return results$;
+ }())
+ };
+ }
+ function coerceType(node, typeObj, options){
+ var type, structure, coerceFunc;
+ type = typeObj.type, structure = typeObj.structure;
+ if (type) {
+ coerceFunc = types[type];
+ return coerceFunc(node, options);
+ } else {
+ switch (structure) {
+ case 'array':
+ return coerceArray(node, typeObj);
+ case 'tuple':
+ return coerceTuple(node, typeObj);
+ case 'fields':
+ return coerceFields(node, typeObj);
+ }
+ }
+ }
+ function coerceTypes(node, types, options){
+ var i$, len$, type, ref$, valueType, value;
+ for (i$ = 0, len$ = types.length; i$ < len$; ++i$) {
+ type = types[i$];
+ ref$ = coerceType(node, type, options), valueType = ref$.type, value = ref$.value;
+ if (valueType === 'Nothing') {
+ continue;
+ }
+ if (parsedTypeCheck([type], value)) {
+ return value;
+ }
+ }
+ throw new Error("Value " + JSON.stringify(node) + " does not type check against " + JSON.stringify(types) + ".");
+ }
+ module.exports = coerceTypes;
+}).call(this);