Blame view

node_modules/stylus/lib/functions/selector-exists.js 507 Bytes
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  var utils = require('../utils');
  
  /**
   * Returns true if the given selector exists.
   *
   * @param {String} sel
   * @return {Boolean}
   * @api public
   */
  
  module.exports = function selectorExists(sel) {
    utils.assertString(sel, 'selector');
  
    if (!this.__selectorsMap__) {
      var Normalizer = require('../visitor/normalizer')
        , visitor = new Normalizer(this.root.clone());
      visitor.visit(visitor.root);
  
      this.__selectorsMap__ = visitor.map;
    }
  
    return sel.string in this.__selectorsMap__;
  };