From bfa45a2b49e4f3cb8112a5c2d432849e2130cfd6 Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Wed, 19 Nov 2014 14:30:26 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=9F=AD=E8=B7=AF=E4=B8=8E=20=E7=9F=AD?= =?UTF-8?q?=E8=B7=AF=E6=88=96=E5=BC=95=E5=8F=91=E4=BE=9D=E8=B5=96=E6=94=B6?= =?UTF-8?q?=E9=9B=86=E5=A4=B1=E8=B4=A5=E7=9A=84BUG=20https://github.com/Ru?= =?UTF-8?q?byLouvre/avalon/issues/583?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avalon.js | 26 ++++++++++++++++++++++---- avalon.modern.js | 18 +++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/avalon.js b/avalon.js index 5480c8ba5..17c6beefe 100644 --- a/avalon.js +++ b/avalon.js @@ -2404,6 +2404,7 @@ for (var i = vars.length, prop; prop = vars[--i]; ) { if (scope.hasOwnProperty(prop)) { ret.push(prop + prefix + prop) + data.vars.push(prop) if (data.type === "duplex") { vars.get = name + "." + prop } @@ -2411,7 +2412,6 @@ } } return ret - } function uniqSet(array) { @@ -2449,7 +2449,7 @@ var dataType = data.type var filters = data.filters ? data.filters.join("") : "" var exprId = scopes.map(function(el) { - return el.$id.replace(rproxy, "$1") + return String(el.$id).replace(rproxy, "$1") }) + code + dataType + filters var vars = getVariables(code).concat(), assigns = [], @@ -2458,6 +2458,7 @@ prefix = "" //args 是一个对象数组, names 是将要生成的求值函数的参数 scopes = uniqSet(scopes) + data.vars = [] for (var i = 0, sn = scopes.length; i < sn; i++) { if (vars.length) { var name = "vm" + expose + "_" + i @@ -2469,6 +2470,20 @@ if (!assigns.length && dataType === "duplex") { return } + //https://github.com/RubyLouvre/avalon/issues/583 + data.vars.forEach(function(v) { + var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") + code = code.replace(reg, function(_) { + var c = _.charAt(v.length) + if (c === "." || c === "[") { + var name = "var" + String(Math.random()).replace(/^0\./, "") + assigns.push(name + " = " + _) + return name + } else { + return _ + } + }) + }) //---------------args---------------- if (filters) { args.push(avalon.filters) @@ -2571,9 +2586,12 @@ parseExpr(code, scopes, data) if (data.evaluator && !noregister) { data.handler = bindingExecutors[data.handlerName || data.type] - data.evaluator.toString = function() { - return data.type + " binding to eval(" + code + ")" + if (data.type === "if") { + console.log(data.evaluator + "") } +// data.evaluator.toString = function() { +// return data.type + " binding to eval(" + code + ")" +// } //方便调试 //这里非常重要,我们通过判定视图刷新函数的element是否在DOM树决定 //将它移出订阅者列表 diff --git a/avalon.modern.js b/avalon.modern.js index 102a66ecd..35bb26970 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -1798,6 +1798,7 @@ for (var i = vars.length, prop; prop = vars[--i]; ) { if (scope.hasOwnProperty(prop)) { ret.push(prop + prefix + prop) + data.vars.push(prop) if (data.type === "duplex") { vars.get = name + "." + prop } @@ -1848,6 +1849,7 @@ names = [], args = [], prefix = "" + data.vars = [] //args 是一个对象数组, names 是将要生成的求值函数的参数 scopes = uniqSet(scopes) for (var i = 0, sn = scopes.length; i < sn; i++) { @@ -1861,6 +1863,20 @@ if (!assigns.length && dataType === "duplex") { return } + //https://github.com/RubyLouvre/avalon/issues/583 + data.vars.forEach(function(v) { + var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") + code = code.replace(reg, function(_) { + var c = _.charAt(v.length) + if (c === "." || c === "[") { + var name = "var" + String(Math.random()).replace(/^0\./, "") + assigns.push(name + " = " + _) + return name + } else { + return _ + } + }) + }) //---------------args---------------- if (filters) { args.push(avalon.filters) @@ -1931,7 +1947,7 @@ } catch (e) { log("debug: parse error," + e.message) } finally { - vars = textBuffer = names = null //释放内存 + vars = textBuffer = names = null //释放内存 } }