[gtksourceview: 1/14] javascript.lang (and family): Minor tweaks
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview: 1/14] javascript.lang (and family): Minor tweaks
- Date: Thu, 11 Jun 2020 17:26:23 +0000 (UTC)
commit b8447767aae4d0b59b42800728278185b4263e0c
Author: Jeffery To <jeffery to gmail com>
Date: Wed Jun 3 17:34:55 2020 +0800
javascript.lang (and family): Minor tweaks
* Remove escapes (backslash) for literal braces / curly brackets in
regexes
* Add example of export import alias for TypeScript
* Standardize on "incorrectly highlighted" in test files
* Reformat some "incorrectly highlighted" sections in test files
* Clarified const assertions in TypeScript test files
data/language-specs/javascript-literals.lang | 8 +++----
data/language-specs/javascript-modules.lang | 4 ++--
data/language-specs/javascript.lang | 3 ++-
data/language-specs/jsdoc.lang | 8 +++----
data/language-specs/typescript.lang | 2 +-
tests/syntax-highlighting/file.j | 14 +++++++++----
tests/syntax-highlighting/file.js | 14 +++++++++----
tests/syntax-highlighting/file.jsx | 14 +++++++++----
tests/syntax-highlighting/file.ts | 29 +++++++++++++++++---------
tests/syntax-highlighting/file.tsx | 31 ++++++++++++++++++----------
10 files changed, 82 insertions(+), 45 deletions(-)
---
diff --git a/data/language-specs/javascript-literals.lang b/data/language-specs/javascript-literals.lang
index 5dd13fcc..e52ff891 100644
--- a/data/language-specs/javascript-literals.lang
+++ b/data/language-specs/javascript-literals.lang
@@ -435,7 +435,7 @@
<!-- ES2018 -->
<context id="_unicode-property-escapes" style-ref="js:escape">
<match extended="true">
- \\ [pP] \{ (?: [a-zA-Z_]+ = )? [a-zA-Z0-9_]+ \}
+ \\ [pP] { (?: [a-zA-Z_]+ = )? [a-zA-Z0-9_]+ }
</match>
</context> <!-- /_unicode-property-escapes -->
@@ -523,7 +523,7 @@
<context id="_template-head" style-ref="js:template-literal" once-only="true">
<start>(?<=`)</start>
- <end>(?=`|\$\{)</end>
+ <end>(?=`|\${)</end>
<include>
<context ref="js:embedded-lang-hooks"/>
<!-- no comments here -->
@@ -535,7 +535,7 @@
<context id="_template-substitution-tails" style-ref="js:template-literal">
<start>(?<=})</start>
- <end>(?=`|\$\{)</end>
+ <end>(?=`|\${)</end>
<include>
<context ref="js:embedded-lang-hooks"/>
<!-- no comments here -->
@@ -544,7 +544,7 @@
</context> <!-- /_template-substitution-tails -->
<context id="_template-placeholders">
- <start>\$\{</start>
+ <start>\${</start>
<end>}</end>
<include>
<context sub-pattern="0" where="start" style-ref="js:template-placeholder"/>
diff --git a/data/language-specs/javascript-modules.lang b/data/language-specs/javascript-modules.lang
index fe014372..cac548fa 100644
--- a/data/language-specs/javascript-modules.lang
+++ b/data/language-specs/javascript-modules.lang
@@ -234,7 +234,7 @@
-->
<context id="_choice-export-named" end-parent="true">
- <start>(?=\{)</start>
+ <start>(?={)</start>
<end>\%{js:statement-end}</end>
<include>
<context ref="js:embedded-lang-hooks"/>
@@ -321,7 +321,7 @@
-->
<context id="_choice-import-named" end-parent="true">
- <start>(?=\{)</start>
+ <start>(?={)</start>
<end>\%{js:statement-end}</end>
<include>
<context ref="js:embedded-lang-hooks"/>
diff --git a/data/language-specs/javascript.lang b/data/language-specs/javascript.lang
index add32910..503dc0ee 100644
--- a/data/language-specs/javascript.lang
+++ b/data/language-specs/javascript.lang
@@ -191,7 +191,7 @@
<!-- <UnicodeEscapeSequence> -->
<define-regex id="unicode-escape" extended="true">
- \\u (?: [0-9a-fA-F]{4} | \{ [0-9a-fA-F]{1,} \} )
+ \\u (?: [0-9a-fA-F]{4} | { [0-9a-fA-F]{1,} } )
</define-regex> <!-- /unicode-escape -->
<!-- <IdentifierStart> -->
@@ -313,6 +313,7 @@
</define-regex> <!-- /class-expression-keyword -->
<!-- ## Embedded lang hooks
+
a placeholder context where an embedding language (e.g. html)
can <replace>
-->
diff --git a/data/language-specs/jsdoc.lang b/data/language-specs/jsdoc.lang
index 1162e267..e9c03592 100644
--- a/data/language-specs/jsdoc.lang
+++ b/data/language-specs/jsdoc.lang
@@ -57,8 +57,8 @@
</context>
<context id="inline-tag" style-ref="inline-tag" end-at-line-end="true">
- <start>\{@</start>
- <end>\}</end>
+ <start>{@</start>
+ <end>}</end>
<include>
<context ref="embedded-lang-hooks"/>
<context ref="escape"/>
@@ -67,8 +67,8 @@
</context>
<context id="type" style-ref="type" end-at-line-end="true">
- <start>\{</start>
- <end>\}</end>
+ <start>{</start>
+ <end>}</end>
<include>
<context ref="embedded-lang-hooks"/>
<context ref="escape"/>
diff --git a/data/language-specs/typescript.lang b/data/language-specs/typescript.lang
index e3adb060..6ca558b8 100644
--- a/data/language-specs/typescript.lang
+++ b/data/language-specs/typescript.lang
@@ -127,7 +127,7 @@
\%{js:optional-whitespace-or-comments}
)?
\%{js:keyword-start} class \%{js:keyword-end}
- </define-regex> <!-- / -->
+ </define-regex> <!-- /class-expression-keyword -->
<context id="js-ordered-string" once-only="true">
<start>\%{js:before-next-token}</start>
diff --git a/tests/syntax-highlighting/file.j b/tests/syntax-highlighting/file.j
index 89f0dd72..3b96edba 100644
--- a/tests/syntax-highlighting/file.j
+++ b/tests/syntax-highlighting/file.j
@@ -530,18 +530,24 @@ new.target;
new . /* comment */ target;
super;
this;
+// incorrectly highlighted
+new .
+target;
new . /* comment
-*/ target; // not correctly highlighted
+*/ target;
new // comment
-.target; // not correctly highlighted
+.target;
// function keywords
import(); // ES2020
import /* comment */ (); // ES2020
+// incorrectly highlighted (though it may appear correct)
+import
+();
import /* comment
-*/ (); // not correctly highlighted (though it may appear correct)
+*/ ();
import // comment
-(); // not correctly highlighted (though it may appear correct)
+();
// properties (subset)
array.length;
diff --git a/tests/syntax-highlighting/file.js b/tests/syntax-highlighting/file.js
index 4a238bcf..e3f2de2d 100644
--- a/tests/syntax-highlighting/file.js
+++ b/tests/syntax-highlighting/file.js
@@ -229,18 +229,24 @@ new.target;
new . /* comment */ target;
super;
this;
+// incorrectly highlighted
+new .
+target;
new . /* comment
-*/ target; // not correctly highlighted
+*/ target;
new // comment
-.target; // not correctly highlighted
+.target;
// function keywords
import(); // ES2020
import /* comment */ (); // ES2020
+// incorrectly highlighted (though it may appear correct)
+import
+();
import /* comment
-*/ (); // not correctly highlighted (though it may appear correct)
+*/ ();
import // comment
-(); // not correctly highlighted (though it may appear correct)
+();
// properties (subset)
array.length;
diff --git a/tests/syntax-highlighting/file.jsx b/tests/syntax-highlighting/file.jsx
index bd59d6b0..5da9cc5a 100644
--- a/tests/syntax-highlighting/file.jsx
+++ b/tests/syntax-highlighting/file.jsx
@@ -286,18 +286,24 @@ new.target;
new . /* comment */ target;
super;
this;
+// incorrectly highlighted
+new .
+target;
new . /* comment
-*/ target; // not correctly highlighted
+*/ target;
new // comment
-.target; // not correctly highlighted
+.target;
// function keywords
import(); // ES2020
import /* comment */ (); // ES2020
+// incorrectly highlighted (though it may appear correct)
+import
+();
import /* comment
-*/ (); // not correctly highlighted (though it may appear correct)
+*/ ();
import // comment
-(); // not correctly highlighted (though it may appear correct)
+();
// properties (subset)
array.length;
diff --git a/tests/syntax-highlighting/file.ts b/tests/syntax-highlighting/file.ts
index 199aac48..47887693 100644
--- a/tests/syntax-highlighting/file.ts
+++ b/tests/syntax-highlighting/file.ts
@@ -171,7 +171,7 @@ let a: (this: void) => void;
let a: (this /* comment */ : void) => void;
let a: (...string
: string[]) => void;
-// Not correctly highlighted
+// Incorrectly highlighted
let a: (string
: string) => void;
let a: (this /* comment
@@ -204,7 +204,7 @@ a = <T, K extends keyof T>(x) => x;
// Type assertion
a = <string>obj;
-a = <const>obj;
+a = <const>"abc"; // const assertion
/*
@@ -229,7 +229,7 @@ let a: string;
/* as operator (type assertion / cast) */
( obj as string );
-( obj as const );
+( "abc" as const ); // const assertion
// Non-null assertion operator (post-fix !)
@@ -499,7 +499,7 @@ a = import // comment
fn<string>();
fn<string, number>();
fn < string > /* comment */ ();
-// Not correctly highlighted (interpreted as less than / equal than)
+// Incorrectly highlighted (interpreted as less than / equal than)
fn<string
();
fn<string>
@@ -513,7 +513,7 @@ fn<string> // comment
myTag<string>`Template literal`;
myTag<string, number>`Template literal`;
myTag < string > /* comment */ `Template literal`;
-// Not correctly highlighted (interpreted as less than / equal than)
+// Incorrectly highlighted (interpreted as less than / equal than)
myTag<string
`Template literal`;
myTag<string>
@@ -525,7 +525,7 @@ myTag<string> // comment
// Type assertion
a = <string>obj;
-a = <const>obj;
+a = <const>"abc"; // const assertion
/* Export / import declaration */
@@ -550,6 +550,9 @@ export declare namespace Super.Sub {}
export enum Color { Red, Green, Blue }
export const enum Num { One = 1, Two, Three }
+// Export import alias
+export import shortname = Long.Namespace.Name;
+
// Export interface declaration
export interface MyObj {}
export interface Square<T> extends Shape, PenStroke<number> {}
@@ -823,18 +826,24 @@ new.target;
new . /* comment */ target;
super;
this;
+// incorrectly highlighted
+new .
+target;
new . /* comment
-*/ target; // not correctly highlighted
+*/ target;
new // comment
-.target; // not correctly highlighted
+.target;
// function keywords
import(); // ES2020
import /* comment */ (); // ES2020
+// incorrectly highlighted (though it may appear correct)
+import
+();
import /* comment
-*/ (); // not correctly highlighted (though it may appear correct)
+*/ ();
import // comment
-(); // not correctly highlighted (though it may appear correct)
+();
// properties (subset)
array.length;
diff --git a/tests/syntax-highlighting/file.tsx b/tests/syntax-highlighting/file.tsx
index b63955c7..caab96c1 100644
--- a/tests/syntax-highlighting/file.tsx
+++ b/tests/syntax-highlighting/file.tsx
@@ -23,7 +23,7 @@
a = <T extends any>(x: T) => x;
a = < T /* comment */ , U >(x: T, y: U) => x;
-// Not correctly highlighted (extra </T> added to close incorrect T elements)
+// Incorrectly highlighted (extra </T> added to close incorrect T elements)
a = <T
extends any>(x: T) => x;
</T>
@@ -275,7 +275,7 @@ let a: (this: void) => void;
let a: (this /* comment */ : void) => void;
let a: (...string
: string[]) => void;
-// Not correctly highlighted
+// Incorrectly highlighted
let a: (string
: string) => void;
let a: (this /* comment
@@ -309,7 +309,7 @@ a = <T, K extends keyof T>(x) => x;
// Type assertion
/* type assertions should be done using the "as" operator in typescript jsx
a = <string>obj;
-a = <const>obj;
+a = <const>"abc"; // const assertion
*/
@@ -335,7 +335,7 @@ let a: string;
/* as operator (type assertion / cast) */
( obj as string );
-( obj as const );
+( "abc" as const ); // const assertion
// Non-null assertion operator (post-fix !)
@@ -605,7 +605,7 @@ a = import // comment
fn<string>();
fn<string, number>();
fn < string > /* comment */ ();
-// Not correctly highlighted (interpreted as less than / equal than)
+// Incorrectly highlighted (interpreted as less than / equal than)
fn<string
();
fn<string>
@@ -619,7 +619,7 @@ fn<string> // comment
myTag<string>`Template literal`;
myTag<string, number>`Template literal`;
myTag < string > /* comment */ `Template literal`;
-// Not correctly highlighted (interpreted as less than / equal than)
+// Incorrectly highlighted (interpreted as less than / equal than)
myTag<string
`Template literal`;
myTag<string>
@@ -632,7 +632,7 @@ myTag<string> // comment
// Type assertion
/* type assertions should be done using the "as" operator in typescript jsx
a = <string>obj;
-a = <const>obj;
+a = <const>"abc"; // const assertion
*/
@@ -658,6 +658,9 @@ export declare namespace Super.Sub {}
export enum Color { Red, Green, Blue }
export const enum Num { One = 1, Two, Three }
+// Export import alias
+export import shortname = Long.Namespace.Name;
+
// Export interface declaration
export interface MyObj {}
export interface Square<T> extends Shape, PenStroke<number> {}
@@ -931,18 +934,24 @@ new.target;
new . /* comment */ target;
super;
this;
+// incorrectly highlighted
+new .
+target;
new . /* comment
-*/ target; // not correctly highlighted
+*/ target;
new // comment
-.target; // not correctly highlighted
+.target;
// function keywords
import(); // ES2020
import /* comment */ (); // ES2020
+// incorrectly highlighted (though it may appear correct)
+import
+();
import /* comment
-*/ (); // not correctly highlighted (though it may appear correct)
+*/ ();
import // comment
-(); // not correctly highlighted (though it may appear correct)
+();
// properties (subset)
array.length;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]