"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/coffee-script/lib/coffee-script/scope.js" (7 Feb 2017, 4254 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Generated by CoffeeScript 1.9.0
    2 (function() {
    3   var Scope, extend, last, _ref,
    4     __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
    5 
    6   _ref = require('./helpers'), extend = _ref.extend, last = _ref.last;
    7 
    8   exports.Scope = Scope = (function() {
    9     function Scope(_at_parent, _at_expressions, _at_method, _at_referencedVars) {
   10       var _ref1, _ref2;
   11       this.parent = _at_parent;
   12       this.expressions = _at_expressions;
   13       this.method = _at_method;
   14       this.referencedVars = _at_referencedVars;
   15       this.variables = [
   16         {
   17           name: 'arguments',
   18           type: 'arguments'
   19         }
   20       ];
   21       this.positions = {};
   22       if (!this.parent) {
   23         this.utilities = {};
   24       }
   25       this.root = (_ref1 = (_ref2 = this.parent) != null ? _ref2.root : void 0) != null ? _ref1 : this;
   26     }
   27 
   28     Scope.prototype.add = function(name, type, immediate) {
   29       if (this.shared && !immediate) {
   30         return this.parent.add(name, type, immediate);
   31       }
   32       if (Object.prototype.hasOwnProperty.call(this.positions, name)) {
   33         return this.variables[this.positions[name]].type = type;
   34       } else {
   35         return this.positions[name] = this.variables.push({
   36           name: name,
   37           type: type
   38         }) - 1;
   39       }
   40     };
   41 
   42     Scope.prototype.namedMethod = function() {
   43       var _ref1;
   44       if (((_ref1 = this.method) != null ? _ref1.name : void 0) || !this.parent) {
   45         return this.method;
   46       }
   47       return this.parent.namedMethod();
   48     };
   49 
   50     Scope.prototype.find = function(name) {
   51       if (this.check(name)) {
   52         return true;
   53       }
   54       this.add(name, 'var');
   55       return false;
   56     };
   57 
   58     Scope.prototype.parameter = function(name) {
   59       if (this.shared && this.parent.check(name, true)) {
   60         return;
   61       }
   62       return this.add(name, 'param');
   63     };
   64 
   65     Scope.prototype.check = function(name) {
   66       var _ref1;
   67       return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0));
   68     };
   69 
   70     Scope.prototype.temporary = function(name, index) {
   71       if (name.length > 1) {
   72         return '_' + name + (index > 1 ? index - 1 : '');
   73       } else {
   74         return '_' + (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');
   75       }
   76     };
   77 
   78     Scope.prototype.type = function(name) {
   79       var v, _i, _len, _ref1;
   80       _ref1 = this.variables;
   81       for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
   82         v = _ref1[_i];
   83         if (v.name === name) {
   84           return v.type;
   85         }
   86       }
   87       return null;
   88     };
   89 
   90     Scope.prototype.freeVariable = function(name, reserve) {
   91       var index, temp;
   92       if (reserve == null) {
   93         reserve = true;
   94       }
   95       index = 0;
   96       while (true) {
   97         temp = this.temporary(name, index);
   98         if (!(this.check(temp) || __indexOf.call(this.root.referencedVars, temp) >= 0)) {
   99           break;
  100         }
  101         index++;
  102       }
  103       if (reserve) {
  104         this.add(temp, 'var', true);
  105       }
  106       return temp;
  107     };
  108 
  109     Scope.prototype.assign = function(name, value) {
  110       this.add(name, {
  111         value: value,
  112         assigned: true
  113       }, true);
  114       return this.hasAssignments = true;
  115     };
  116 
  117     Scope.prototype.hasDeclarations = function() {
  118       return !!this.declaredVariables().length;
  119     };
  120 
  121     Scope.prototype.declaredVariables = function() {
  122       var realVars, tempVars, v, _i, _len, _ref1;
  123       realVars = [];
  124       tempVars = [];
  125       _ref1 = this.variables;
  126       for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  127         v = _ref1[_i];
  128         if (v.type === 'var') {
  129           (v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name);
  130         }
  131       }
  132       return realVars.sort().concat(tempVars.sort());
  133     };
  134 
  135     Scope.prototype.assignedVariables = function() {
  136       var v, _i, _len, _ref1, _results;
  137       _ref1 = this.variables;
  138       _results = [];
  139       for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  140         v = _ref1[_i];
  141         if (v.type.assigned) {
  142           _results.push(v.name + " = " + v.type.value);
  143         }
  144       }
  145       return _results;
  146     };
  147 
  148     return Scope;
  149 
  150   })();
  151 
  152 }).call(this);