Fix variable initializer end if ending in operator

Fixes #909, #932, #940
This commit is contained in:
Sheetal Nandi 2023-02-08 16:32:54 -08:00
Родитель abfece0c49
Коммит f169c9dbf5
10 изменённых файлов: 405 добавлений и 29 удалений

Просмотреть файл

@ -669,7 +669,7 @@ repository:
- begin: (?<!=|!)(=)(?!=)
beginCaptures:
'1': { name: keyword.operator.assignment.ts }
end: (?=[,);}\]]|({{startOfIdentifier}}(of|in)\s+))|(?=^\s*$)|(?<!\*\/)(?<=\S)(?<!=)(?=\s*$)
end: (?=[,);}\]]|({{startOfIdentifier}}(of|in)\s+))|(?=^\s*$)|(?<![\|\&\+\-\*\/])(?<=\S)(?<!=)(?=\s*$)
patterns:
- include: '#expression'

Просмотреть файл

@ -2061,7 +2061,7 @@
</dict>
</dict>
<key>end</key>
<string>(?=[,);}\]]|((?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(of|in)\s+))|(?=^\s*$)|(?&lt;!\*\/)(?&lt;=\S)(?&lt;!=)(?=\s*$)</string>
<string>(?=[,);}\]]|((?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(of|in)\s+))|(?=^\s*$)|(?&lt;![\|\&amp;\+\-\*\/])(?&lt;=\S)(?&lt;!=)(?=\s*$)</string>
<key>patterns</key>
<array>
<dict>

Просмотреть файл

@ -2081,7 +2081,7 @@
</dict>
</dict>
<key>end</key>
<string>(?=[,);}\]]|((?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(of|in)\s+))|(?=^\s*$)|(?&lt;!\*\/)(?&lt;=\S)(?&lt;!=)(?=\s*$)</string>
<string>(?=[,);}\]]|((?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(of|in)\s+))|(?=^\s*$)|(?&lt;![\|\&amp;\+\-\*\/])(?&lt;=\S)(?&lt;!=)(?=\s*$)</string>
<key>patterns</key>
<array>
<dict>

Просмотреть файл

@ -63,34 +63,34 @@ Grammar: TypeScript.tmLanguage
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> 2 > 1 &&
^^^^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts constant.numeric.decimal.ts
source.ts meta.class.ts meta.field.declaration.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts keyword.operator.relational.ts
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.relational.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts constant.numeric.decimal.ts
source.ts meta.class.ts meta.field.declaration.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts keyword.operator.logical.ts
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> FOO < FOOO;
^^^^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^^^
source.ts meta.class.ts variable.other.constant.ts
source.ts meta.class.ts meta.field.declaration.ts variable.other.constant.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts keyword.operator.relational.ts
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.relational.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
source.ts meta.class.ts meta.field.declaration.ts variable.other.constant.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
> myFunc2 = () =>
@ -131,34 +131,34 @@ Grammar: TypeScript.tmLanguage
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> 2 > 1 &&
^^^^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts constant.numeric.decimal.ts
source.ts meta.class.ts meta.field.declaration.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts keyword.operator.relational.ts
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.relational.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts constant.numeric.decimal.ts
source.ts meta.class.ts meta.field.declaration.ts constant.numeric.decimal.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts keyword.operator.logical.ts
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> FOO < FOOO;
^^^^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^^^
source.ts meta.class.ts variable.other.constant.ts
source.ts meta.class.ts meta.field.declaration.ts variable.other.constant.ts
^
source.ts meta.class.ts
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts keyword.operator.relational.ts
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.relational.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
source.ts meta.class.ts meta.field.declaration.ts variable.other.constant.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
>}

Просмотреть файл

@ -0,0 +1,136 @@
original file
-----------------------------------
class TestClass {
veryVeryVeryVeryVeryVeryVeryVeryLongName = true;
veryVeryVeryVeryLongName: string;
test = () =>
!this.veryVeryVeryVeryVeryVeryVeryVeryLongName ||
(!!this.veryVeryVeryVeryLongName && this.veryVeryVeryVeryLongName === 'veryVeryVeryVeryLongString');
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>class TestClass {
^^^^^
source.ts meta.class.ts storage.type.class.ts
^
source.ts meta.class.ts
^^^^^^^^^
source.ts meta.class.ts entity.name.type.class.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts punctuation.definition.block.ts
> veryVeryVeryVeryVeryVeryVeryVeryLongName = true;
^^
source.ts meta.class.ts meta.field.declaration.ts
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts constant.language.boolean.true.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
> veryVeryVeryVeryLongName: string;
^^
source.ts meta.class.ts meta.field.declaration.ts
^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
>
^
source.ts meta.class.ts
> test = () =>
^^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts storage.type.function.arrow.ts
> !this.veryVeryVeryVeryVeryVeryVeryVeryLongName ||
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.language.this.ts
^
source.ts meta.class.ts meta.field.declaration.ts punctuation.accessor.ts
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.other.property.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> (!!this.veryVeryVeryVeryLongName && this.veryVeryVeryVeryLongName === 'veryVeryVeryVeryLongString');
^^^^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.language.this.ts
^
source.ts meta.class.ts meta.field.declaration.ts punctuation.accessor.ts
^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.other.property.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.language.this.ts
^
source.ts meta.class.ts meta.field.declaration.ts punctuation.accessor.ts
^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.other.property.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.comparison.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts string.quoted.single.ts punctuation.definition.string.begin.ts
^^^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts string.quoted.single.ts
^
source.ts meta.class.ts meta.field.declaration.ts string.quoted.single.ts punctuation.definition.string.end.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
>}
^
source.ts meta.class.ts punctuation.definition.block.ts

Просмотреть файл

@ -0,0 +1,84 @@
original file
-----------------------------------
class A {
f = () =>
false &&
(false) ||
(this.f);
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>class A {
^^^^^
source.ts meta.class.ts storage.type.class.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts entity.name.type.class.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts punctuation.definition.block.ts
> f = () =>
^^^^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.assignment.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts storage.type.function.arrow.ts
^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
> false &&
^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.arrow.ts
^^^^^
source.ts meta.class.ts meta.field.declaration.ts constant.language.boolean.false.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> (false) ||
^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^^^^^
source.ts meta.class.ts meta.field.declaration.ts constant.language.boolean.false.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> (this.f);
^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts variable.language.this.ts
^
source.ts meta.class.ts meta.field.declaration.ts punctuation.accessor.ts
^
source.ts meta.class.ts meta.field.declaration.ts variable.other.property.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
>}
^
source.ts meta.class.ts punctuation.definition.block.ts

Просмотреть файл

@ -0,0 +1,132 @@
original file
-----------------------------------
class Foo {
readonly baz =
this.bar() ||
(this.bar() &&
this.bar());
bar() {
return true;
}
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>class Foo {
^^^^^
source.ts meta.class.ts storage.type.class.ts
^
source.ts meta.class.ts
^^^
source.ts meta.class.ts entity.name.type.class.ts
^
source.ts meta.class.ts
^
source.ts meta.class.ts punctuation.definition.block.ts
> readonly baz =
^^^^
source.ts meta.class.ts
^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts storage.modifier.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^^
source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.assignment.ts
^^
source.ts meta.class.ts meta.field.declaration.ts
> this.bar() ||
^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts variable.language.this.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts punctuation.accessor.ts
^^^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
> (this.bar() &&
^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts variable.language.this.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts punctuation.accessor.ts
^^^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.field.declaration.ts
^^
source.ts meta.class.ts meta.field.declaration.ts keyword.operator.logical.ts
^^
source.ts meta.class.ts meta.field.declaration.ts
> this.bar());
^^^^^^^^
source.ts meta.class.ts meta.field.declaration.ts
^^^^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts variable.language.this.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts punctuation.accessor.ts
^^^
source.ts meta.class.ts meta.field.declaration.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts meta.field.declaration.ts meta.brace.round.ts
^
source.ts meta.class.ts punctuation.terminator.statement.ts
>
^
source.ts meta.class.ts
> bar() {
^^^^
source.ts meta.class.ts meta.method.declaration.ts
^^^
source.ts meta.class.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.class.ts meta.method.declaration.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
> return true;
^^^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^^^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts constant.language.boolean.true.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.terminator.statement.ts
> }
^^^^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts
^
source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts
>}
^
source.ts meta.class.ts punctuation.definition.block.ts

8
tests/cases/issue909.ts Normal file
Просмотреть файл

@ -0,0 +1,8 @@
class TestClass {
veryVeryVeryVeryVeryVeryVeryVeryLongName = true;
veryVeryVeryVeryLongName: string;
test = () =>
!this.veryVeryVeryVeryVeryVeryVeryVeryLongName ||
(!!this.veryVeryVeryVeryLongName && this.veryVeryVeryVeryLongName === 'veryVeryVeryVeryLongString');
}

6
tests/cases/issue932.ts Normal file
Просмотреть файл

@ -0,0 +1,6 @@
class A {
f = () =>
false &&
(false) ||
(this.f);
}

10
tests/cases/issue940.ts Normal file
Просмотреть файл

@ -0,0 +1,10 @@
class Foo {
readonly baz =
this.bar() ||
(this.bar() &&
this.bar());
bar() {
return true;
}
}