[gtksourceview] typescript.lang: missing keywords; add test file



commit 0dde9e254f1f4911ef1d67c935414a0900bbc869
Author: Nuno Martins <nunocastromartins protonmail com>
Date:   Thu Sep 26 22:21:54 2019 +0000

    typescript.lang: missing keywords; add test file
    
    - Adds missing keywords and basic type to the TS lang file.
    - Adds TS utility types.
    - Adds TS test file.

 data/language-specs/typescript.lang | 24 +++++++++++
 tests/syntax-highlighting/file.ts   | 85 +++++++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)
---
diff --git a/data/language-specs/typescript.lang b/data/language-specs/typescript.lang
index 917cb1a1..650ffd3e 100644
--- a/data/language-specs/typescript.lang
+++ b/data/language-specs/typescript.lang
@@ -36,23 +36,30 @@
   <styles>
     <style id="keyword" name="Keyword" map-to="def:keyword"/>
     <style id="basic-type" name="Basic Data Type" map-to="def:type"/>
+    <style id="utility-type" name="Utility Type" map-to="def:function"/>
   </styles>
 
   <definitions>
     <!-- TS specific stuff (i.e. stuff which is not JS) -->
     <context id="ts-proper">
       <include>
+        <!-- From: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words -->
         <context id="keywords" style-ref="keyword">
+          <keyword>abstract</keyword>
           <keyword>declare</keyword>
           <keyword>enum</keyword>
           <keyword>implements</keyword>
+          <keyword>infer</keyword>
           <keyword>interface</keyword>
+          <keyword>is</keyword>
+          <keyword>keyof</keyword>
           <keyword>module</keyword>
           <keyword>namespace</keyword>
           <keyword>package</keyword>
           <keyword>private</keyword>
           <keyword>protected</keyword>
           <keyword>public</keyword>
+          <keyword>readonly</keyword>
           <keyword>type</keyword>
         </context>
 
@@ -65,8 +72,25 @@
           <keyword>number</keyword>
           <keyword>object</keyword>
           <keyword>string</keyword>
+          <keyword>symbol</keyword>
           <keyword>unknown</keyword>
         </context>
+
+        <!-- From: https://www.typescriptlang.org/docs/handbook/utility-types.html -->
+        <context id="utility-types" style-ref="utility-type">
+          <keyword>Exclude</keyword>
+          <keyword>Extract</keyword>
+          <keyword>InstanceType</keyword>
+          <keyword>NonNullable</keyword>
+          <keyword>Omit</keyword>
+          <keyword>Partial</keyword>
+          <keyword>Pick</keyword>
+          <keyword>Readonly</keyword>
+          <keyword>Record</keyword>
+          <keyword>Required</keyword>
+          <keyword>ReturnType</keyword>
+          <keyword>ThisType</keyword>
+        </context>
       </include>
     </context>
 
diff --git a/tests/syntax-highlighting/file.ts b/tests/syntax-highlighting/file.ts
new file mode 100644
index 00000000..7a2044c1
--- /dev/null
+++ b/tests/syntax-highlighting/file.ts
@@ -0,0 +1,85 @@
+// Declarations
+declare var v: any;
+
+// Namespaces
+namespace N {}
+
+// Modules
+declare module '*.txt' {
+  export const txt: string;
+}
+
+// Types
+let num: number = 1;
+let str: string = 'str';
+let bool: boolean = true;
+let obj: object = {};
+let sym: symbol = Symbol();
+let something: any;
+let dunno: unknown;
+let none: null = null;
+let undef: undefined = undefined;
+// Void type
+function nothing(): void {
+  return;
+}
+// Never type
+function err(): never {
+  throw new Error();
+}
+
+// Custom types
+type T = Array<string | number>;
+type Keys = keyof {a: number; b: number};
+type Inferred<T> = T extends {a: infer U; b: infer U} ? U : never;
+
+// Utility types
+let part: Partial<{a: number; b: number}>;
+let ro: Readonly<string[]>;
+let rec: Record<string, any>;
+let pick: Pick<{a: number; b: number}, 'a'>;
+let omit: Omit<{a: number; b: number}, 'b'>;
+let exc: Exclude<'a' | 'b' | 'c', 'a'>;
+let ext: Extract<'a' | 'b' | 'c', 'a' | 'f'>;
+let nonNull: NonNullable<string | null>;
+let retT: ReturnType<() => string>;
+let inst: InstanceType<typeof Number>;
+let req: Required<{a?: number; b?: string}>;
+let thisT: ThisType<any>;
+
+// Interfaces
+interface I {
+  prop: T;
+}
+interface II extends I {
+  readonly r: string;
+}
+
+// Classes
+abstract class C implements II {
+  prop: T;
+  readonly r: string;
+
+  public pub: number;
+  protected prot: number;
+  private priv: number;
+
+  constructor(private priv2: string) {}
+
+  public abstract abst(): void;
+}
+
+// Enums
+enum Dir {
+  Up = 1,
+  Down,
+}
+const enum E {
+  Yes = 1,
+  No = Yes - 1,
+}
+
+// Type guards
+function isNumber(n: any): n is number {
+  return typeof n === 'number';
+}


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