[gtksourceview: 10/14] typescript.lang: Add highlighting for private fields (stage 3 proposal)
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview: 10/14] typescript.lang: Add highlighting for private fields (stage 3 proposal)
- Date: Thu, 11 Jun 2020 17:27:08 +0000 (UTC)
commit b4cab0a400ff7ec7eab4ba5c346a6d0f8d9030bc
Author: Jeffery To <jeffery to gmail com>
Date: Mon Jun 8 04:18:17 2020 +0800
typescript.lang: Add highlighting for private fields (stage 3 proposal)
Support for private fields was added in TypeScript 3.8.
data/language-specs/typescript-js-expressions.lang | 16 +++++++++++++
.../typescript-js-functions-classes.lang | 22 +++++++++++++++++
data/language-specs/typescript.lang | 28 ++++++++++++++++++++++
tests/syntax-highlighting/file.ts | 20 ++++++++++++++--
tests/syntax-highlighting/file.tsx | 20 ++++++++++++++--
5 files changed, 102 insertions(+), 4 deletions(-)
---
diff --git a/data/language-specs/typescript-js-expressions.lang
b/data/language-specs/typescript-js-expressions.lang
index ff98e8b8..ba4d12f5 100644
--- a/data/language-specs/typescript-js-expressions.lang
+++ b/data/language-specs/typescript-js-expressions.lang
@@ -140,6 +140,22 @@
<!-- # Post-primary expression -->
+ <!-- replaces js-expr:_dot-property-accessor-content -->
+ <context id="dot-property-accessor-content">
+ <include>
+ <context ref="typescript:choice-private-identifier"/>
+ <context ref="js-expr:_dot-property-accessor-content" original="true"/>
+ </include>
+ </context> <!-- /dot-property-accessor-content -->
+
+ <!-- replaces js-expr:_optional-chain-content -->
+ <context id="optional-chain-content">
+ <include>
+ <context ref="typescript:choice-private-identifier"/>
+ <context ref="js-expr:_optional-chain-content" original="true"/>
+ </include>
+ </context> <!-- /optional-chain-content -->
+
<!-- replaces js-expr:_post-primary-expression -->
<context id="post-primary-expression">
<include>
diff --git a/data/language-specs/typescript-js-functions-classes.lang
b/data/language-specs/typescript-js-functions-classes.lang
index 3fa49727..8147d022 100644
--- a/data/language-specs/typescript-js-functions-classes.lang
+++ b/data/language-specs/typescript-js-functions-classes.lang
@@ -251,6 +251,25 @@
</include>
</context> <!-- /_choice-class-body-index-member -->
+ <context id="_choice-class-body-private-field" end-parent="true">
+ <start>(?=#\%{js:identifier-start})</start>
+ <end>;</end>
+ <include>
+ <context ref="js:comments"/>
+
+ <context id="_class-body-private-field-content">
+ <include>
+ <context ref="typescript:ordered-private-identifier"/>
+ <context ref="typescript:ordered-optional-modifier"/>
+ <context ref="typescript:ordered-definite-assignment-assertion"/>
+ <context ref="typescript:ordered-type-annotation"/>
+ <context ref="js:ordered-default-value-assignment"/>
+ </include>
+ </context> <!-- /_class-body-private-field-content -->
+
+ </include>
+ </context> <!-- /_choice-class-body-private-field -->
+
<context id="_class-body-method-parameters-list" once-only="true">
<start>\(</start>
<end>\)</end>
@@ -401,6 +420,8 @@
index members can only be modified with "readonly"
+ private fields can only be modified with "readonly"
+
cannot have abstract generators: abstract *generator()
https://github.com/Microsoft/TypeScript/issues/25710
@@ -421,6 +442,7 @@
<context ref="_ordered-class-body-readonly-property-modifier"/>
<context ref="_choice-class-body-index-member"/>
+ <context ref="_choice-class-body-private-field"/>
<context ref="_choice-class-body-method-keyword-method-definition"/>
<context ref="js-fn:ordered-property-accessor-keyword"/>
diff --git a/data/language-specs/typescript.lang b/data/language-specs/typescript.lang
index eec0e772..971589fe 100644
--- a/data/language-specs/typescript.lang
+++ b/data/language-specs/typescript.lang
@@ -365,6 +365,32 @@
</include>
</context> <!-- /ordered-namespace-name -->
+ <!-- ## Private identifier (stage 3 proposal)
+
+ #identifier
+ -->
+
+ <!-- <PrivateIdentifier> -->
+ <context id="choice-private-identifier" end-parent="true">
+ <start>#(?=\%{js:identifier-start})</start>
+ <end>\%{def:always-match}</end>
+ <include>
+ <context sub-pattern="0" where="start" style-ref="js:identifier"/>
+ <!-- no comments here -->
+ <!-- do not extend the context by matching comments, which may
+ lead to multiple identifiers -->
+ <context ref="js:_identifier-name-content"/>
+ </include>
+ </context> <!-- /choice-private-identifier -->
+
+ <context id="ordered-private-identifier" once-only="true">
+ <start>\%{js:before-next-token}</start>
+ <end>\%{js:before-next-token}</end>
+ <include>
+ <context ref="choice-private-identifier"/>
+ </include>
+ </context> <!-- /ordered-private-identifier -->
+
<!-- ## Constructor modifier -->
<context id="constructor-modifier" style-ref="type-keyword" once-only="true">
@@ -874,6 +900,8 @@
<!-- ### Post-primary expression -->
+ <replace id="js-expr:_dot-property-accessor-content"
ref="typescript-js-expr:dot-property-accessor-content"/>
+ <replace id="js-expr:_optional-chain-content" ref="typescript-js-expr:optional-chain-content"/>
<replace id="js-expr:_post-primary-expression" ref="typescript-js-expr:post-primary-expression"/>
<!-- ### Pre-LHS expression -->
diff --git a/tests/syntax-highlighting/file.ts b/tests/syntax-highlighting/file.ts
index ff86f798..57ddff95 100644
--- a/tests/syntax-highlighting/file.ts
+++ b/tests/syntax-highlighting/file.ts
@@ -387,7 +387,7 @@ type Container<T> = { value: T };
/* Literals */
-// Numeric separators (stage 2 proposal)
+// Numeric separators (stage 3 proposal)
let decimal = 1_000_000;
let binary_integer = 0b1100_0011_1101_0001;
let octal_integer = 0o123_456_700;
@@ -470,7 +470,7 @@ a = class extends Super implements Super.Sub {};
class MyClass implements Super.Sub {}
class MyClass extends Super implements Super.Sub {}
-// Class properties
+// Class properties (stage 3 proposal)
a = class {
property;
property = 1;
@@ -494,6 +494,13 @@ a = class {
[index: number]: string;
};
+// Private fields (stage 3 proposal)
+a = class {
+ #privateprop;
+ #privateprop: string = '';
+ setPrivateProp(s: string) { this.#privateprop = s; }
+};
+
// Accessibility modifiers for properties / methods
a = class {
public property;
@@ -632,6 +639,15 @@ a = class {
abstract [prop: string]: any;
declare [prop: string]: any;
};
+// Modifiers other than "readonly" do not apply to private fields
+a = class {
+ public #privateprop;
+ protected #privateprop;
+ private #privateprop;
+ static #privateprop;
+ abstract #privateprop;
+ declare #privateprop;
+};
/* Expression */
diff --git a/tests/syntax-highlighting/file.tsx b/tests/syntax-highlighting/file.tsx
index 7d9589c2..e8eb8e91 100644
--- a/tests/syntax-highlighting/file.tsx
+++ b/tests/syntax-highlighting/file.tsx
@@ -493,7 +493,7 @@ type Container<T> = { value: T };
/* Literals */
-// Numeric separators (stage 2 proposal)
+// Numeric separators (stage 3 proposal)
let decimal = 1_000_000;
let binary_integer = 0b1100_0011_1101_0001;
let octal_integer = 0o123_456_700;
@@ -576,7 +576,7 @@ a = class extends Super implements Super.Sub {};
class MyClass implements Super.Sub {}
class MyClass extends Super implements Super.Sub {}
-// Class properties
+// Class properties (stage 3 proposal)
a = class {
property;
property = 1;
@@ -600,6 +600,13 @@ a = class {
[index: number]: string;
};
+// Private fields (stage 3 proposal)
+a = class {
+ #privateprop;
+ #privateprop: string = '';
+ setPrivateProp(s: string) { this.#privateprop = s; }
+};
+
// Accessibility modifiers for properties / methods
a = class {
public property;
@@ -738,6 +745,15 @@ a = class {
abstract [prop: string]: any;
declare [prop: string]: any;
};
+// Modifiers other than "readonly" do not apply to private fields
+a = class {
+ public #privateprop;
+ protected #privateprop;
+ private #privateprop;
+ static #privateprop;
+ abstract #privateprop;
+ declare #privateprop;
+};
/* Expression */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]