create: function (context) {
    var options = {
      closingSlash: 'never',
      beforeSelfClosing: 'always',
      afterOpening: 'never'
    };
    for (var key in options) {
      if (has(options, key) && has(context.options[0] || {}, key)) {
        options[key] = context.options[0][key];
      }
    }

    return {
      JSXOpeningElement: function (node) {
        if (options.closingSlash !== 'allow' && node.selfClosing) {
          validateClosingSlash(context, node, options.closingSlash);
        }
        if (options.afterOpening !== 'allow') {
          validateAfterOpening(context, node, options.afterOpening);
        }
        if (options.beforeSelfClosing !== 'allow' && node.selfClosing) {
          validateBeforeSelfClosing(context, node, options.beforeSelfClosing);
        }
      },
      JSXClosingElement: function (node) {
        if (options.afterOpening !== 'allow') {
          validateAfterOpening(context, node, options.afterOpening);
        }
        if (options.closingSlash !== 'allow') {
          validateClosingSlash(context, node, options.closingSlash);
        }
      }
    };
  }
	IsPropertyDescriptor: function IsPropertyDescriptor(Desc) {
		if (this.Type(Desc) !== 'Object') {
			return false;
		}
		var allowed = {
			'[[Configurable]]': true,
			'[[Enumerable]]': true,
			'[[Get]]': true,
			'[[Set]]': true,
			'[[Value]]': true,
			'[[Writable]]': true
		};

		for (var key in Desc) { // eslint-disable-line
			if (has(Desc, key) && !allowed[key]) {
				return false;
			}
		}

		var isData = has(Desc, '[[Value]]');
		var IsAccessor = has(Desc, '[[Get]]') || has(Desc, '[[Set]]');
		if (isData && IsAccessor) {
			throw new $TypeError('Property Descriptors may not be both accessor and data descriptors');
		}
		return true;
	},
function getDependency(name, options) {
    var tree = options.tree, overrides = options.overrides;
    if (has(options.overrides, name)) {
        return tree.dependencies[overrides[name]];
    }
    if (has(tree.dependencies, name)) {
        return tree.dependencies[name];
    }
}
Example #4
0
  function onResponse(err, res) {
    if (err || res.status !== 200) {
      console.error("Failed to fetch data from bountysource:",
          res.status, err);
      queue.push(null);
      flush();
      return;
    }

    if (!res.body.length) {
      queue.push(null);
      flush();
      return;
    }

    page++;

    for (var i = 0; i < res.body.length; i++) {
      var rawSponsor = res.body[i];
      // Sponsors without id are anonymous
      if (has(rawSponsor, 'id')) {
        var sponsor = {
          id: rawSponsor.slug,
          name: rawSponsor.display_name,
          amount: parseFloat(rawSponsor.monthly_amount),
          url: null,
          logoUrl: null,
          frontLogoUrl: null,
          imageUrl: rawSponsor.image_url_large
        };

        if (sponsor.amount < 1) {
          continue;
        }

        if (has(override, sponsor.id)) {
          sponsor.url = override[sponsor.id].url;
          if (override[sponsor.id].imageUrl)
            sponsor.imageUrl = override[sponsor.id].imageUrl;
          if (override[sponsor.id].frontImageUrl)
            sponsor.frontImageUrl = override[sponsor.id].frontImageUrl;
        }

        queue.push(sponsor);

        if (!--count) {
          queue.push(null);
          break;
        }
      }
    }

    flush();
  }
function defineProperty(object, property, descriptor) {
  if ((typeof object !== "object" && typeof object !== "function") || object === null) {
    throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  }
  if ((typeof descriptor !== "object" && typeof descriptor !== "function") || descriptor === null) {
    throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  }
  // make a valiant attempt to use the real defineProperty
  // for I8's DOM elements.
  if (definePropertyFallback) {
    try {
      return definePropertyFallback.call(Object, object, property, descriptor);
    } catch (exception) {
      // try the shim if the real one doesn't work
    }
  }

  // If it's a data property.
  if (has(descriptor, "value")) {
    // fail silently if "writable", "enumerable", or "configurable"
    // are requested but not supported
    if (supportsAccessors && (lookupGetter(object, property) ||
                              lookupSetter(object, property)))
      {
        // As accessors are supported only on engines implementing
        // `__proto__` we can safely override `__proto__` while defining
        // a property to make sure that we don't hit an inherited
        // accessor.
        var prototype = object.__proto__;
        object.__proto__ = prototypeOfObject;
        // Deleting a property anyway since getter / setter may be
        // defined on object itself.
        delete object[property];
        object[property] = descriptor.value;
        // Setting original `__proto__` back now.
        object.__proto__ = prototype;
      } else {
        object[property] = descriptor.value;
      }
  } else {
    if (!supportsAccessors) {
      throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
    }
    // If we got that far then getters and setters can be defined !!
    if (has(descriptor, "get")) {
      defineGetter(object, property, descriptor.get);
    }
    if (has(descriptor, "set")) {
      defineSetter(object, property, descriptor.set);
    }
  }
  return object;
}
	IsAccessorDescriptor: function IsAccessorDescriptor(Desc) {
		if (typeof Desc === 'undefined') {
			return false;
		}

		assertRecord(this, 'Property Descriptor', 'Desc', Desc);

		if (!has(Desc, '[[Get]]') && !has(Desc, '[[Set]]')) {
			return false;
		}

		return true;
	},
	IsDataDescriptor: function IsDataDescriptor(Desc) {
		if (typeof Desc === 'undefined') {
			return false;
		}

		assertRecord(this, 'Property Descriptor', 'Desc', Desc);

		if (!has(Desc, '[[Value]]') && !has(Desc, '[[Writable]]')) {
			return false;
		}

		return true;
	},
Example #8
0
 rvers.forEach(function (v) {
     if (has(self.lhashes, v.hash)) {
         var lv = self.lhashes[v.hash];
         if (lv.message !== v.message) {} // conflict!
         else if (lv.version !== v.version) {} // conflict!
         else {} // ok...
     }
     else if (has(self.lnums, v.version)) {
         var lv = self.lnums[v.version];
         if (lv.message !== v.message) {} // conflict!
         else if (lv.version !== v.version) {} // conflict!
         else {} // ok...
     }
     else newvers.push(v);
 });
Example #9
0
	IsDataDescriptor: function IsDataDescriptor(Desc) {
		if (typeof Desc === 'undefined') {
			return false;
		}

		if (!this.IsPropertyDescriptor(Desc)) {
			throw new TypeError('Desc must be a Property Descriptor');
		}

		if (!has(Desc, '[[Value]]') && !has(Desc, '[[Writable]]')) {
			return false;
		}

		return true;
	},
Example #10
0
	IsAccessorDescriptor: function IsAccessorDescriptor(Desc) {
		if (typeof Desc === 'undefined') {
			return false;
		}

		if (!this.IsPropertyDescriptor(Desc)) {
			throw new TypeError('Desc must be a Property Descriptor');
		}

		if (!has(Desc, '[[Get]]') && !has(Desc, '[[Set]]')) {
			return false;
		}

		return true;
	},
Example #11
0
  /**
   * Data management.
   *
   * Getter / setter for processor-specific informtion.
   *
   * @param {string} key - Key to get or set.
   * @param {*} value - Value to set.
   * @return {*} - Either the operator on processor in
   *   setter mode; or the value stored as `key` in
   *   getter mode.
   */
  function data(key, value) {
    assertConcrete('data');

    if (typeof key === 'string') {
      /* Set `key`. */
      if (arguments.length === 2) {
        namespace[key] = value;

        return processor;
      }

      /* Get `key`. */
      return (has(namespace, key) && namespace[key]) || null;
    }

    /* Get space. */
    if (!key) {
      return namespace;
    }

    /* Set space. */
    namespace = key;

    return processor;
  }
Example #12
0
function i18nWrap(locale, key) {
    if (!has(locales, locale)) {
        i18n.add(locale, loadLocale(locale));
        locales[locale] = true;
    }
    i18n(locale, key);
}
Example #13
0
  return (req, res) => {
    // set content type
    res.setHeader('content-type', 'text/html');

    // create html stream, gzip, then pipe to response
    const tr = trumpet();
    tr.pipe(oppressor(req)).pipe(res);

    // create a write stream to the .page selector
    const pageStream = tr.select('.page').createWriteStream();

    // check if the user is "logged in"
    const cookies = cookie.parse(req.headers.cookie || '');
    const isSession = cookies.session && has(sessions, cookies.session);

    if (isSession) {
      // pipe a read stream to the page selector
      const chat = trumpet();
      chat.pipe(pageStream);

      // update the usernmae
      const username = chat.select('.username').createWriteStream();
      username.end(sessions[cookies.session]);

      // pipe the chat html to the stream that pipes to .page
      fs.createReadStream('browser/pages/chat.html').pipe(chat);

    } else {
      // pipe the rendered html to stream that pipes to .page
      fs.createReadStream(`browser/pages/${page}.html`).pipe(pageStream);
    }

    // pipe the root html to the html stream
    fs.createReadStream('browser/index.html').pipe(tr);
  };
Example #14
0
 function getOption(type) {
   const userOptions = context.options[0] || {};
   if (has(userOptions, type)) {
     return userOptions[type];
   }
   return DEFAULTS[type];
 }
      'Program:exit': function() {
        const list = components.list();
        for (const component in list) {
          if (
            !has(list, component) ||
            hasOtherProperties(list[component].node) ||
            list[component].useThis ||
            list[component].useRef ||
            list[component].invalidReturn ||
            list[component].hasChildContextTypes ||
            list[component].useDecorators ||
            (!utils.isES5Component(list[component].node) && !utils.isES6Component(list[component].node))
          ) {
            continue;
          }

          if (list[component].hasSCU && list[component].usePropsOrContext) {
            continue;
          }
          context.report({
            node: list[component].node,
            message: 'Component should be written as a pure function'
          });
        }
      }
function findExternal(source, externals, context) {
  if (!externals) return false

  // string match
  if (typeof externals === 'string') return (source === externals)

  // array: recurse
  if (externals instanceof Array) {
    return externals.some(function (e) { return findExternal(source, e, context) })
  }

  if (externals instanceof RegExp) {
    return externals.test(source)
  }

  if (typeof externals === 'function') {
    var functionExternalFound = false
    externals.call(null, context, source, function(err, value) {
      if (err) {
        functionExternalFound = false
      } else {
        functionExternalFound = findExternal(source, value, context)
      }
    })
    return functionExternalFound
  }

  // else, vanilla object
  for (var key in externals) {
    if (!has(externals, key)) continue
    if (source === key) return true
  }
  return false
}
    function getMapIndexParamName(node) {
      var callee = node.callee;
      if (callee.type !== 'MemberExpression') {
        return null;
      }
      if (callee.property.type !== 'Identifier') {
        return null;
      }
      if (!has(iteratorFunctionsToIndexParamPosition, callee.property.name)) {
        return null;
      }

      var firstArg = node.arguments[0];
      if (!firstArg) {
        return null;
      }

      var isFunction = [
        'ArrowFunctionExpression',
        'FunctionExpression'
      ].indexOf(firstArg.type) !== -1;
      if (!isFunction) {
        return null;
      }

      var params = firstArg.params;

      var indexParamPosition = iteratorFunctionsToIndexParamPosition[callee.property.name];
      if (params.length < indexParamPosition + 1) {
        return null;
      }

      return params[indexParamPosition].name;
    }
    /**
     * Report errors
     */
    function reportErrors() {
      dedupeErrors();

      let nodeA;
      let nodeB;
      let indexA;
      let indexB;
      for (const i in errors) {
        if (!has(errors, i)) {
          continue;
        }

        nodeA = errors[i].node;
        nodeB = errors[i].closest.ref.node;
        indexA = i;
        indexB = errors[i].closest.ref.index;

        context.report({
          node: nodeA,
          message: MISPOSITION_MESSAGE,
          data: {
            propA: getPropertyName(nodeA),
            propB: getPropertyName(nodeB),
            position: indexA < indexB ? 'before' : 'after'
          }
        });
      }
    }
Example #19
0
Chat.prototype.join = function (channel) {
  var self = this
  if (channel === '#!status') channel = '!status'
  if (channel === '!status') {
    return self.emit('join', channel)
  }
  if (has(self.swarms, channel)) {
    return self.emit('join', channel)
  }
  self.logs[channel] = hyperlog(
    sub(self.db, channel), { valueEncoding: 'json' })

  self.logs[channel].createReadStream({ live: true })
    .on('data', function (row) {
      self.emit('say', channel, row)
    })

  self.emit('join', channel)
  var hub = signalhub(shasum('chatwizard.' + channel), self.hubs)
  var swarm = wswarm(hub)
  self.swarms[channel] = swarm
  self.peers[channel] = {}
  self.onswarm[channel] = function (peer, id) {
    self.emit('peer', channel, id)
    self.peers[channel][id] = peer
    peer.pipe(self.logs[channel].replicate({ live: true })).pipe(peer)
  }
  self.ondisconnect[channel] = function (peer, id) {
    self.emit('disconnect', channel, id)
    delete self.peers[channel][id]
  }
  swarm.on('peer', self.onswarm[channel])
  swarm.on('disconnect', self.ondisconnect[channel])
}
 function reportIfForbidden(element, node) {
   if (has(indexedForbidConfigs, element)) {
     context.report({
       node: node,
       message: errorMessageForElement(element)
     });
   }
 }
Example #21
0
 falafel(fsrc, function (node) {
     if (node.type !== 'Identifier') return;
     if (node.name !== c.names.literal) return;
     var up = upexpr(node);
     if (getscope(ctx.scope, node) !== key) return;
     if (!has(lpatch[key], ix ++)) return;
     Function(names, up.source()).apply(null, vars);
 });
Example #22
0
function encodeResult (res, count) {
    var output = '';
    output += (res.ok ? 'ok ' : 'not ok ') + count;
    output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
    
    if (res.skip) output += ' # SKIP';
    else if (res.todo) output += ' # TODO';
    
    output += '\n';
    if (res.ok) return output;
    
    var outer = '  ';
    var inner = outer + '  ';
    output += outer + '---\n';
    output += inner + 'operator: ' + res.operator + '\n';
    
    if (has(res, 'expected') || has(res, 'actual')) {
        var ex = inspect(res.expected, {depth: res.objectPrintDepth});
        var ac = inspect(res.actual, {depth: res.objectPrintDepth});
        
        if (Math.max(ex.length, ac.length) > 65 || invalidYaml(ex) || invalidYaml(ac)) {
            output += inner + 'expected: |-\n' + inner + '  ' + ex + '\n';
            output += inner + 'actual: |-\n' + inner + '  ' + ac + '\n';
        } else {
            output += inner + 'expected: ' + ex + '\n';
            output += inner + 'actual:   ' + ac + '\n';
        }
    }
    if (res.at) {
        output += inner + 'at: ' + res.at + '\n';
    }

    var actualStack = res.actual && (typeof res.actual === 'object' || typeof res.actual === 'function') ? res.actual.stack : undefined;
    var errorStack = res.error && res.error.stack;
    var stack = defined(actualStack, errorStack);
    if (stack) {
        var lines = String(stack).split('\n');
        output += inner + 'stack: |-\n';
        for (var i = 0; i < lines.length; i++) {
            output += inner + '  ' + lines[i] + '\n';
        }
    }
    
    output += outer + '...\n';
    return output;
}
Example #23
0
function hasKeys(obj) {
  for (var key in obj) {
    if (has(obj, key)) {
      return true;
    }
  }
  return false;
}
Example #24
0
  session.on('request', function(method, args, resp) {
    if (!has(handlers, method)) {
      resp.send('cannot handle the "' + method + '" method', true);
      return;
    }

    resp.send(handlers[method].apply(null, args));
  });
Example #25
0
 initialize: function(){
   if (has('svg-smil')) {
     var img = new Image();
     img.src = 'http://weihub.com/images/run.svg';
     img.setAttribute('width', '100%');
     document.getElementById('running-car').appendChild(img);
   }
 }
 'Program:exit': function() {
   const list = components.list();
   for (const component in list) {
     if (!has(list, component) || isValid(list[component])) {
       continue;
     }
     reportSetStateUsages(list[component]);
   }
 }
Example #27
0
Chat.prototype.say = function (channel, msg) {
  if (!has(this.logs, channel)) return
  var data = {
    time: Date.now(),
    who: this.nym,
    message: msg
  }
  this.logs[channel].append(data, function (err, node) {})
}
Example #28
0
	HasOwnProperty: function HasOwnProperty(O, P) {
		if (this.Type(O) !== 'Object') {
			throw new TypeError('O must be an Object');
		}
		if (!this.IsPropertyKey(P)) {
			throw new TypeError('P must be a Property Key');
		}
		return has(O, P);
	},
Example #29
0
  return (name) => {
    if (has(resolvedFiles, name)) {
      const { filePath, code } = resolvedFiles[name];
      return vm.run(filePath, code);
    }

    // The requested package was not found.
    return null;
  };
Example #30
0
function filterRules(rules, predicate) {
  const result = {};
  for (const key in rules) {
    if (has(rules, key) && predicate(rules[key])) {
      result[key] = rules[key];
    }
  }
  return result;
}