[gtksourceview: 1/2] javascript.lang: Fix highlighting for reserved word property names



commit 91e33c6c8a1254734f098bbcd66c3470e4b49df9
Author: Jeffery To <jeffery to gmail com>
Date:   Sat Jan 18 23:15:54 2020 +0800

    javascript.lang: Fix highlighting for reserved word property names
    
    Reserved words (extends, class, etc.) are allowed as property names of
    objects, but property accessors (obj.extends) were highlighted as
    errors. This fixes this incorrect highlighting.

 data/language-specs/javascript-expressions.lang |  4 ++--
 data/language-specs/javascript.lang             | 26 ++++++++++++++++++-------
 tests/syntax-highlighting/file.j                |  2 +-
 tests/syntax-highlighting/file.js               |  2 +-
 tests/syntax-highlighting/file.jsx              |  2 +-
 tests/syntax-highlighting/file.ts               |  2 +-
 tests/syntax-highlighting/file.tsx              |  2 +-
 7 files changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/data/language-specs/javascript-expressions.lang b/data/language-specs/javascript-expressions.lang
index 5f869b3e..533cc1b5 100644
--- a/data/language-specs/javascript-expressions.lang
+++ b/data/language-specs/javascript-expressions.lang
@@ -303,7 +303,7 @@
             <context id="_dot-property-accessor-content">
               <include>
                 <context ref="js-val:properties-methods"/>
-                <context ref="js:identifier"/>
+                <context ref="js:identifier-name"/>
               </include>
             </context> <!-- /_dot-property-accessor-content -->
 
@@ -342,7 +342,7 @@
                      this context will end early for other cases
                 -->
                 <context ref="js-val:properties-methods"/>
-                <context ref="js:identifier"/>
+                <context ref="js:identifier-name"/>
               </include>
             </context> <!-- /_optional-chain-content -->
 
diff --git a/data/language-specs/javascript.lang b/data/language-specs/javascript.lang
index 170ccfec..4739ad3b 100644
--- a/data/language-specs/javascript.lang
+++ b/data/language-specs/javascript.lang
@@ -489,7 +489,13 @@
       <match>\%{identifier}</match>
     </context> <!-- /_identifier-names -->
 
-    <context id="choice-identifier-name" end-parent="true">
+    <context id="_identifier-name-content">
+      <include>
+        <context ref="_identifier-names"/>
+      </include>
+    </context> <!-- /_identifier-name-content -->
+
+    <context id="identifier-name" once-only="true">
       <start>(?=\%{identifier-start})</start>
       <end>\%{def:always-match}</end>
       <include>
@@ -497,13 +503,19 @@
         <!-- no comments here -->
         <!-- do not extend the context by matching comments or
              embedded-lang-hooks, which may lead to multiple identifiers -->
+        <context ref="_identifier-name-content"/>
+      </include>
+    </context> <!-- /choice-identifier-name -->
 
-        <context id="_identifier-name-content">
-          <include>
-            <context ref="_identifier-names"/>
-          </include>
-        </context> <!-- /_identifier-name-content -->
-
+    <context id="choice-identifier-name" end-parent="true">
+      <start>(?=\%{identifier-start})</start>
+      <end>\%{def:always-match}</end>
+      <include>
+        <!-- no embedded-lang-hooks here -->
+        <!-- no comments here -->
+        <!-- do not extend the context by matching comments or
+             embedded-lang-hooks, which may lead to multiple identifiers -->
+        <context ref="_identifier-name-content"/>
       </include>
     </context> <!-- /choice-identifier-name -->
 
diff --git a/tests/syntax-highlighting/file.j b/tests/syntax-highlighting/file.j
index 092b08b5..1c639485 100644
--- a/tests/syntax-highlighting/file.j
+++ b/tests/syntax-highlighting/file.j
@@ -777,7 +777,7 @@ a = class extends Bar {
 arr.length;
 obj
     . prototype
-    . constructor;
+    . extends;
 
 // Bracket notation
 arr['length'];
diff --git a/tests/syntax-highlighting/file.js b/tests/syntax-highlighting/file.js
index fb71e151..36657c62 100644
--- a/tests/syntax-highlighting/file.js
+++ b/tests/syntax-highlighting/file.js
@@ -476,7 +476,7 @@ a = class extends Bar {
 arr.length;
 obj
     . prototype
-    . constructor;
+    . extends;
 
 // Bracket notation
 arr['length'];
diff --git a/tests/syntax-highlighting/file.jsx b/tests/syntax-highlighting/file.jsx
index 29a8fe07..6da543f5 100644
--- a/tests/syntax-highlighting/file.jsx
+++ b/tests/syntax-highlighting/file.jsx
@@ -533,7 +533,7 @@ a = class extends Bar {
 arr.length;
 obj
     . prototype
-    . constructor;
+    . extends;
 
 // Bracket notation
 arr['length'];
diff --git a/tests/syntax-highlighting/file.ts b/tests/syntax-highlighting/file.ts
index df6aa4d3..b2bf3d52 100644
--- a/tests/syntax-highlighting/file.ts
+++ b/tests/syntax-highlighting/file.ts
@@ -1070,7 +1070,7 @@ a = class extends Bar {
 arr.length;
 obj
     . prototype
-    . constructor;
+    . extends;
 
 // Bracket notation
 arr['length'];
diff --git a/tests/syntax-highlighting/file.tsx b/tests/syntax-highlighting/file.tsx
index a71d431d..2ed8a485 100644
--- a/tests/syntax-highlighting/file.tsx
+++ b/tests/syntax-highlighting/file.tsx
@@ -1178,7 +1178,7 @@ a = class extends Bar {
 arr.length;
 obj
     . prototype
-    . constructor;
+    . extends;
 
 // Bracket notation
 arr['length'];


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