Skip to content

Commit 5b7b00f

Browse files
committed
incomplete new exp parser implementation
1 parent c8779f1 commit 5b7b00f

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

src/exp-parser.js

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,21 @@ function getVariables (code) {
4141
* We need full paths because we need to define them in the compiler's
4242
* bindings, so that they emit 'get' events during dependency tracking.
4343
*/
44-
function getPaths (code, vars) {
45-
var pathRE = new RegExp("\\b(" + vars.join('|') + ")[$\\w\\.]*\\b", 'g')
46-
return code.match(pathRE)
44+
// function getPaths (code, vars) {
45+
// var pathRE = new RegExp("\\b(" + vars.join('|') + ")[$\\w\\.]*\\b", 'g')
46+
// return code.match(pathRE)
47+
// }
48+
49+
function filterUnique (vars) {
50+
var hash = utils.hash(),
51+
i = vars.length,
52+
key
53+
while (i--) {
54+
key = vars[i]
55+
if (hash[key]) continue
56+
hash[key] = 1
57+
}
58+
return Object.keys(hash)
4759
}
4860

4961
/**
@@ -77,27 +89,33 @@ module.exports = {
7789
getter: makeGetter('return ' + exp, exp)
7890
}
7991
}
80-
var args = [],
81-
v, i, keyPrefix,
82-
l = vars.length,
83-
hash = Object.create(null)
84-
for (i = 0; i < l; i++) {
85-
v = vars[i]
86-
// avoid duplicate keys
87-
if (hash[v]) continue
88-
hash[v] = v
89-
// push assignment
90-
keyPrefix = v.charAt(0)
91-
args.push(v + (
92-
(keyPrefix === '$' || keyPrefix === '_')
93-
? '=this.' + v
94-
: '=this.$get("' + v + '")'
95-
))
96-
}
97-
args = 'var ' + args.join(',') + ';return ' + exp
92+
console.log(vars)
93+
vars = filterUnique(vars)
94+
// var args = [],
95+
// v, i, keyPrefix,
96+
// l = vars.length,
97+
// hash = Object.create(null)
98+
// for (i = 0; i < l; i++) {
99+
// v = vars[i]
100+
// // avoid duplicate keys
101+
// if (hash[v]) continue
102+
// hash[v] = v
103+
// // push assignment
104+
// keyPrefix = v.charAt(0)
105+
// args.push(v + (
106+
// (keyPrefix === '$' || keyPrefix === '_')
107+
// ? '=this.' + v
108+
// : '=this.$get("' + v + '")'
109+
// ))
110+
// }
111+
// args = 'var ' + args.join(',') + ';return ' + exp
112+
var pathRE = new RegExp("\\b(" + vars.join('|') + ")[$\\w\\.]*\\b", 'g'),
113+
paths = exp.match(pathRE),
114+
body = 'return ' + exp.replace(pathRE, 'this.$&')
115+
console.log(paths, body)
98116
return {
99-
getter: makeGetter(args, exp),
100-
paths: getPaths(exp, Object.keys(hash))
117+
getter: makeGetter(body, exp),
118+
paths: paths
101119
}
102120
}
103121
}

0 commit comments

Comments
 (0)