File tree 6 files changed +147
-4
lines changed
python/jsbeautifier/javascript
6 files changed +147
-4
lines changed Original file line number Diff line number Diff line change @@ -611,10 +611,15 @@ var TagOpenParserToken = function(parent, raw_token) {
611
611
this . tag_check = tag_check_match ? tag_check_match [ 1 ] : '' ;
612
612
613
613
// handle "{{#> myPartial}}" or "{{~#> myPartial}}"
614
- if ( ( raw_token . text === '{{#>' || raw_token . text === '{{~#>' ) && this . tag_check === '>' && raw_token . next !== null ) {
615
- this . tag_check = raw_token . next . text . split ( ' ' ) [ 0 ] ;
614
+ if ( ( raw_token . text . startsWith ( '{{#>' ) || raw_token . text . startsWith ( '{{~#>' ) ) && this . tag_check [ 0 ] === '>' ) {
615
+ if ( this . tag_check === '>' && raw_token . next !== null ) {
616
+ this . tag_check = raw_token . next . text . split ( ' ' ) [ 0 ] ;
617
+ } else {
618
+ this . tag_check = raw_token . text . split ( '>' ) [ 1 ] ;
619
+ }
616
620
}
617
621
}
622
+
618
623
this . tag_check = this . tag_check . toLowerCase ( ) ;
619
624
620
625
if ( raw_token . type === TOKEN . COMMENT ) {
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 @@ -269,7 +269,10 @@ def _read_word(self, previous_token):
269
269
and (previous_token .text == "set" or previous_token .text == "get" )
270
270
)
271
271
) and reserved_word_pattern .match (resulting_string ):
272
- if resulting_string == "in" or resulting_string == "of" :
272
+ if (resulting_string == "in" or resulting_string == "of" ) and (
273
+ previous_token .type == TOKEN .WORD
274
+ or previous_token .type == TOKEN .STRING
275
+ ):
273
276
# in and of are operators, need to hack
274
277
return self ._create_token (TOKEN .OPERATOR , resulting_string )
275
278
Original file line number Diff line number Diff line change @@ -3591,6 +3591,57 @@ exports.test_data = {
3591
3591
'{{/if}}'
3592
3592
]
3593
3593
} ]
3594
+ } , {
3595
+ name : "Corrects Partial Behavior Involving Whitespace" ,
3596
+ description : "Handles partials that do not have a space before the tag" ,
3597
+ template : "^^^ $$$" ,
3598
+ tests : [ {
3599
+ input : [
3600
+ '{{#>row}}' ,
3601
+ ' {{#>column}}' ,
3602
+ ' <span>content</span>' ,
3603
+ ' {{/column}}' ,
3604
+ ' {{/row}}'
3605
+ ] ,
3606
+ output : [
3607
+ '{{#>row}}' ,
3608
+ ' {{#>column}}' ,
3609
+ ' <span>content</span>' ,
3610
+ ' {{/column}}' ,
3611
+ '{{/row}}'
3612
+ ]
3613
+ } , {
3614
+ input : [
3615
+ '{{~#>row}}' ,
3616
+ '{{#>column}}' ,
3617
+ '<p>content</p>' ,
3618
+ '{{/column}}' ,
3619
+ '{{/row}}'
3620
+ ] ,
3621
+ output : [
3622
+ '{{~#>row}}' ,
3623
+ ' {{#>column}}' ,
3624
+ ' <p>content</p>' ,
3625
+ ' {{/column}}' ,
3626
+ '{{/row}}'
3627
+ ]
3628
+ } , {
3629
+ unchanged : [
3630
+ '{{#>row}}' ,
3631
+ ' {{#>column}}' ,
3632
+ ' <span>content</span>' ,
3633
+ ' {{/column}}' ,
3634
+ '{{/row}}'
3635
+ ]
3636
+ } , {
3637
+ unchanged : [
3638
+ '{{#> row}}' ,
3639
+ ' {{#> column}}' ,
3640
+ ' <span>content</span>' ,
3641
+ ' {{/column}}' ,
3642
+ '{{/row}}'
3643
+ ]
3644
+ } ]
3594
3645
} , {
3595
3646
name : "New Test Suite"
3596
3647
} ]
Original file line number Diff line number Diff line change @@ -4786,6 +4786,89 @@ exports.test_data = {
4786
4786
')'
4787
4787
]
4788
4788
} ,
4789
+ {
4790
+ comment : "Issue ##1846 - in keyword in class method causes indentation problem" ,
4791
+ input : [
4792
+ 'class {' ,
4793
+ ' get a() {' ,
4794
+ '\n' ,
4795
+ ' }' ,
4796
+ '\n' ,
4797
+ ' in() {' ,
4798
+ '\n' ,
4799
+ ' }' ,
4800
+ '\n' ,
4801
+ ' b() {' ,
4802
+ '\n' ,
4803
+ ' }' ,
4804
+ '}'
4805
+ ] ,
4806
+ output : [
4807
+ 'class {' ,
4808
+ ' get a() {' ,
4809
+ '\n' ,
4810
+ ' }' ,
4811
+ '\n' ,
4812
+ ' in() {' ,
4813
+ '\n' ,
4814
+ ' }' ,
4815
+ '\n' ,
4816
+ ' b() {' ,
4817
+ '\n' ,
4818
+ ' }' ,
4819
+ '}'
4820
+ ]
4821
+ } ,
4822
+ {
4823
+ comment : "Related to Issue ##1846 - Do not indent 'in' keyword if not a class method" ,
4824
+ input : [
4825
+ 'function test() {' ,
4826
+ 'for x in nums {}' ,
4827
+ '"make" in car' ,
4828
+ '3 in number;' ,
4829
+ '}'
4830
+ ] ,
4831
+ output : [
4832
+ 'function test() {' ,
4833
+ ' for x in nums {}' ,
4834
+ ' "make" in car' ,
4835
+ ' 3 in number;' ,
4836
+ '}'
4837
+ ]
4838
+ } ,
4839
+ {
4840
+ comment : "Related to Issue ##1846 - of keyword in class method causes indentation problem" ,
4841
+ input : [
4842
+ 'class {' ,
4843
+ ' get a() {' ,
4844
+ '\n' ,
4845
+ ' }' ,
4846
+ '\n' ,
4847
+ ' of() {' ,
4848
+ '\n' ,
4849
+ ' }' ,
4850
+ '\n' ,
4851
+ ' b() {' ,
4852
+ '\n' ,
4853
+ ' }' ,
4854
+ '}'
4855
+ ] ,
4856
+ output : [
4857
+ 'class {' ,
4858
+ ' get a() {' ,
4859
+ '\n' ,
4860
+ ' }' ,
4861
+ '\n' ,
4862
+ ' of() {' ,
4863
+ '\n' ,
4864
+ ' }' ,
4865
+ '\n' ,
4866
+ ' b() {' ,
4867
+ '\n' ,
4868
+ ' }' ,
4869
+ '}'
4870
+ ]
4871
+ } ,
4789
4872
{
4790
4873
comment : 'Issue #1950: Do not remove whitespace after number - test scenario: number before a dot' ,
4791
4874
input : '1000000000000001000 .toFixed(0)!==1000000000000001024' ,
You can’t perform that action at this time.
0 commit comments