Blame view

node_modules/stylus/lib/stack/scope.js 861 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  
  /*!
   * Stylus - stack - Scope
   * Copyright (c) Automattic <developer.wordpress.com>
   * MIT Licensed
   */
  
  /**
   * Initialize a new `Scope`.
   *
   * @api private
   */
  
  var Scope = module.exports = function Scope() {
    this.locals = {};
  };
  
  /**
   * Add `ident` node to the current scope.
   *
   * @param {Ident} ident
   * @api private
   */
  
  Scope.prototype.add = function(ident){
    this.locals[ident.name] = ident.val;
  };
  
  /**
   * Lookup the given local variable `name`.
   *
   * @param {String} name
   * @return {Node}
   * @api private
   */
  
  Scope.prototype.lookup = function(name){
    return this.locals[name];
  };
  
  /**
   * Custom inspect.
   *
   * @return {String}
   * @api public
   */
  
  Scope.prototype.inspect = function(){
    var keys = Object.keys(this.locals).map(function(key){ return '@' + key; });
    return '[Scope'
      + (keys.length ? ' ' + keys.join(', ') : '')
      + ']';
  };