Skip to content

Commit

Permalink
Merge branch 'main' into feature/space-after-named-function-classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Apr 22, 2022
2 parents 11f2dae + 3f22fa1 commit 4cc5e6e
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 4 deletions.
Binary file added .DS_Store
Binary file not shown.
9 changes: 7 additions & 2 deletions js/src/html/beautifier.js
Expand Up @@ -611,10 +611,15 @@ var TagOpenParserToken = function(parent, raw_token) {
this.tag_check = tag_check_match ? tag_check_match[1] : '';

// handle "{{#> myPartial}}" or "{{~#> myPartial}}"
if ((raw_token.text === '{{#>' || raw_token.text === '{{~#>') && this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text.split(' ')[0];
if ((raw_token.text.startsWith('{{#>') || raw_token.text.startsWith('{{~#>')) && this.tag_check[0] === '>') {
if (this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text.split(' ')[0];
} else {
this.tag_check = raw_token.text.split('>')[1];
}
}
}

this.tag_check = this.tag_check.toLowerCase();

if (raw_token.type === TOKEN.COMMENT) {
Expand Down
3 changes: 2 additions & 1 deletion js/src/javascript/tokenizer.js
Expand Up @@ -186,7 +186,8 @@ Tokenizer.prototype._read_word = function(previous_token) {
if (!(previous_token.type === TOKEN.DOT ||
(previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
reserved_word_pattern.test(resulting_string)) {
if (resulting_string === 'in' || resulting_string === 'of') { // hack for 'in' and 'of' operators
if ((resulting_string === 'in' || resulting_string === 'of') &&
(previous_token.type === TOKEN.WORD || previous_token.type === TOKEN.STRING)) { // hack for 'in' and 'of' operators
return this._create_token(TOKEN.OPERATOR, resulting_string);
}
return this._create_token(TOKEN.RESERVED, resulting_string);
Expand Down
5 changes: 4 additions & 1 deletion python/jsbeautifier/javascript/tokenizer.py
Expand Up @@ -269,7 +269,10 @@ def _read_word(self, previous_token):
and (previous_token.text == "set" or previous_token.text == "get")
)
) and reserved_word_pattern.match(resulting_string):
if resulting_string == "in" or resulting_string == "of":
if (resulting_string == "in" or resulting_string == "of") and (
previous_token.type == TOKEN.WORD
or previous_token.type == TOKEN.STRING
):
# in and of are operators, need to hack
return self._create_token(TOKEN.OPERATOR, resulting_string)

Expand Down
51 changes: 51 additions & 0 deletions test/data/html/tests.js
Expand Up @@ -3591,6 +3591,57 @@ exports.test_data = {
'{{/if}}'
]
}]
}, {
name: "Corrects Partial Behavior Involving Whitespace",
description: "Handles partials that do not have a space before the tag",
template: "^^^ $$$",
tests: [{
input: [
'{{#>row}}',
' {{#>column}}',
' <span>content</span>',
' {{/column}}',
' {{/row}}'
],
output: [
'{{#>row}}',
' {{#>column}}',
' <span>content</span>',
' {{/column}}',
'{{/row}}'
]
}, {
input: [
'{{~#>row}}',
'{{#>column}}',
'<p>content</p>',
'{{/column}}',
'{{/row}}'
],
output: [
'{{~#>row}}',
' {{#>column}}',
' <p>content</p>',
' {{/column}}',
'{{/row}}'
]
}, {
unchanged: [
'{{#>row}}',
' {{#>column}}',
' <span>content</span>',
' {{/column}}',
'{{/row}}'
]
}, {
unchanged: [
'{{#> row}}',
' {{#> column}}',
' <span>content</span>',
' {{/column}}',
'{{/row}}'
]
}]
}, {
name: "New Test Suite"
}]
Expand Down
83 changes: 83 additions & 0 deletions test/data/javascript/tests.js
Expand Up @@ -4786,6 +4786,89 @@ exports.test_data = {
')'
]
},
{
comment: "Issue ##1846 - in keyword in class method causes indentation problem",
input: [
'class {',
' get a() {',
'\n',
' }',
'\n',
' in() {',
'\n',
' }',
'\n',
' b() {',
'\n',
' }',
'}'
],
output: [
'class {',
' get a() {',
'\n',
' }',
'\n',
' in() {',
'\n',
' }',
'\n',
' b() {',
'\n',
' }',
'}'
]
},
{
comment: "Related to Issue ##1846 - Do not indent 'in' keyword if not a class method",
input: [
'function test() {',
'for x in nums {}',
'"make" in car',
'3 in number;',
'}'
],
output: [
'function test() {',
' for x in nums {}',
' "make" in car',
' 3 in number;',
'}'
]
},
{
comment: "Related to Issue ##1846 - of keyword in class method causes indentation problem",
input: [
'class {',
' get a() {',
'\n',
' }',
'\n',
' of() {',
'\n',
' }',
'\n',
' b() {',
'\n',
' }',
'}'
],
output: [
'class {',
' get a() {',
'\n',
' }',
'\n',
' of() {',
'\n',
' }',
'\n',
' b() {',
'\n',
' }',
'}'
]
},
{
comment: 'Issue #1950: Do not remove whitespace after number - test scenario: number before a dot',
input: '1000000000000001000 .toFixed(0)!==1000000000000001024',
Expand Down

0 comments on commit 4cc5e6e

Please sign in to comment.