[gtksourceview: 3/5] javascript.lang: Support nullish coalescing



commit b5eb691e01e166cd9c0e70314480ac06cd99f23f
Author: Jeffery To <jeffery to gmail com>
Date:   Sat Jan 18 02:37:51 2020 +0800

    javascript.lang: Support nullish coalescing
    
    The proposal reached stage 4 in December 2019, will be in ES2020.
    
    This also removes TypeScript-specific handling for nullish coalescing.
    
    Reference:
    https://github.com/tc39/proposal-nullish-coalescing

 data/language-specs/javascript-expressions.lang    |  1 +
 data/language-specs/javascript.lang                |  1 +
 data/language-specs/typescript-js-expressions.lang | 44 ----------------------
 data/language-specs/typescript.lang                |  5 ---
 tests/syntax-highlighting/file.j                   |  3 ++
 tests/syntax-highlighting/file.js                  |  3 ++
 tests/syntax-highlighting/file.jsx                 |  3 ++
 tests/syntax-highlighting/file.ts                  |  7 ++--
 tests/syntax-highlighting/file.tsx                 |  7 ++--
 9 files changed, 17 insertions(+), 57 deletions(-)
---
diff --git a/data/language-specs/javascript-expressions.lang b/data/language-specs/javascript-expressions.lang
index 95026a7b..5f869b3e 100644
--- a/data/language-specs/javascript-expressions.lang
+++ b/data/language-specs/javascript-expressions.lang
@@ -576,6 +576,7 @@
         [+/*%-] =? |                         # arithmetic (assignment)
         [!=]==? |                            # equality
         &amp;&amp; | \|\| |                  # logical
+        \?\? |                               # nullish coalescing (ES2020)
         [&amp;|^] =? |                       # bitwise logical (assignment)
         (?: &lt;&lt; | &gt;&gt;&gt;? ) =? |  # bitwise shift (assignment)
         [&lt;&gt;]=? |                       # relational
diff --git a/data/language-specs/javascript.lang b/data/language-specs/javascript.lang
index 4ae8ab11..8f3fa3c9 100644
--- a/data/language-specs/javascript.lang
+++ b/data/language-specs/javascript.lang
@@ -140,6 +140,7 @@
          * Promise.allSettled
          * globalThis
          * Optional Chaining
+         * Nullish Coalescing operator
 
          Features from Annex B of the spec are not highlighted to
          discourage their use, except:
diff --git a/data/language-specs/typescript-js-expressions.lang 
b/data/language-specs/typescript-js-expressions.lang
index 3e7416bc..4c8bad26 100644
--- a/data/language-specs/typescript-js-expressions.lang
+++ b/data/language-specs/typescript-js-expressions.lang
@@ -161,50 +161,6 @@
     </context> <!-- /pre-lhs-expression -->
 
 
-    <!-- # Binary operators -->
-
-    <!-- excluding comma operator -->
-    <define-regex id="_binary-operator" extended="true">
-      (?:
-        \*\* =? |                            # exponentiation (assignment) (ES2016)
-        [+/*%-] =? |                         # arithmetic (assignment)
-        [!=]==? |                            # equality
-        &amp;&amp; | \|\| |                  # logical
-        \?\? |                               # nullish coalescing (stage 3 proposal)
-        [&amp;|^] =? |                       # bitwise logical (assignment)
-        (?: &lt;&lt; | &gt;&gt;&gt;? ) =? |  # bitwise shift (assignment)
-        [&lt;&gt;]=? |                       # relational
-        =                                    # assignment
-      )
-    </define-regex> <!-- /_binary-operator -->
-
-    <!-- ## Without comma -->
-
-    <!-- replaces js-expr:_binary-operators-without-comma -->
-    <context id="binary-operators-without-comma">
-      <start>\%{_binary-operator}</start>
-      <end>\%{js:before-next-token}</end>
-      <include>
-        <context sub-pattern="0" where="start" style-ref="js:binary-operator"/>
-        <context ref="js:comments"/>
-        <context ref="js-expr:_binary-operator-without-comma-content"/>
-      </include>
-    </context> <!-- /binary-operators-without-comma -->
-
-    <!-- ## With comma -->
-
-    <!-- replaces js-expr:_binary-operators-with-comma -->
-    <context id="binary-operators-with-comma">
-      <start>(\%{_binary-operator}|,)</start>
-      <end>\%{js:before-next-token}</end>
-      <include>
-        <context sub-pattern="0" where="start" style-ref="js:binary-operator"/>
-        <context ref="js:comments"/>
-        <context ref="js-expr:_binary-operator-with-comma-content"/>
-      </include>
-    </context> <!-- /binary-operators-with-comma -->
-
-
     <!-- # as operator (type assertion / cast)
 
          a = obj as string;
diff --git a/data/language-specs/typescript.lang b/data/language-specs/typescript.lang
index c5568153..fa6e6da9 100644
--- a/data/language-specs/typescript.lang
+++ b/data/language-specs/typescript.lang
@@ -775,11 +775,6 @@
 
     <replace id="js-expr:_pre-lhs-expression" ref="typescript-js-expr:pre-lhs-expression"/>
 
-    <!-- ### Binary operators -->
-
-    <replace id="js-expr:_binary-operators-without-comma" 
ref="typescript-js-expr:binary-operators-without-comma"/>
-    <replace id="js-expr:_binary-operators-with-comma" ref="typescript-js-expr:binary-operators-with-comma"/>
-
     <!-- ### Post-LHS expression -->
 
     <replace id="js-expr:_post-lhs-expression-without-comma" 
ref="typescript-js-expr:post-lhs-expression-without-comma"/>
diff --git a/tests/syntax-highlighting/file.j b/tests/syntax-highlighting/file.j
index 4591ce33..092b08b5 100644
--- a/tests/syntax-highlighting/file.j
+++ b/tests/syntax-highlighting/file.j
@@ -741,6 +741,9 @@ a = class extends Bar {
 ( 1 || 2 );
 ( !1 );
 
+// Nullish coalescing (ES2020)
+( a ?? 1 );
+
 // Assignment
 ( a = 1 );
 ( a += 1 );
diff --git a/tests/syntax-highlighting/file.js b/tests/syntax-highlighting/file.js
index fa7e0680..fb71e151 100644
--- a/tests/syntax-highlighting/file.js
+++ b/tests/syntax-highlighting/file.js
@@ -440,6 +440,9 @@ a = class extends Bar {
 ( 1 || 2 );
 ( !1 );
 
+// Nullish coalescing (ES2020)
+( a ?? 1 );
+
 // Assignment
 ( a = 1 );
 ( a += 1 );
diff --git a/tests/syntax-highlighting/file.jsx b/tests/syntax-highlighting/file.jsx
index cfb23f1d..29a8fe07 100644
--- a/tests/syntax-highlighting/file.jsx
+++ b/tests/syntax-highlighting/file.jsx
@@ -497,6 +497,9 @@ a = class extends Bar {
 ( 1 || 2 );
 ( !1 );
 
+// Nullish coalescing (ES2020)
+( a ?? 1 );
+
 // Assignment
 ( a = 1 );
 ( a += 1 );
diff --git a/tests/syntax-highlighting/file.ts b/tests/syntax-highlighting/file.ts
index f902fa14..df6aa4d3 100644
--- a/tests/syntax-highlighting/file.ts
+++ b/tests/syntax-highlighting/file.ts
@@ -495,10 +495,6 @@ a = import . /* comment
 a = import // comment
 .meta.__dirname; // incorrectly highlighted
 
-// Nullish coalescing (stage 3 proposal)
-( obj ?? 'default value' );
-a = foo ?? 1, bar ?? 2;
-
 // Type arguments for function calls
 fn<string>();
 fn<string, number>();
@@ -1038,6 +1034,9 @@ a = class extends Bar {
 ( 1 || 2 );
 ( !1 );
 
+// Nullish coalescing (ES2020)
+( a ?? 1 );
+
 // Assignment
 ( a = 1 );
 ( a += 1 );
diff --git a/tests/syntax-highlighting/file.tsx b/tests/syntax-highlighting/file.tsx
index cd515d92..a71d431d 100644
--- a/tests/syntax-highlighting/file.tsx
+++ b/tests/syntax-highlighting/file.tsx
@@ -601,10 +601,6 @@ a = import . /* comment
 a = import // comment
 .meta.__dirname; // incorrectly highlighted
 
-// Nullish coalescing (stage 3 proposal)
-( obj ?? 'default value' );
-a = foo ?? 1, bar ?? 2;
-
 // Type arguments for function calls
 fn<string>();
 fn<string, number>();
@@ -1146,6 +1142,9 @@ a = class extends Bar {
 ( 1 || 2 );
 ( !1 );
 
+// Nullish coalescing (ES2020)
+( a ?? 1 );
+
 // Assignment
 ( a = 1 );
 ( a += 1 );


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]