[ISSUE 1846] Resolve indent issue with class method named in

This commit is contained in:
kcamsanc 2022-03-28 21:57:31 -04:00
parent 3145b1d4a3
commit 47c63b65fb
4 changed files with 91 additions and 2 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -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);

View File

@ -22,6 +22,8 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from ast import Str
from lib2to3.pgen2.token import STRING
import re
from ..core.inputscanner import InputScanner
from ..core.tokenizer import TokenTypes as BaseTokenTypes
@ -265,7 +267,10 @@ class Tokenizer(BaseTokenizer):
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)

View File

@ -4532,6 +4532,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',
' }',
'}'
]
}
]
}, {