[gtksourceview/gtksourceview-4-6] javascript.lang: Fix dot property accessor context not ended properly
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gtksourceview-4-6] javascript.lang: Fix dot property accessor context not ended properly
- Date: Wed, 8 Apr 2020 17:40:04 +0000 (UTC)
commit c15319811321bb72e222f41db21208bf754ecb80
Author: Jeffery To <jeffery to gmail com>
Date: Sun Apr 5 19:37:44 2020 +0800
javascript.lang: Fix dot property accessor context not ended properly
A similar issue also exists for optional chaining (e.g. Math?.PI).
Fixes #120.
data/language-specs/javascript-expressions.lang | 39 ++++++++++++++++++++-----
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 ++
6 files changed, 41 insertions(+), 8 deletions(-)
---
diff --git a/data/language-specs/javascript-expressions.lang b/data/language-specs/javascript-expressions.lang
index 533cc1b5..dd184825 100644
--- a/data/language-specs/javascript-expressions.lang
+++ b/data/language-specs/javascript-expressions.lang
@@ -192,13 +192,15 @@
<!-- 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 -->
+ embedded-lang-hooks, which may lead to multiple
+ identifiers -->
<context id="_primary-expression-identifier-content">
<include>
- <!-- technically these would be choices, but it would be very
- difficult to turn large keyword contexts into container
- contexts with end-parent="true" -->
+ <!-- technically these would be choices, but it
+ would be very difficult to turn large keyword
+ contexts into container contexts with
+ end-parent="true" -->
<context ref="js-lit:null-value"/>
<context ref="js-lit:boolean"/>
<context ref="js-val:global-values"/>
@@ -288,6 +290,29 @@
func?.()
-->
+ <context id="_choice-property-identifier" end-parent="true">
+ <start>(?=\%{js: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 id="_property-identifier-content">
+ <include>
+ <!-- technically these would be choices, but it would be
+ very difficult to turn large keyword contexts into
+ container contexts with end-parent="true" -->
+ <context ref="js-val:properties-methods"/>
+ <context ref="js:identifier-name"/>
+ </include>
+ </context> <!-- /_property-identifier-content -->
+
+ </include>
+ </context> <!-- /_choice-property-identifier -->
+
<context id="_post-primary-expression">
<include>
<context ref="js:embedded-lang-hooks"/>
@@ -302,8 +327,7 @@
<context id="_dot-property-accessor-content">
<include>
- <context ref="js-val:properties-methods"/>
- <context ref="js:identifier-name"/>
+ <context ref="_choice-property-identifier"/>
</include>
</context> <!-- /_dot-property-accessor-content -->
@@ -341,8 +365,7 @@
<!-- only match dot-property accessor content here
this context will end early for other cases
-->
- <context ref="js-val:properties-methods"/>
- <context ref="js:identifier-name"/>
+ <context ref="_choice-property-identifier"/>
</include>
</context> <!-- /_optional-chain-content -->
diff --git a/tests/syntax-highlighting/file.j b/tests/syntax-highlighting/file.j
index 0cef88ab..8c95c70c 100644
--- a/tests/syntax-highlighting/file.j
+++ b/tests/syntax-highlighting/file.j
@@ -802,6 +802,8 @@ arr.length;
obj
. prototype
. extends;
+const pi = Math.PI
+const num = 0
// Bracket notation
arr['length'];
diff --git a/tests/syntax-highlighting/file.js b/tests/syntax-highlighting/file.js
index 039c1dad..f3a2ec69 100644
--- a/tests/syntax-highlighting/file.js
+++ b/tests/syntax-highlighting/file.js
@@ -501,6 +501,8 @@ arr.length;
obj
. prototype
. extends;
+const pi = Math.PI
+const num = 0
// Bracket notation
arr['length'];
diff --git a/tests/syntax-highlighting/file.jsx b/tests/syntax-highlighting/file.jsx
index 595f7969..a774d169 100644
--- a/tests/syntax-highlighting/file.jsx
+++ b/tests/syntax-highlighting/file.jsx
@@ -558,6 +558,8 @@ arr.length;
obj
. prototype
. extends;
+const pi = Math.PI
+const num = 0
// Bracket notation
arr['length'];
diff --git a/tests/syntax-highlighting/file.ts b/tests/syntax-highlighting/file.ts
index 157d1f5c..548cd73f 100644
--- a/tests/syntax-highlighting/file.ts
+++ b/tests/syntax-highlighting/file.ts
@@ -1095,6 +1095,8 @@ arr.length;
obj
. prototype
. extends;
+const pi = Math.PI
+const num = 0
// Bracket notation
arr['length'];
diff --git a/tests/syntax-highlighting/file.tsx b/tests/syntax-highlighting/file.tsx
index 9507ea1f..b5bf97a1 100644
--- a/tests/syntax-highlighting/file.tsx
+++ b/tests/syntax-highlighting/file.tsx
@@ -1203,6 +1203,8 @@ arr.length;
obj
. prototype
. extends;
+const pi = Math.PI
+const num = 0
// Bracket notation
arr['length'];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]