Skip to content

Commit

Permalink
fix for #2 where tags would get wrong cachekey inside if
Browse files Browse the repository at this point in the history
  • Loading branch information
somebee committed Aug 4, 2015
1 parent 56b1e80 commit 3f64d6c
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 58 deletions.
23 changes: 20 additions & 3 deletions lib/compiler/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,12 @@
this._nodes = this._nodes.map(function(child) {
return child.consume(node);
});
if (this._nodes.length > 1) { this._nodes = [new Arr(new ArgList(this._nodes))] };
// FIXME should not include terminators and comments when counting
if (this._nodes.length > 1) {
this._nodes = [new Arr(new ArgList(this._nodes))];
this._nodes[0].value()._indentation = this._indentation;
this._indentation = null;
};


return this;
Expand Down Expand Up @@ -3783,7 +3788,7 @@
// l.@parens = yes
var str = l.c();
// p "check for parens in !: {str}"
if (!(str.match(/^\!?([\w\.]+)$/) || (l instanceof Parens))) { str = '(' + str + ')' };
if (!(str.match(/^\!?([\w\.]+)$/) || (l instanceof Parens) || l.shouldParenthesize())) { str = '(' + str + ')' };
// l.set(parens: yes) # sure?
return "" + this.op() + str;
} else if (this.op() == '√') {
Expand Down Expand Up @@ -6824,8 +6829,10 @@
// if this is an ivar, we should set the reference relative
// to the outer reference, or possibly right on context?
var par = this.parent();
tree = par && par.tree();
var ctx = !o.ivar && par && par.reference() || scope.context();
var key = o.ivar || par && par.tree().indexOf(this);
var key = o.ivar || tree && tree.nextCacheKey();


// need the context -- might be better to rewrite it for real?
// parse the whole thing into calls etc
Expand Down Expand Up @@ -6858,11 +6865,21 @@
if(options === undefined) options = {};
this._nodes = this.load(list);
this._options = options;
this._counter = 0;
this;
};

subclass$(TagTree,ListNode);
exports.TagTree = TagTree; // export class

TagTree.prototype.__counter = {name: 'counter'};
TagTree.prototype.counter = function(v){ return this._counter; }
TagTree.prototype.setCounter = function(v){ this._counter = v; return this; };

TagTree.prototype.nextCacheKey = function (){
return this._counter++;
};

TagTree.prototype.load = function (list){
if (list instanceof ListNode) {
// p "is a list node!! {list.count}"
Expand Down
5 changes: 1 addition & 4 deletions lib/imba/core.events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function(){




function emit__(event,args,node){
Expand Down Expand Up @@ -81,5 +79,4 @@
return this;
};


}())
})()
15 changes: 6 additions & 9 deletions lib/imba/dom.events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function(){


function iter$(a){ return a ? (a.toArray ? a.toArray() : a) : []; };

// externs;
Expand Down Expand Up @@ -420,7 +418,7 @@
this._bubble = false;
this.setTarget(node);
this.target().ontouchstart(this);
if (!(this._bubble)) { break };
if (!this._bubble) { break };
};
dom = dom.parentNode;
};
Expand All @@ -438,7 +436,7 @@
};

Imba.Touch.prototype.update = function (){
if (!(this._active)) { return this };
if (!this._active) { return this };
// catching a touch-redirect?!?
if (this._redirect) {
if (this._target && this._target.ontouchcancel) {
Expand All @@ -462,7 +460,7 @@
};

Imba.Touch.prototype.move = function (){
if (!(this._active)) { return this };
if (!this._active) { return this };

if (this._gestures) {
for (var i=0, ary=iter$(this._gestures), len=ary.length, g; i < len; i++) {
Expand All @@ -475,7 +473,7 @@
};

Imba.Touch.prototype.ended = function (){
if (!(this._active)) { return this };
if (!this._active) { return this };

this._updates++;

Expand Down Expand Up @@ -687,7 +685,7 @@

Imba.Event.prototype.keycombo = function (){
var sym;
if (!(sym = this.keychar())) { return };
if (!((sym = this.keychar()))) { return };
sym = Imba.CHARMAP[sym] || sym;
var combo = [];
if (this.event().ctrlKey) { combo.push('ctrl') };
Expand Down Expand Up @@ -931,5 +929,4 @@
});
};


}())
})()
9 changes: 3 additions & 6 deletions lib/imba/dom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function(){


function idx$(a,b){
return (b && b.indexOf) ? b.indexOf(a) : [].indexOf.call(a,b);
};
Expand Down Expand Up @@ -249,7 +247,7 @@

ElementTag.prototype.siblings = function (sel){
var par, self=this;
if (!(par = this.parent())) { return [] }; // FIXME
if (!((par = this.parent()))) { return [] }; // FIXME
var ary = this.dom().parentNode.children;
var nodes = new ImbaSelector(null,this,ary);
return nodes.filter(function(n) {
Expand Down Expand Up @@ -682,7 +680,7 @@
if (!dom) { return null };
if (dom._dom) { return dom }; // could use inheritance instead
if (dom._tag) { return dom._tag };
if (!(dom.nodeName)) { return null }; // better check?
if (!dom.nodeName) { return null }; // better check?

var ns = null;
var id = dom.id;
Expand Down Expand Up @@ -1044,5 +1042,4 @@
Imba.defineTag('video');
Imba.defineTag('wbr');


}())
})()
49 changes: 39 additions & 10 deletions lib/imba/dom.server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function(){


var global_;
// could create a fake document
function ImbaServerDocument(){ };
Expand Down Expand Up @@ -67,7 +65,8 @@
// should somehow be linked to their owner, no?
this.nodeName = type;
this.classList = new ImbaNodeClassList(this);
this.children = null;
this.children = [];

this;
};

Expand All @@ -83,11 +82,16 @@

ImbaServerElement.prototype.appendChild = function (child){
// again, could be optimized much more
this.children || (this.children = []);
this.children.push(child);
return child;
};

ImbaServerElement.prototype.insertBefore = function (node,before){
var idx = this.children.indexOf(before);
this.arr().splice(idx,0,node);
return this;
};

// should implement at some point
// should also use shortcut to wipe
// def firstChild
Expand All @@ -114,16 +118,16 @@
};

ImbaServerElement.prototype.__innerHTML = function (){
var ary, item;
var item;
return this.innerHTML || this.textContent || (this.children && this.children.join("")) || '';
var str = this.innerHTML || this.textContent || '';
if (str) { return str };

if (ary = this.children) {
if (this.children.length) {
var i = 0;
var l = ary.length;
var l = this.children.length;
while (i < l){
if (item = ary[i++]) {
if (item = this.children[i++]) {
str += item.toString();
};
};
Expand Down Expand Up @@ -180,6 +184,18 @@
enumerable: true,
configurable: true});

Object.defineProperty(el,'firstElementChild',{get: function(v) {
return this.children && this.children[0];
},
enumerable: true,
configurable: true});

Object.defineProperty(el,'lastElementChild',{get: function(v) {
return this.children && this.children[this.children.length - 1];
},
enumerable: true,
configurable: true});



IMBA_TAGS.htmlelement.prototype.toString = function (){
Expand All @@ -193,6 +209,20 @@
this._empty = true;
return this;
};

IMBA_TAGS.htmlelement.prototype.first = function (){
return this._dom.children[0];
};

IMBA_TAGS.htmlelement.prototype.last = function (){
return this._dom.children[this._dom.children.length - 1];
};

IMBA_TAGS.htmlelement.prototype.prepend = function (item){
console.log("PREPEND FROM SERVER");
return this._dom.children.unshift(item);
// insert(item, before: first)
};



Expand All @@ -218,5 +248,4 @@
Imba.doc = global.document || new ImbaServerDocument();
global.document || (global.document = Imba.doc);


}())
})()
5 changes: 1 addition & 4 deletions lib/imba/dom.virtual.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function(){



// maybe do a quick check first to see if there are any nested arrays?
function flatten(input,out){
Expand Down Expand Up @@ -122,5 +120,4 @@
};



}())
})()
5 changes: 1 addition & 4 deletions lib/imba/imba.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
(function(){


Imba = {};


}())
})()
5 changes: 1 addition & 4 deletions lib/imba/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function(){


// externs;

require('./imba');
Expand All @@ -16,5 +14,4 @@

require('./selector');


}())
})()
7 changes: 2 additions & 5 deletions lib/imba/selector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(function(){


function iter$(a){ return a ? (a.toArray ? a.toArray() : a) : []; };

function ImbaSelector(sel,scope,nodes){
Expand Down Expand Up @@ -33,7 +31,7 @@
ImbaSelector.prototype.scope = function (){
var ctx;
if (this._scope) { return this._scope };
if (!(ctx = this._context)) { return global.document };
if (!((ctx = this._context))) { return global.document };
return this._scope = ctx.toScope ? (ctx.toScope()) : (ctx);
};

Expand Down Expand Up @@ -216,5 +214,4 @@
};



}())
})()

0 comments on commit 3f64d6c

Please sign in to comment.