Skip to content

Commit

Permalink
Fix space in parent for objects items
Browse files Browse the repository at this point in the history
Fixed #860
  • Loading branch information
bitwiseman committed Jan 30, 2016
1 parent bde0f5f commit cb3ef83
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 5 deletions.
4 changes: 2 additions & 2 deletions js/lib/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,8 @@
flags.inline_frame = true;
previous_flags.multiline_frame = previous_flags.multiline_frame || flags.multiline_frame;
flags.multiline_frame = false;
} else {
output.space_before_token = last_type === 'TK_COMMA';
} else if (last_type === 'TK_COMMA') {
output.space_before_token = true;
}
} else if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
if (last_type === 'TK_START_BLOCK') {
Expand Down
52 changes: 52 additions & 0 deletions js/test/generated/beautify-javascript-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,23 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bt('a=[];', 'a = [];');
bt('a=[b,c,d];', 'a = [b, c, d];');
bt('a= f[b];', 'a = f[b];');
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}',
'{\n' +
' files: [{\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: ["im/design_standards/*.*"],\n' +
' dest: "www/gui/build"\n' +
' }]\n' +
'}');

// Space in parens tests - (s = "", e = "")
opts.space_in_paren = false;
Expand All @@ -422,6 +439,23 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bt('a=[];', 'a = [];');
bt('a=[b,c,d];', 'a = [b, c, d];');
bt('a= f[b];', 'a = f[b];');
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}',
'{\n' +
' files: [{\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: ["im/design_standards/*.*"],\n' +
' dest: "www/gui/build"\n' +
' }]\n' +
'}');

// Space in parens tests - (s = " ", e = "")
opts.space_in_paren = true;
Expand All @@ -433,6 +467,15 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bt('a=[];', 'a = [];');
bt('a=[b,c,d];', 'a = [ b, c, d ];');
bt('a= f[b];', 'a = f[ b ];');
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}');

// Space in parens tests - (s = " ", e = " ")
opts.space_in_paren = true;
Expand All @@ -444,6 +487,15 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bt('a=[];', 'a = [ ];');
bt('a=[b,c,d];', 'a = [ b, c, d ];');
bt('a= f[b];', 'a = f[ b ];');
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}');


reset_options();
Expand Down
5 changes: 2 additions & 3 deletions python/jsbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,8 @@ def handle_start_block(self, current_token):
self.flags.inline_frame = True
self.previous_flags.multiline_frame = self.previous_flags.multiline_frame or self.flags.multiline_frame
self.flags.multiline_frame = False
else:
self.output.space_before_token = self.last_type == 'TK_COMMA'

elif self.last_type == 'TK_COMMA':
self.output.space_before_token = True

elif self.last_type not in ['TK_OPERATOR', 'TK_START_EXPR']:
if self.last_type == 'TK_START_BLOCK':
Expand Down
52 changes: 52 additions & 0 deletions python/jsbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ def unicode_char(value):
bt('a=[];', 'a = [];')
bt('a=[b,c,d];', 'a = [b, c, d];')
bt('a= f[b];', 'a = f[b];')
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}',
'{\n' +
' files: [{\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: ["im/design_standards/*.*"],\n' +
' dest: "www/gui/build"\n' +
' }]\n' +
'}')

# Space in parens tests - (s = "", e = "")
self.options.space_in_paren = false
Expand All @@ -248,6 +265,23 @@ def unicode_char(value):
bt('a=[];', 'a = [];')
bt('a=[b,c,d];', 'a = [b, c, d];')
bt('a= f[b];', 'a = f[b];')
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}',
'{\n' +
' files: [{\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: ["im/design_standards/*.*"],\n' +
' dest: "www/gui/build"\n' +
' }]\n' +
'}')

# Space in parens tests - (s = " ", e = "")
self.options.space_in_paren = true
Expand All @@ -259,6 +293,15 @@ def unicode_char(value):
bt('a=[];', 'a = [];')
bt('a=[b,c,d];', 'a = [ b, c, d ];')
bt('a= f[b];', 'a = f[ b ];')
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}')

# Space in parens tests - (s = " ", e = " ")
self.options.space_in_paren = true
Expand All @@ -270,6 +313,15 @@ def unicode_char(value):
bt('a=[];', 'a = [ ];')
bt('a=[b,c,d];', 'a = [ b, c, d ];')
bt('a= f[b];', 'a = f[ b ];')
bt(
'{\n' +
' files: [ {\n' +
' expand: true,\n' +
' cwd: "www/gui/",\n' +
' src: [ "im/design_standards/*.*" ],\n' +
' dest: "www/gui/build"\n' +
' } ]\n' +
'}')


self.reset_options();
Expand Down
22 changes: 22 additions & 0 deletions test/data/javascript/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,28 @@ exports.test_data = {
input: 'a= f[b];',
output: 'a = f[{{s}}b{{s}}];'
},
{
input: [
'{',
' files: [ {',
' expand: true,',
' cwd: "www/gui/",',
' src: [ "im/design_standards/*.*" ],',
' dest: "www/gui/build"',
' } ]',
'}'
],
output: [
'{',
' files: [{{s}}{',
' expand: true,',
' cwd: "www/gui/",',
' src: [{{s}}"im/design_standards/*.*"{{s}}],',
' dest: "www/gui/build"',
' }{{s}}]',
'}'
],
},
],
}, {
name: "New Test Suite"
Expand Down

0 comments on commit cb3ef83

Please sign in to comment.