remove static whitespace properties in favor of pushing to the dynamic ones

This commit is contained in:
Sebastian McKenzie
2014-11-12 00:15:31 +11:00
parent 3d5d170eff
commit 1ac40ee834
2 changed files with 21 additions and 23 deletions

View File

@@ -54,10 +54,7 @@ Node.prototype.needsWhitespace = function (type) {
lines = Node.needsWhitespace(expr, node, type);
if (lines) return false;
});
if (lines) return lines;
var opts = whitespace.static[node.type];
return (opts && opts[type]) || 0;
return lines || 0;
};
Node.prototype.needsWhitespaceBefore = function () {

View File

@@ -1,25 +1,6 @@
var _ = require("lodash");
var t = require("../../types");
exports.static = {
FunctionExpression: 1,
FunctionStatement: 1,
ClassExpression: 1,
ClassStatement: 1,
ForOfStatement: 1,
ForInStatement: 1,
ForStatement: 1,
SwitchStatement: 1,
IfStatement: { before: 1 },
CallExpression: { after: 1 },
Literal: { after: 1 }
};
_.each(exports.static, function (amounts, type) {
if (_.isNumber(amounts)) amounts = { after: amounts, before: amounts };
exports.static[type] = amounts;
});
exports.before = {
nodes: {
Property: function (node, parent) {
@@ -43,6 +24,8 @@ exports.before = {
};
exports.after = {
nodes: {},
list: {
VariableDeclaration: function (node) {
return _.map(node.declarations, "init");;
@@ -57,3 +40,21 @@ exports.after = {
}
}
};
_.each({
Function: 1,
Class: 1,
For: 1,
SwitchStatement: 1,
IfStatement: { before: 1 },
CallExpression: { after: 1 },
Literal: { after: 1 }
}, function (amounts, type) {
if (_.isNumber(amounts)) amounts = { after: amounts, before: amounts };
_.each(amounts, function (amount, key) {
exports[key].nodes[type] = function () {
return amount;
};
});
});