Skip to content

Commit 56610b8

Browse files
author
RubyLouvre
committed
优化parseExpr
1 parent 27166cf commit 56610b8

File tree

9 files changed

+379
-873
lines changed

9 files changed

+379
-873
lines changed

dist/avalon.js

Lines changed: 71 additions & 189 deletions
Large diffs are not rendered by default.

dist/avalon.modern.js

Lines changed: 95 additions & 213 deletions
Large diffs are not rendered by default.

dist/avalon.next.js

Lines changed: 95 additions & 213 deletions
Large diffs are not rendered by default.

dist/avalon.test.js

Lines changed: 103 additions & 221 deletions
Large diffs are not rendered by default.

karma.conf.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ module.exports = function (config) {
1616
'karma/seed/config.js',
1717
'karma/filters/index.js',
1818
'karma/vdom/index.js',
19-
19+
'karma/dom/index.js',
2020
'karma/$watch.js',
21-
'karma/other.js',
2221
'karma/directives/text.js',
2322
'karma/directives/controller.js',
2423
'karma/directives/expr.js',

karma/dom/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ describe('测试dom模块', function () {
5858
expect(avalon.parseHTML('<div></div>').nodeType).to.equal(11)
5959
expect(avalon.parseHTML('<div></div>').nodeType).to.equal(11)
6060

61+
var table = document.createElement('table')
62+
avalon.innerHTML(table, '<tr><td>111</td></tr>')
63+
expect(table.getElementsByTagName('td').length).to.equal(1)
64+
avalon.clearHTML(table)
65+
expect(table.childNodes.length).to.equal(0)
66+
6167
expect(avalon.parseHTML).to.be.a('function')
6268
expect(avalon.innerHTML).to.be.a('function')
6369
expect(avalon.clearHTML).to.be.a('function')
@@ -82,8 +88,8 @@ describe('测试dom模块', function () {
8288
it('it is the reverse of escape-html', function () {
8389
var str1 = '<strong> & <a> are examples of "HTML Tags"'
8490
var str2 = '&amp; & &gt; are examples of \'HTML entities\''
85-
expect(fn(avalon.filters.escape(str1)+"!!")).to.be.equal(str1+"!!")
86-
91+
expect(fn(avalon.filters.escape(str1) + "!!")).to.be.equal(str1 + "!!")
92+
8793
expect(fn(avalon.filters.escape(str2))).to.be.equal(str2)
8894
})
8995
})

karma/other.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/directives/html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var update = require('./_update')
2-
var reconcile = require('../strategy/reconcile')
2+
//var reconcile = require('../strategy/reconcile')
33

44
avalon.directive('html', {
55
parse: function (copy, src, binding) {

src/strategy/parser/parseExpr.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ function parseExpr(str, category) {
4747
binding = str
4848
str = binding.expr
4949
}
50-
if (typeof str !== 'string')
51-
return ''
50+
5251
var cacheID = str
5352
var cacheStr = evaluatorPool.get(category + ':' + cacheID)
5453

@@ -84,12 +83,12 @@ function parseExpr(str, category) {
8483
}
8584

8685
body = body.replace(rAt, '$1__vmodel__.')
87-
if (category === 'js') {
88-
return evaluatorPool.put(category + ':' + cacheID, body)
89-
} else if (category === 'on') {
86+
87+
if (category === 'on') {
9088
collectLocal(_body, local)
89+
} else if (category === 'js') {
90+
return evaluatorPool.put(category + ':' + cacheID, body)
9191
}
92-
9392
//处理表达式的过滤器部分
9493

9594
var filters = input.map(function (str) {

0 commit comments

Comments
 (0)