Permalink
Browse files

Refactored dot notation, and bug fix

  • Loading branch information...
1 parent 2dcd93d commit dad404c56cc19e6a4449bfe995ec4c4627b81edf @raycmorgan committed Jun 20, 2012
Showing with 21 additions and 12 deletions.
  1. +21 −12 lib/mu/renderer.js
View
@@ -111,27 +111,36 @@ function normalize(context, name, body) {
function walkToFind(context, name) {
var i = context.length;
- var names = name.split('.');
- var current;
- walk:
while (i--) {
- current = context[i];
+ var result = contextLevelContains(context[i], name);
- for (var j = 0; j < names.length; j++) {
- if (names[j] in current) {
- current = current[names[j]];
- } else {
- continue walk;
- }
+ if (result !== undefined) {
+ return result;
}
-
- return current;
}
return undefined;
}
+function contextLevelContains(context, fullPath) {
+ var pathParts = fullPath.split('.');
+ var obj = context;
+
+ for (var i = 0; i < pathParts.length; i++) {
+ var part = pathParts[i];
+
+ if (typeof obj == 'object' && part in obj) {
+ obj = obj[part];
+ } else {
+ obj = undefined;
+ break;
+ }
+ }
+
+ return obj;
+}
+
// TODO: if Proxy, make more efficient
// TODO: cache?
function smashContext(context) {

0 comments on commit dad404c

Please sign in to comment.