Skip to content

Commit

Permalink
Merge pull request #768 from Kingwl/master
Browse files Browse the repository at this point in the history
add nullish coalescing support
  • Loading branch information
sheetalkamat authored Aug 22, 2019
2 parents 84238ef + ce39790 commit f833322
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 6 deletions.
4 changes: 2 additions & 2 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ repository:

#ternary expression
ternary-expression:
begin: (?!\?\.\s*[^[:digit:]])(\?)
begin: (?!\?\.\s*[^[:digit:]])(\?)(?!\?)
beginCaptures:
'1': { name: keyword.operator.ternary.ts }
end: \s*(:)
Expand Down Expand Up @@ -1634,7 +1634,7 @@ repository:
- name: keyword.operator.relational.ts
match: <=|>=|<>|<|>
- name: keyword.operator.logical.ts
match: \!|&&|\|\|
match: \!|&&|\|\||\?\?
- name: keyword.operator.bitwise.ts
match: \&|~|\^|\|
- name: keyword.operator.assignment.ts
Expand Down
4 changes: 2 additions & 2 deletions TypeScript.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -4590,7 +4590,7 @@
<key>ternary-expression</key>
<dict>
<key>begin</key>
<string>(?!\?\.\s*[^[:digit:]])(\?)</string>
<string>(?!\?\.\s*[^[:digit:]])(\?)(?!\?)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -5327,7 +5327,7 @@
<key>name</key>
<string>keyword.operator.logical.ts</string>
<key>match</key>
<string>\!|&amp;&amp;|\|\|</string>
<string>\!|&amp;&amp;|\|\||\?\?</string>
</dict>
<dict>
<key>name</key>
Expand Down
4 changes: 2 additions & 2 deletions TypeScriptReact.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -4614,7 +4614,7 @@
<key>ternary-expression</key>
<dict>
<key>begin</key>
<string>(?!\?\.\s*[^[:digit:]])(\?)</string>
<string>(?!\?\.\s*[^[:digit:]])(\?)(?!\?)</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -5273,7 +5273,7 @@
<key>name</key>
<string>keyword.operator.logical.tsx</string>
<key>match</key>
<string>\!|&amp;&amp;|\|\|</string>
<string>\!|&amp;&amp;|\|\||\?\?</string>
</dict>
<dict>
<key>name</key>
Expand Down
274 changes: 274 additions & 0 deletions tests/baselines/issue522_1.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
original file
-----------------------------------
const brokenSyntaxHighlighting = () => {
const array = a ?? b ?? c ?? d ?? g;

/**
* No TypeEror, but syntax highlighting is broken
*/
const test = a ?? b ?? c ?? d ?? g;

for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
};

brokenSyntaxHighlighting();

-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>const brokenSyntaxHighlighting = () => {
^^^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts
^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.constant.ts entity.name.function.ts
^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.var.expr.ts meta.arrow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.var.expr.ts meta.arrow.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts storage.type.function.arrow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
> const array = a ?? b ?? c ?? d ?? g;
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.constant.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
>
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
> /**
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts comment.block.documentation.ts punctuation.definition.comment.ts
> * No TypeEror, but syntax highlighting is broken
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts comment.block.documentation.ts
> */
^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts comment.block.documentation.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts comment.block.documentation.ts punctuation.definition.comment.ts
> const test = a ?? b ?? c ?? d ?? g;
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.constant.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
>
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
> for (let i = 0; i < array.length; i++) {
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts keyword.control.loop.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.brace.round.ts
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.var.expr.ts constant.numeric.decimal.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts keyword.operator.relational.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts variable.other.object.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.accessor.ts
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts support.variable.property.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.terminator.statement.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts variable.other.readwrite.ts
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts keyword.operator.increment.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts punctuation.definition.block.ts
> console.log(array[i]);
^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts
^^^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts meta.function-call.ts support.class.console.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts meta.function-call.ts punctuation.accessor.ts
^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts meta.function-call.ts support.function.console.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts meta.brace.round.ts
^^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts meta.array.literal.ts meta.brace.square.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts meta.array.literal.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts meta.array.literal.ts meta.brace.square.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts punctuation.terminator.statement.ts
> }
^^^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts meta.block.ts punctuation.definition.block.ts
> };
^^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts
^
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
^
source.ts punctuation.terminator.statement.ts
>
^^^
source.ts
> brokenSyntaxHighlighting();
^^
source.ts
^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.brace.round.ts
^
source.ts meta.brace.round.ts
^
source.ts punctuation.terminator.statement.ts
>
^^^
source.ts
15 changes: 15 additions & 0 deletions tests/cases/issue522_1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const brokenSyntaxHighlighting = () => {
const array = a ?? b ?? c ?? d ?? g;

/**
* No TypeEror, but syntax highlighting is broken
*/
const test = a ?? b ?? c ?? d ?? g;

for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
};

brokenSyntaxHighlighting();

0 comments on commit f833322

Please sign in to comment.