Skip to content

Commit 4cc5e6e

Browse files
authoredApr 22, 2022
Merge branch 'main' into feature/space-after-named-function-classes
2 parents 11f2dae + 3f22fa1 commit 4cc5e6e

File tree

6 files changed

+147
-4
lines changed

6 files changed

+147
-4
lines changed
 

‎.DS_Store

8 KB
Binary file not shown.

‎js/src/html/beautifier.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,15 @@ var TagOpenParserToken = function(parent, raw_token) {
611611
this.tag_check = tag_check_match ? tag_check_match[1] : '';
612612

613613
// 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+
}
616620
}
617621
}
622+
618623
this.tag_check = this.tag_check.toLowerCase();
619624

620625
if (raw_token.type === TOKEN.COMMENT) {

‎js/src/javascript/tokenizer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ Tokenizer.prototype._read_word = function(previous_token) {
186186
if (!(previous_token.type === TOKEN.DOT ||
187187
(previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
188188
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
190191
return this._create_token(TOKEN.OPERATOR, resulting_string);
191192
}
192193
return this._create_token(TOKEN.RESERVED, resulting_string);

‎python/jsbeautifier/javascript/tokenizer.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ def _read_word(self, previous_token):
269269
and (previous_token.text == "set" or previous_token.text == "get")
270270
)
271271
) 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+
):
273276
# in and of are operators, need to hack
274277
return self._create_token(TOKEN.OPERATOR, resulting_string)
275278

‎test/data/html/tests.js

+51
Original file line numberDiff line numberDiff line change
@@ -3591,6 +3591,57 @@ exports.test_data = {
35913591
'{{/if}}'
35923592
]
35933593
}]
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+
}]
35943645
}, {
35953646
name: "New Test Suite"
35963647
}]

‎test/data/javascript/tests.js

+83
Original file line numberDiff line numberDiff line change
@@ -4786,6 +4786,89 @@ exports.test_data = {
47864786
')'
47874787
]
47884788
},
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+
},
47894872
{
47904873
comment: 'Issue #1950: Do not remove whitespace after number - test scenario: number before a dot',
47914874
input: '1000000000000001000 .toFixed(0)!==1000000000000001024',

0 commit comments

Comments
 (0)
Please sign in to comment.