Permalink
Browse files

Dont mess with whitespaces

  • Loading branch information...
1 parent 05dcb4a commit cc855c17ffa88c43d2f25049ff1fbcec4ec92021 Couto committed Dec 10, 2012
Showing with 11 additions and 11 deletions.
  1. +11 −11 index.js
View
@@ -28,23 +28,23 @@ module.exports = function (src, opts, fn) {
src = src || opts.source;
opts.range = true;
if (typeof src !== 'string') src = String(src);
-
+
var ast = opts.ast || parse(src, opts);
delete opts.ast;
-
+
var result = {
chunks : src.split(''),
toString : function () { return result.chunks.join('') },
inspect : function () { return result.toString() }
};
var index = 0;
-
+
(function walk (node, parent) {
insertHelpers(node, parent, result.chunks);
-
+
forEach(objectKeys(node), function (key) {
if (key === 'parent') return;
-
+
var child = node[key];
if (isArray(child)) {
forEach(child, function (c) {
@@ -60,21 +60,21 @@ module.exports = function (src, opts, fn) {
});
fn(node);
})(ast, undefined);
-
+
return result;
};
-
+
function insertHelpers (node, parent, chunks) {
if (!node.range) return;
-
+
node.parent = parent;
-
+
node.source = function () {
return chunks.slice(
node.range[0], node.range[1]
).join('');
};
-
+
if (node.update && typeof node.update === 'object') {
var prev = node.update;
forEach(objectKeys(prev), function (key) {
@@ -85,7 +85,7 @@ function insertHelpers (node, parent, chunks) {
else {
node.update = update;
}
-
+
function update (s) {
chunks[node.range[0]] = s;
for (var i = node.range[0] + 1; i < node.range[1]; i++) {

0 comments on commit cc855c1

Please sign in to comment.