Skip to content

Commit c9cd516

Browse files
committed
Split the binary expressions if they use more than 80 chars
1 parent 3c3ba1e commit c9cd516

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

node_translators/bin.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
'use strict';
33

44
module.exports = function (node, indent) {
5-
var codegen = this.process.bind(this);
6-
return codegen(node.left, indent) +
7-
this.ws + node.type + this.ws +
8-
codegen(node.right, indent);
5+
var codegen, str, firstpart, secondpart;
6+
codegen = this.process.bind(this);
7+
8+
firstpart = codegen(node.left, indent);
9+
secondpart = codegen(node.right, indent);
10+
str = firstpart + this.ws + node.type + this.ws + secondpart;
11+
12+
if (str.length > 80) {
13+
str = firstpart + this.ws + node.type + this.nl + indent + this.indent + secondpart;
14+
}
15+
16+
return str;
917
};

test/tests.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ describe('Declare', function () {
3939
});
4040
});
4141

42+
describe('BinaryExpressions', function () {
43+
it('should use multiple lines if they are longer than 80 chars', function () {
44+
expect(parseUnparse('<?php\n{echo "background:#F9F7D8;color:#A79F00; border:1px solid #F0EEBD;" . "background:#F9F7D8;color:#A79F00; border:1px solid #F0EEBD;" . "background:#F9F7D8;color:#A79F00; border:1px solid #F0EEBD;";}')).toBe([ '<?php', '', '{', ' echo "background:#F9F7D8;color:#A79F00; border:1px solid #F0EEBD;" .', ' "background:#F9F7D8;color:#A79F00; border:1px solid #F0EEBD;" .', ' "background:#F9F7D8;color:#A79F00; border:1px solid #F0EEBD;";', '}', '', '' ].join('\n'));
45+
});
46+
});
47+
4248
describe('acid1.php', function () {
4349
it('must correcty convert nested blocks', function (done) {
4450
fs.readFile('./test/spec/acid1-parsed.php', function (err, strparsed) {

0 commit comments

Comments
 (0)