设置变量
自内向外在作用域栈中查找变量，如果找到则改写变量值，否则将变量存放到顶层 Scope
540938
public void set(Object key, Object value) {
		for (Scope cur=this; true; cur=cur.parent) {
			// HashMap 允许有 null 值 value，必须要做 containsKey 判断
			if (cur.data != null && cur.data.containsKey(key)) {
				cur.data.put(key, value);
				return ;
			}
			
			if (cur.parent == null) {
				if (cur.data == null) {			// 支持顶层 data 为 null 值
					cur.data = new HashMap();
				}
				cur.data.put(key, value);
				return ;
			}
		}
	}
1352284
function (val) {
            if (val === undefined || val === null) {
                return '';
            }
            //接收到的是raw包装的字符串，则不转义。If get an object with 'raw' property, no encode.
            if (val.$saker_raw$) {
                return val.str;
            }
            if (typeof val !== 'string') {
                return val;
            }
            var map = {
                '&': '&amp;',
                '<': '&lt;',
                '>': '&gt;',
                '"': '&quot;',
                "'": '&#039;'
            };

            return val.replace(/[&<>"']/g, function (m) {
                return map[m];
            });
        }
62713
public void setScope(String key) {
        Integer value = key != null ? SCOPES.get(key.toLowerCase()) : null;
        varScope = value != null ? value : null;
    }
722104
function (scope, option) {
                var params = option.params;
                var start = params[0];
                var end = params[1];
                var step = params[2];
                if (!step) {
                    step = start > end ? -1 : 1;
                } else if (start > end && step > 0 || start < end && step < 0) {
                    step = -step;
                }
                var ret = [];
                for (var i = start; start < end ? i < end : i > end; i += step) {
                    ret.push(i);
                }
                return ret;
            }
237902
function(tmplText, data, settings) {
			// node.js buffer toString
			tmplText+="";
			
			if(settings){
				// 临时定义
				settings = defaults({}, settings, Et.tmplSettings);
				settings={
						script: new RegExp(settings.scriptBegin.replace(dotRegExp,"\\$1")+"([\\s\\S]+?)"+settings.scriptEnd.replace(dotRegExp,"\\$1"),"g"),
						out: new RegExp(settings.outBegin.replace(dotRegExp,"\\$1")+"([\\s\\S]+?)"+settings.outEnd.replace(dotRegExp,"\\$1"),"g"),
						escapeOut: new RegExp(settings.escapeOutBegin.replace(dotRegExp,"\\$1")+"([\\s\\S]+?)"+settings.escapeOutEnd.replace(dotRegExp,"\\$1"),"g"),
				};
			}else{
				// 模板标签
				if(
					Et.tmplSettings.scriptBegin!="%{" ||
					Et.tmplSettings.scriptEnd!="}%" ||
					Et.tmplSettings.outBegin!="{=" ||
					Et.tmplSettings.outEnd!="}" ||
					Et.tmplSettings.escapeOutBegin!="{-" ||
					Et.tmplSettings.escapeOutEnd!="}" 
				){
					cacheTmplSettings={
						script: new RegExp(Et.tmplSettings.scriptBegin.replace(dotRegExp,"\\$1")+"([\\s\\S]+?)"+Et.tmplSettings.scriptEnd.replace(dotRegExp,"\\$1"),"g"),
						out: new RegExp(Et.tmplSettings.outBegin.replace(dotRegExp,"\\$1")+"([\\s\\S]+?)"+Et.tmplSettings.outEnd.replace(dotRegExp,"\\$1"),"g"),
						escapeOut: new RegExp(Et.tmplSettings.escapeOutBegin.replace(dotRegExp,"\\$1")+"([\\s\\S]+?)"+Et.tmplSettings.escapeOutEnd.replace(dotRegExp,"\\$1"),"g"),
					};
				}
				settings=cacheTmplSettings;
			}
			
			tmplText = Et.unescape(tmplText);
			var render;
			var matcher = new RegExp([(settings.escapeOut || noMatch).source, (settings.out || noMatch).source, (settings.script || noMatch).source].join("|") + "|$", "g");
			var index = 0;
			var source = "_p+='";
			tmplText.replace(matcher, function(match, escapeOut, out, script, offset) {
				source += tmplText.slice(index, offset).replace(escaper, function(match) {
					return "\\" + escapes[match];
				});
				if(escapeOut) {
					source += "'+\n((_t=(" + escapeOut + "))==null?'':Et.escape(_t))+'";
				}
				if(out) {
					//source += "'+((_t=(" + out+ "))==null?'':_t)+'";
//					source += "'+" + out + "+'";
					source += "'+\n((_t=(" + out+ "))==null?'':_t)+'";
				}
				if(script) {
					source += "';" + script + "\n_p+='";
				}
				index = offset + match.length;
				return match;
			});
			source += "';";
			var vars=getVars(source); 
			// Script support 
			if(this.enableScript){
//				source=source.replace(scriptReg, function($0, $1){
//					return '<script>'+$1.trim()+'<\/script>'
//				})
				source=source.replace("<etj-script>",'<script>').replace("</etj-script>",'<\/script>');
			}
			// Style support, don't warp
			if(this.enableStyle){
//				source=source.replace(styleReg, function($0, $1){
//					return '<style>'+$1.trim()+'</style>';
//				})
				source=source.replace("<etj-style>",'<style>').replace("</etj-style>",'<\/style>');
			}
//			console.info(source);
			source = "'use strict';"+vars+"_t,_p='',out=function(){_p+=Array.prototype.join.call(arguments, '')};" + source + "return _p";
			try {
				render = new Function("data", "Et",  source);
			} catch (e) {
				e.source = "function anonymous(data,Et) {" + source + "}";;
				throw e;
			}
			if(data) {
				try{
					return render(data, Et);
				}catch(e){
					console.error(e);
				}
				
			}
			var template = function(data) {
				try{
					return render(data, Et);
				}catch(e){
					console.error(e);
				}
			};
			return template;
		}
144141
static AuthRequest fromString(String str) {
        String[] parts = str.split("-----");
        String clientId = parts[0];
        String[] scopes = parts.length == 2 ? parts[1].split(",") : new String[0];
        AuthRequest req = new AuthRequest("", clientId).withScopes(scopes);
        return req;
    }
324373
function () {
            var len = this.source.length,
                char,
                result = '';
            if (this.position >= len) {
                return undefined;
            }
            for (; this.position < len; this.position++) {
                char = this.readNextChars(1);

                if (char === '(' && this.quotes.length === 0) {
                    this.brackets.push(this.position);
                } else if (char === ')' && this.quotes.length === 0) {
                    this.brackets.pop();
                }

                //除这些外，且不在引号内部的特殊字符，都break。Special characters, except the following, and is not in quotes, all break.
                if (['.', ',', '(', ')', '[', ']', '"', "'", ' '].indexOf(char) === -1 && /\W/.test(char) && this.quotes.length === 0) {
                    break;
                }

                //class="@name"   class="@arr.join('')"
                if ((char === '"' || char === "'") && (this.brackets.length === 0 || this.brackets[this.brackets.length - 1] < (this.braces[this.braces.length - 1] || {position: -1}).position)) {
                    break;
                }

                //class="@name abc"   class="@arr.join(' ') abc"
                if (char === ' ' && (this.brackets.length === 0 || this.brackets[this.brackets.length - 1] < (this.braces[this.braces.length - 1] || {position: -1}).position)) {
                    break;
                }

                //class="@name.toString()abc"   class="@arr.join().toString()abc"
                if (char === ')' && [').', ')[', ')]', ')('].indexOf(this.readNextChars(2)) === -1) {
                    result += char;
                    this.position++;
                    break;
                }

                if (char === ']' && ['].', '][', ']]', ']('].indexOf(this.readNextChars(2)) === -1) {
                    result += char;
                    this.position++;
                    break;
                }

                //引号的处理。Handle quotes.
                if ((char === '"' || char === "'") && this.readPrevChars(1) !== '\\') {
                    if (this.quotes.length === 0) {
                        this.quotes.push({
                            type: char === '"' ? quotesEnum.doubleQuotes : quotesEnum.singleQuotes,
                            position: this.position
                        });
                    } else if (this.quotes.length > 0) {
                        if (char === '"' && this.quotes[0].type === quotesEnum.doubleQuotes) {
                            this.quotes.pop();
                        } else if (char === "'" && this.quotes[0].type === quotesEnum.singleQuotes) {
                            this.quotes.pop();
                        }
                    }
                }

                result += char;
            }
            //准备进入前端读取模式。Ready to switch to frontend read mode.
            this.state = stateEnum.client;
            return result;
        }
604068
function (name, value) {
            var self = this, setValue,
                // if host does not have meta info corresponding to (name,value)
                // then register on demand in order to collect all data meta info
                // 一定要注册属性元数据，否则其他模块通过 _attrs 不能枚举到所有有效属性
                // 因为属性在声明注册前可以直接设置值
                attrConfig = ensureNonEmpty(self.getAttrs(), name), setter = attrConfig.setter;    // if setter has effect
            // if setter has effect
            if (setter && (setter = normalFn(self, setter))) {
                setValue = setter.call(self, value, name);
            }
            if (setValue === INVALID) {
                return FALSE;
            }
            if (setValue !== undefined) {
                value = setValue;
            }    // finally set
            // finally set
            getAttrVals(self)[name] = value;
            return undefined;
        }
231336
function(param) {

			/**
			 * Reference the instance
			 */
			var rInstance = this;

			if (typeof param !== "undefined") {
				rInstance.text = param.text;
				rInstance.scopes = [].concat(param.scope);
			}


			/**
			 * The required regexp computed using delims in settings
			 * @type {RegExp}
			 */
			var re = new RegExp(['{%(.+?)%}|', this.delimStart, '(.+?)', this.delimEnd].join(''), 'g');

			/**
			 * Save the raw text
			 * @type {String}
			 */
			rInstance.raw = rInstance.text;

			/**
			 * Compute and assign to compiledText property of the same object
			 * @param  {String} _  Matched string
			 * @param  {String} $1 Content of first match group
			 * @param  {String} $2 Content of second match group
			 * @return {String}    Interpolated string
			 */

			rInstance.text = rInstance.text.replace(re, function(_, $1, $2) {
				var computed;

				/**
				 * If escaped value is found, interpolation will not happen
				 */
				if ($1) {
					computed = $1;
				}

				/**
				 * Matched content, let's interpolate
				 */
				if ($2) {

					/**
					 * Break out scope variables out of scope's box and evaluate the expr expression
					 */
					var scopeBox = function(expr, localScope) {
						var variables = '';

						/**
						 * If scope is a window object, no need to scopebox it
						 */
						if (typeof window !== "undefined" ? localScope !== window : true) {
							for(var i in localScope) {
								variables += 'var ' + i + ' = localScope.' + i + '; ';
							}
						}
						var unbox = '(function() { ' + variables + ' try { return eval(expr);} catch(e) {} })()';
						return eval(unbox);
					};

					if (rInstance.scopes.length) {
						var numScopes = rInstance.scopes.length;
						for (var i=0;i<numScopes;i++) {
							/**
							 * Current Scope
							 * @type {String}
							 */
							var scope = rInstance.scopes[i];

							/**
							 * Get the computation
							 * @type {Any}
							 */
							computed = scopeBox($2, scope);

							/**
							 * If the computed property is a function, execute it in the context of the current scope
							 * @type {Unknown}
							 */
							if (typeof computed === "function") {
								computed = computed.call(scope);
							}

							/**
							 * If the computed property is an object, get the string
							 */
							if (typeof computed === "object") {
								computed = computed.toString();
							}
								
							/**
							 * Found what we were looking for, now break the loop
							 */
							if (computed !== undefined)
								break;
						}
					} else {
						/**
						 * If no scope is passed, let us assume the global scope
						 * @type {Any}
						 */
						computed = scopeBox($2, (typeof window !== "undefined" ? window : {}));
					}

					/**
					 * If no computations were found, we return the raw matched value back
					 * @type {String}
					 */
					computed = computed !== undefined ? computed : _;
				}

				/**
				 * Final computed value returned
				 */
				return computed;
			});
			
			/**
			 * Return self for chaining
			 */
			return rInstance;
		}
474156
public function scope($scope, ...$args)
    {
        // 查询范围的第一个参数始终是当前查询对象
        array_unshift($args, $this);

        if ($scope instanceof \Closure) {
            call_user_func_array($scope, $args);
            return $this;
        }

        if (is_string($scope)) {
            $scope = explode(',', $scope);
        }

        if ($this->model) {
            // 检查模型类的查询范围方法
            foreach ($scope as $name) {
                $method = 'scope' . trim($name);

                if (method_exists($this->model, $method)) {
                    call_user_func_array([$this->model, $method], $args);
                }
            }
        }

        return $this;
    }
1143553
def encode_scopes(scopes, use_quote=False):
    
    scopes_as_string = Scope.separator.join(scopes)

    if use_quote:
        return quote(scopes_as_string)
    return scopes_as_string
205757
function(input) {
      // 清理input数据、因为parsed数据最终会被缓存，
      // 我们要尽量让相同的选择器只对应一份parsed数据
      input = clean(input);
      // 先检查缓存中是否有数据
      if (parsed = this.cache.get(input)) return parsed;
      // 如果没有: 初始化参数
      var parsed = this.parsed = [
        [null]
      ];
      var remain = this.input = input;
      var TRUNK = this.TRUNK;
      var prevRemain;
        // 将remain进行this._process这里每匹配一个字符串都会进行一次reduce
      while (prevRemain != (remain = remain.replace(TRUNK, this._process.bind(this)))) {
        prevRemain = remain;
      }
      // 如果没有被解析完 证明选择器字符串有不能被解析的部分
      if (remain !== '') this.error(remain);
      // 返回数据并推入cache
      return this.cache.set(input, parsed);
    }
85455
function getScopeData(session, offset) {
        var path = session.path,
            fileInfo = {
                type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
                name: path,
                offsetLines: 0,
                text: ScopeManager.filterText(session.getJavascriptText())
            };

        ScopeManager.postMessage({
            type: MessageIds.TERN_SCOPEDATA_MSG,
            fileInfo: fileInfo,
            offset: offset
        });

        var ternPromise = ScopeManager.addPendingRequest(fileInfo.name, offset, MessageIds.TERN_SCOPEDATA_MSG);

        var result = new $.Deferred();

        ternPromise.done(function (response) {
            result.resolveWith(null, [response.scope]);
        }).fail(function () {
            result.reject();
        });

        return result;
    }
1116807
function _parseDuibaUrlQuery(urlQuery, appSecret){
    var urlObj = querystring.parse(_.trimEnd(urlQuery, '&'));
    var md5Sign = genSign(querystring.stringify(_.omit(urlObj,['sign'])), appSecret);

    // 将返回结果中的字符串 true/false，转换为 boolean 类型
    var TransDic = {
        'true': true,
        'false': false
    };
    for(var key in urlObj){
        var value = urlObj[key];
        urlObj[key] = typeof TransDic[value] === 'boolean' ? TransDic[value] : value;
    }

    if(md5Sign !== urlObj.sign){
        return {
            sign_pass: false,
            params: urlObj
        };
    }else{
        return {
            sign_pass: true,
            params: urlObj
        };
    }
}
422088
function(scope) {

		var index = this._debug_all_scopes.indexOf(scope);
		if (index == -1) Lava.t();
		this._debug_all_scopes.splice(index, 1);

	}
1147381
private void beforeValue() throws JSONException {
        if (stack.isEmpty()) {
            return;
        }

        Scope context = peek();
        if (context == Scope.EMPTY_ARRAY) { // first in array
            replaceTop(Scope.NONEMPTY_ARRAY);
            newline();
        } else if (context == Scope.NONEMPTY_ARRAY) { // another in array
            out.append(',');
            newline();
        } else if (context == Scope.DANGLING_KEY) { // value for key
            out.append(indent == null ? ":" : ": ");
            replaceTop(Scope.NONEMPTY_OBJECT);
        } else if (context != Scope.NULL) {
            throw new JSONException("Nesting problem");
        }
    }
13200
CharSequence scopeDeclaration()
	{
		if (scopeVariables.length == 0)
		{
			return "";
		}
		StringBuilder scopeDeclaration = new StringBuilder();
		scopeDeclaration.append(scopeVariables[0]);
		for (int i = 1; i < scopeVariables.length; i++)
		{
			scopeDeclaration.append(", ");
			scopeDeclaration.append(scopeVariables[i]);
		}
		return scopeDeclaration;
	}