File tree 4 files changed +89
-2
lines changed
python/jsbeautifier/javascript
4 files changed +89
-2
lines changed Original file line number Diff line number Diff line change @@ -186,7 +186,8 @@ Tokenizer.prototype._read_word = function(previous_token) {
186
186
if ( ! ( previous_token . type === TOKEN . DOT ||
187
187
( previous_token . type === TOKEN . RESERVED && ( previous_token . text === 'set' || previous_token . text === 'get' ) ) ) &&
188
188
reserved_word_pattern . test ( resulting_string ) ) {
189
- if ( resulting_string === 'in' || resulting_string === 'of' ) { // hack for 'in' and 'of' operators
189
+ if ( ( resulting_string === 'in' || resulting_string === 'of' ) &&
190
+ ( previous_token . type === TOKEN . WORD || previous_token . type === TOKEN . STRING ) ) { // hack for 'in' and 'of' operators
190
191
return this . _create_token ( TOKEN . OPERATOR , resulting_string ) ;
191
192
}
192
193
return this . _create_token ( TOKEN . RESERVED , resulting_string ) ;
Original file line number Diff line number Diff line change @@ -267,7 +267,10 @@ def _read_word(self, previous_token):
267
267
and (previous_token .text == "set" or previous_token .text == "get" )
268
268
)
269
269
) and reserved_word_pattern .match (resulting_string ):
270
- if resulting_string == "in" or resulting_string == "of" :
270
+ if (resulting_string == "in" or resulting_string == "of" ) and (
271
+ previous_token .type == TOKEN .WORD
272
+ or previous_token .type == TOKEN .STRING
273
+ ):
271
274
# in and of are operators, need to hack
272
275
return self ._create_token (TOKEN .OPERATOR , resulting_string )
273
276
Original file line number Diff line number Diff line change @@ -4721,6 +4721,89 @@ exports.test_data = {
4721
4721
')'
4722
4722
]
4723
4723
} ,
4724
+ {
4725
+ comment : "Issue ##1846 - in keyword in class method causes indentation problem" ,
4726
+ input : [
4727
+ 'class {' ,
4728
+ ' get a() {' ,
4729
+ '\n' ,
4730
+ ' }' ,
4731
+ '\n' ,
4732
+ ' in() {' ,
4733
+ '\n' ,
4734
+ ' }' ,
4735
+ '\n' ,
4736
+ ' b() {' ,
4737
+ '\n' ,
4738
+ ' }' ,
4739
+ '}'
4740
+ ] ,
4741
+ output : [
4742
+ 'class {' ,
4743
+ ' get a() {' ,
4744
+ '\n' ,
4745
+ ' }' ,
4746
+ '\n' ,
4747
+ ' in() {' ,
4748
+ '\n' ,
4749
+ ' }' ,
4750
+ '\n' ,
4751
+ ' b() {' ,
4752
+ '\n' ,
4753
+ ' }' ,
4754
+ '}'
4755
+ ]
4756
+ } ,
4757
+ {
4758
+ comment : "Related to Issue ##1846 - Do not indent 'in' keyword if not a class method" ,
4759
+ input : [
4760
+ 'function test() {' ,
4761
+ 'for x in nums {}' ,
4762
+ '"make" in car' ,
4763
+ '3 in number;' ,
4764
+ '}'
4765
+ ] ,
4766
+ output : [
4767
+ 'function test() {' ,
4768
+ ' for x in nums {}' ,
4769
+ ' "make" in car' ,
4770
+ ' 3 in number;' ,
4771
+ '}'
4772
+ ]
4773
+ } ,
4774
+ {
4775
+ comment : "Related to Issue ##1846 - of keyword in class method causes indentation problem" ,
4776
+ input : [
4777
+ 'class {' ,
4778
+ ' get a() {' ,
4779
+ '\n' ,
4780
+ ' }' ,
4781
+ '\n' ,
4782
+ ' of() {' ,
4783
+ '\n' ,
4784
+ ' }' ,
4785
+ '\n' ,
4786
+ ' b() {' ,
4787
+ '\n' ,
4788
+ ' }' ,
4789
+ '}'
4790
+ ] ,
4791
+ output : [
4792
+ 'class {' ,
4793
+ ' get a() {' ,
4794
+ '\n' ,
4795
+ ' }' ,
4796
+ '\n' ,
4797
+ ' of() {' ,
4798
+ '\n' ,
4799
+ ' }' ,
4800
+ '\n' ,
4801
+ ' b() {' ,
4802
+ '\n' ,
4803
+ ' }' ,
4804
+ '}'
4805
+ ]
4806
+ } ,
4724
4807
{
4725
4808
comment : 'Issue #1950: Do not remove whitespace after number - test scenario: number before a dot' ,
4726
4809
input : '1000000000000001000 .toFixed(0)!==1000000000000001024' ,
You can’t perform that action at this time.
0 commit comments