react / wstein / node_modules / jest-cli / node_modules / coffee-script / lib / coffee-script / scope.js
80677 views// Generated by CoffeeScript 1.9.31(function() {2var Scope,3indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };45exports.Scope = Scope = (function() {6function Scope(parent, expressions, method, referencedVars) {7var ref, ref1;8this.parent = parent;9this.expressions = expressions;10this.method = method;11this.referencedVars = referencedVars;12this.variables = [13{14name: 'arguments',15type: 'arguments'16}17];18this.positions = {};19if (!this.parent) {20this.utilities = {};21}22this.root = (ref = (ref1 = this.parent) != null ? ref1.root : void 0) != null ? ref : this;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 ref;41if (((ref = this.method) != null ? ref.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 ref;64return !!(this.type(name) || ((ref = this.parent) != null ? ref.check(name) : void 0));65};6667Scope.prototype.temporary = function(name, index, single) {68if (single == null) {69single = false;70}71if (single) {72return (index + parseInt(name, 36)).toString(36).replace(/\d/g, 'a');73} else {74return name + (index || '');75}76};7778Scope.prototype.type = function(name) {79var i, len, ref, v;80ref = this.variables;81for (i = 0, len = ref.length; i < len; i++) {82v = ref[i];83if (v.name === name) {84return v.type;85}86}87return null;88};8990Scope.prototype.freeVariable = function(name, options) {91var index, ref, temp;92if (options == null) {93options = {};94}95index = 0;96while (true) {97temp = this.temporary(name, index, options.single);98if (!(this.check(temp) || indexOf.call(this.root.referencedVars, temp) >= 0)) {99break;100}101index++;102}103if ((ref = options.reserve) != null ? ref : true) {104this.add(temp, 'var', true);105}106return temp;107};108109Scope.prototype.assign = function(name, value) {110this.add(name, {111value: value,112assigned: true113}, true);114return this.hasAssignments = true;115};116117Scope.prototype.hasDeclarations = function() {118return !!this.declaredVariables().length;119};120121Scope.prototype.declaredVariables = function() {122var v;123return ((function() {124var i, len, ref, results;125ref = this.variables;126results = [];127for (i = 0, len = ref.length; i < len; i++) {128v = ref[i];129if (v.type === 'var') {130results.push(v.name);131}132}133return results;134}).call(this)).sort();135};136137Scope.prototype.assignedVariables = function() {138var i, len, ref, results, v;139ref = this.variables;140results = [];141for (i = 0, len = ref.length; i < len; i++) {142v = ref[i];143if (v.type.assigned) {144results.push(v.name + " = " + v.type.value);145}146}147return results;148};149150return Scope;151152})();153154}).call(this);155156157