Skip to content

Commit db53bd7

Browse files
author
Filippo Conti
committed
Ensure bracketsNewLine options for all templates
1 parent 1d67192 commit db53bd7

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

node_translators/class.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ module.exports = function (node, indent) {
3232

3333
// begin curly brace
3434
if (node.name) {
35-
str += this.nl + indent + '{' + this.nl;
35+
if( this.options.bracketsNewLine ) {
36+
str += this.nl + indent + '{' + this.nl;
37+
} else {
38+
str += this.ws + '{' + this.nl;
39+
}
3640
} else {
3741
str += this.ws + '{' + this.nl;
3842
}

node_translators/function.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = function(node, indent) {
2929
if (this.options.bracketsNewLine) {
3030
str += this.nl + indent + '{' + this.nl;
3131
} else {
32-
str += '{' + this.nl;
32+
str += this.ws + '{' + this.nl;
3333
}
3434

3535
str += doBody(codegen, indent, this.indent, this.nl, node.body.children);

node_translators/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
'use strict';
33

44
function CodeGen(options) {
5-
6-
this.ws = ' ';
7-
if (options.dontUseWhitespaces) {
8-
this.ws = '';
9-
}
105

6+
// Get options
117
this.options = options;
8+
this.ws = options.dontUseWhitespaces ? '' : ' ';
129
this.indent = typeof options.indent === 'string' ? options.indent : ' ';
1310
this.nl = this.indent !== '' ? '\n' : '';
1411
this.shortArray = options.shortArray || false;
@@ -31,9 +28,7 @@ function CodeGen(options) {
3128
)
3229
);
3330
} else {
34-
err = new Error(
35-
'Bad AST structure'
36-
);
31+
err = new Error('Bad AST structure');
3732
}
3833
err.node = node;
3934
throw err;

node_translators/interface.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ module.exports = function (node, indent) {
1818
}
1919

2020
// begin curly brace
21-
str += this.nl + indent + '{' + this.nl;
21+
if( this.options.bracketsNewLine ) {
22+
str += this.nl + indent + '{' + this.nl;
23+
} else {
24+
str += this.ws + '{' + this.nl;
25+
}
2226

2327
// interface body
2428
str += doBody(codegen, indent, this.indent, this.nl, node.body);

node_translators/method.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = function(node, indent) {
4848
if (this.options.bracketsNewLine) {
4949
str += this.nl + indent + '{' + this.nl;
5050
} else {
51-
str += '{' + this.nl;
51+
str += this.ws + '{' + this.nl;
5252
}
5353

5454
str += doBody(codegen, indent, this.indent, this.nl, node.body.children);

node_translators/namespace.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var body = require('./helper/body');
55
module.exports = function (node, indent) {
66
var str, codegen;
77

8-
98
str = 'namespace ' + node.name + this.ws + '\n{\n\n';
109
codegen = this.process.bind(this);
1110
str += body(codegen, indent, this.indent, this.nl, node.children);

node_translators/trait.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ module.exports = function (node, indent) {
1818
}
1919

2020
// begin curly brace
21-
str += this.nl + indent + '{' + this.nl;
21+
if( this.options.bracketsNewLine ) {
22+
str += this.nl + indent + '{' + this.nl;
23+
} else {
24+
str += this.ws + '{' + this.nl;
25+
}
2226

2327
// trait body
2428
str += doBody(codegen, indent, this.indent, this.nl, node.body);

0 commit comments

Comments
 (0)