react / wstein / node_modules / jest-cli / node_modules / jasmine-only / node_modules / coffee-script / lib / coffee-script / scope.js
81146 views// Generated by CoffeeScript 1.6.31(function() {2var Scope, extend, last, _ref;34_ref = require('./helpers'), extend = _ref.extend, last = _ref.last;56exports.Scope = Scope = (function() {7Scope.root = null;89function Scope(parent, expressions, method) {10this.parent = parent;11this.expressions = expressions;12this.method = method;13this.variables = [14{15name: 'arguments',16type: 'arguments'17}18];19this.positions = {};20if (!this.parent) {21Scope.root = this;22}23}2425Scope.prototype.add = function(name, type, immediate) {26if (this.shared && !immediate) {27return this.parent.add(name, type, immediate);28}29if (Object.prototype.hasOwnProperty.call(this.positions, name)) {30return this.variables[this.positions[name]].type = type;31} else {32return this.positions[name] = this.variables.push({33name: name,34type: type35}) - 1;36}37};3839Scope.prototype.namedMethod = function() {40var _ref1;41if (((_ref1 = this.method) != null ? _ref1.name : void 0) || !this.parent) {42return this.method;43}44return this.parent.namedMethod();45};4647Scope.prototype.find = function(name) {48if (this.check(name)) {49return true;50}51this.add(name, 'var');52return false;53};5455Scope.prototype.parameter = function(name) {56if (this.shared && this.parent.check(name, true)) {57return;58}59return this.add(name, 'param');60};6162Scope.prototype.check = function(name) {63var _ref1;64return !!(this.type(name) || ((_ref1 = this.parent) != null ? _ref1.check(name) : void 0));65};6667Scope.prototype.temporary = function(name, index) {68if (name.length > 1) {69return '_' + name + (index > 1 ? index - 1 : '');70} else {71return '_' + (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');72}73};7475Scope.prototype.type = function(name) {76var v, _i, _len, _ref1;77_ref1 = this.variables;78for (_i = 0, _len = _ref1.length; _i < _len; _i++) {79v = _ref1[_i];80if (v.name === name) {81return v.type;82}83}84return null;85};8687Scope.prototype.freeVariable = function(name, reserve) {88var index, temp;89if (reserve == null) {90reserve = true;91}92index = 0;93while (this.check((temp = this.temporary(name, index)))) {94index++;95}96if (reserve) {97this.add(temp, 'var', true);98}99return temp;100};101102Scope.prototype.assign = function(name, value) {103this.add(name, {104value: value,105assigned: true106}, true);107return this.hasAssignments = true;108};109110Scope.prototype.hasDeclarations = function() {111return !!this.declaredVariables().length;112};113114Scope.prototype.declaredVariables = function() {115var realVars, tempVars, v, _i, _len, _ref1;116realVars = [];117tempVars = [];118_ref1 = this.variables;119for (_i = 0, _len = _ref1.length; _i < _len; _i++) {120v = _ref1[_i];121if (v.type === 'var') {122(v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name);123}124}125return realVars.sort().concat(tempVars.sort());126};127128Scope.prototype.assignedVariables = function() {129var v, _i, _len, _ref1, _results;130_ref1 = this.variables;131_results = [];132for (_i = 0, _len = _ref1.length; _i < _len; _i++) {133v = _ref1[_i];134if (v.type.assigned) {135_results.push("" + v.name + " = " + v.type.value);136}137}138return _results;139};140141return Scope;142143})();144145}).call(this);146147148