Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions lib/ConcatSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,63 @@ ConcatSource.prototype.add = function(item) {
};

ConcatSource.prototype.source = function() {
return this.children.map(function(item) {
return typeof item === "string" ? item : item.source();
}).join("");
var source = '';

var children = this.children;
for(var i = 0, l = children.length; i < l; ++i) {
var item = children[i];
source += typeof item === "string" ? item : item.source();
}

return source;
};

ConcatSource.prototype.size = function() {
return this.children.map(function(item) {
return typeof item === "string" ? item.length : item.size();
}).reduce(function(sum, s) {
return sum + s;
}, 0);
var size = 0;

var children = this.children;
for(var i = 0, l = children.length; i < l; ++i) {
var item = children[i];
size += typeof item === "string" ? item.length : item.size();
}

return size;
};

require("./SourceAndMapMixin")(ConcatSource.prototype);

ConcatSource.prototype.node = function(options) {
var node = new SourceNode(null, null, null, this.children.map(function(item) {
return typeof item === "string" ? item : item.node(options);
}));
return node;
var chunks = [];

var children = this.children;
for(var i = 0, l = children.length; i < l; ++i) {
var item = children[i];
chunks.push(typeof item === "string" ? item : item.node(options));
}

return new SourceNode(null, null, null, chunks);
};

ConcatSource.prototype.listMap = function(options) {
var map = new SourceListMap();
this.children.forEach(function(item) {
if(typeof item === "string")
map.add(item);
else
map.add(item.listMap(options));
});

var children = this.children;
for(var i = 0, l = children.length; i < l; ++i) {
var item = children[i];
map.add(typeof item === "string" ? item : item.listMap(options));
}

return map;
};

ConcatSource.prototype.updateHash = function(hash) {
this.children.forEach(function(item) {
if(typeof item === "string")
var children = this.children;
for(var i = 0, l = children.length; i < l; ++i) {
var item = children[i];
if(typeof item === "string") {
hash.update(item);
else
} else {
item.updateHash(hash);
});
}
}
};