Warning, /frameworks/syntax-highlighting/autotests/folding/test.ts.fold is written in an unsupported language. File is not indexed.

0001 /// <reference types="node" />
0002 
0003 // TypeScript Test
0004 
0005 class Student <beginfold id='1'>{</beginfold id='1'>
0006     fullName: string;
0007     constructor(public firstName: string, public middleInitial: string, public lastName: string) <beginfold id='1'>{</beginfold id='1'>
0008         this.fullName = firstName + " " + middleInitial + " " + lastName;
0009     <endfold id='1'>}</endfold id='1'>
0010 <endfold id='1'>}</endfold id='1'>
0011 
0012 interface Person <beginfold id='1'>{</beginfold id='1'>
0013     firstName: string;
0014     lastName: string;
0015 <endfold id='1'>}</endfold id='1'>
0016 
0017 function greeter(person : Person) <beginfold id='1'>{</beginfold id='1'>
0018     return "Hello, " + person.firstName + " " + person.lastName;
0019 <endfold id='1'>}</endfold id='1'>
0020 
0021 let user = new Student("Jane", "M.", "User");
0022 
0023 // Built-in
0024 document.body.innerHTML = greeter(user); to
0025 JSON.stringify()
0026 console.log("Hello world");
0027 const os = require('os');
0028 Math.LOG10E;
0029 Number.MAX_SAFE_INTEGER;
0030 String.raw<beginfold id='2'>`</beginfold id='2'>raw text \.\n${}<endfold id='2'>`</endfold id='2'>
0031 
0032 import http = require<beginfold id='3'>(</beginfold id='3'>"http"<endfold id='3'>)</endfold id='3'>;
0033 import path = require<beginfold id='3'>(</beginfold id='3'>"path"<endfold id='3'>)</endfold id='3'>;
0034 import URL = url.URL;
0035 import <beginfold id='1'>{</beginfold id='1'> Readable, Writable <endfold id='1'>}</endfold id='1'> from "stream";
0036 import <beginfold id='1'>{</beginfold id='1'> isBuffer, isString, isObject <endfold id='1'>}</endfold id='1'> from "util";
0037 
0038 const port = 8__88___8;
0039 const baseUrl = new URL(<beginfold id='4'>`</beginfold id='4'>http://localhost:${port}/<endfold id='4'>`</endfold id='4'>);
0040 const rootDir = path.dirname(__dirname);
0041 
0042 const defaultBrowser = os.platform() === "win32" ? "edge" : "chrome";
0043 let browser: "edge" | "chrome" | "none" = defaultBrowser;
0044 let grep: string | undefined;
0045 
0046 interface FileBasedTestConfiguration <beginfold id='1'>{</beginfold id='1'>
0047     <beginfold id='5'>[</beginfold id='5'>setting: string<endfold id='5'>]</endfold id='5'>: string;
0048 <endfold id='1'>}</endfold id='1'>
0049 
0050 function swapCase(s: string): string <beginfold id='1'>{</beginfold id='1'>
0051     return s.replace(/\w/g, (ch) => <beginfold id='1'>{</beginfold id='1'>
0052         const up = ch.toUpperCase();
0053         return ch === up ? ch.toLowerCase() : up;
0054     <endfold id='1'>}</endfold id='1'>);
0055 <endfold id='1'>}</endfold id='1'>
0056 
0057 for (var i in pieces) <beginfold id='1'>{</beginfold id='1'>
0058     switch (true) <beginfold id='1'>{</beginfold id='1'>
0059         case /^\"?Accession\"?/.test(pieces<beginfold id='5'>[</beginfold id='5'>i<endfold id='5'>]</endfold id='5'>):
0060             numeration<beginfold id='5'>[</beginfold id='5'>0<endfold id='5'>]</endfold id='5'> = i;
0061             break;
0062     <endfold id='1'>}</endfold id='1'>
0063 <endfold id='1'>}</endfold id='1'>
0064 
0065 const enum ResponseCode <beginfold id='1'>{</beginfold id='1'>
0066     Success = 200,
0067     BadRequest = 400
0068 <endfold id='1'>}</endfold id='1'>
0069 
0070 // Substitutions
0071 export function isInOpenInterval(start: number, end: number) <beginfold id='1'>{</beginfold id='1'>
0072     return tersible(a => a > start && a < end, () => <beginfold id='4'>`</beginfold id='4'>(${start}...${end})<endfold id='4'>`</endfold id='4'>)
0073 <endfold id='1'>}</endfold id='1'>
0074 const bar = <beginfold id='4'>`</beginfold id='4'>${x} ${y}<endfold id='4'>`</endfold id='4'>;
0075 
0076 // readonly
0077 function f1(mt: <beginfold id='5'>[</beginfold id='5'>number, number<endfold id='5'>]</endfold id='5'>, rt: readonly <beginfold id='5'>[</beginfold id='5'>number, number<endfold id='5'>]</endfold id='5'>) <beginfold id='1'>{</beginfold id='1'>
0078 <endfold id='1'>}</endfold id='1'>
0079 
0080 function f2(ma: string<beginfold id='5'>[</beginfold id='5'><endfold id='5'>]</endfold id='5'>, ra: readonly string<beginfold id='5'>[</beginfold id='5'><endfold id='5'>]</endfold id='5'>, mt: <beginfold id='5'>[</beginfold id='5'>string, string<endfold id='5'>]</endfold id='5'>, rt: readonly <beginfold id='5'>[</beginfold id='5'>string, string<endfold id='5'>]</endfold id='5'>) <beginfold id='1'>{</beginfold id='1'>
0081 <endfold id='1'>}</endfold id='1'>
0082 
0083 type ReadWrite<T> = <beginfold id='1'>{</beginfold id='1'> -readonly <beginfold id='5'>[</beginfold id='5'>P in keyof T<endfold id='5'>]</endfold id='5'> : T<beginfold id='5'>[</beginfold id='5'>P<endfold id='5'>]</endfold id='5'> <endfold id='1'>}</endfold id='1'>;
0084 
0085 // const assertion
0086 let obj = <beginfold id='1'>{</beginfold id='1'> x: 10, y: <beginfold id='5'>[</beginfold id='5'>20, 30<endfold id='5'>]</endfold id='5'>, z: <beginfold id='1'>{</beginfold id='1'> a: <beginfold id='1'>{</beginfold id='1'> b: 42 <endfold id='1'>}</endfold id='1'> <endfold id='1'>}</endfold id='1'> <endfold id='1'>}</endfold id='1'> as const;
0087 let r2 = <beginfold id='1'>{</beginfold id='1'> x: 20, y: 10 <endfold id='1'>}</endfold id='1'> as const;
0088 let r2 = <beginfold id='1'>{</beginfold id='1'>...p<endfold id='1'>}</endfold id='1'> as const;
0089 let p1 = <beginfold id='1'>{</beginfold id='1'> x: 10, y: 20 as const <endfold id='1'>}</endfold id='1'>;
0090 let p2 = <beginfold id='1'>{</beginfold id='1'> 10 as const, 'foo' as const <endfold id='1'>}</endfold id='1'>;
0091 
0092 // Definite assignment operator
0093 class Cl <beginfold id='1'>{</beginfold id='1'>
0094     one?: string;
0095     two!: string;
0096 <endfold id='1'>}</endfold id='1'>
0097 let x! = 1;
0098 
0099 // Function with multiple arguments
0100 const children = <beginfold id='5'>[</beginfold id='5'><endfold id='5'>]</endfold id='5'>.map<Set<Map<number, string>>>(element => <beginfold id='1'>{</beginfold id='1'>
0101     if (!this.identityProvider) <beginfold id='1'>{</beginfold id='1'>
0102         return element;
0103     <endfold id='1'>}</endfold id='1'>
0104     return element;
0105 <endfold id='1'>}</endfold id='1'>);
0106 
0107 // Numerics
0108 var a = 0xA;
0109 var b = 0b1;
0110 var c = 0o7;
0111 var d = 1.1E+3;
0112 var e = 1.E+3;
0113 var f = .1E+3;
0114 var g = 1E+3;
0115 var h = 1.1;
0116 var i = 1.;
0117 var j = .1;
0118 var k =  1;
0119 var l = 1__.e+3_22 | .2____e2 | 0o1_23 | 11__. ;
0120 
0121 // Bigint
0122 const binBig = 0b101n;
0123 const octBig = 0o567n;
0124 const hexBig = 0xC0Bn;
0125 const decBig = 123n;
0126 
0127 // Types
0128 let a: null = null;
0129 let b: number = 123;
0130 let c: number = 123.456;
0131 let d: string = <beginfold id='4'>`</beginfold id='4'>Geeks<endfold id='4'>`</endfold id='4'>;
0132 let e: undefined = undefined;
0133 let f: boolean = true;
0134 let g: number = 0b111001; // Binary
0135 let h: number = 0o436; // Octal
0136 let i: number = 0xadf0d; // Hexa-Decimal
0137 let j: bigint = 123n;
0138 
0139 const query = query<<beginfold id='5'>[</beginfold id='5'>number<endfold id='5'>]</endfold id='5'>, number>(<beginfold id='4'>`</beginfold id='4'>
0140         SELECT *
0141         FROM statistics
0142         WHERE unit_id = $1<endfold id='4'>`</endfold id='4'>)
0143 
0144 function runQuery() <beginfold id='1'>{</beginfold id='1'>
0145     const query = createQuery<<beginfold id='5'>[</beginfold id='5'>number<beginfold id='5'>[</beginfold id='5'><endfold id='5'>]</endfold id='5'><endfold id='5'>]</endfold id='5'>, Table<Columns>>(<beginfold id='4'>`</beginfold id='4'>
0146         some SQL here
0147     <endfold id='4'>`</endfold id='4'>)
0148     return database.execute(query)
0149 <endfold id='1'>}</endfold id='1'>
0150 
0151 aa: <sdf/> string ?<ssd/> string
0152  string // Don't highlight
0153 aa: string assa |
0154    string
0155    string ;
0156    string
0157 
0158 aa: <beginfold id='1'>{</beginfold id='1'> string
0159     string <endfold id='1'>}</endfold id='1'> // Don't highlight
0160 
0161 aa: <beginfold id='5'>[</beginfold id='5'> string
0162       string <endfold id='5'>]</endfold id='5'>
0163 aa: ( string
0164       string ) // Don't highlight
0165 aa: string <string>
0166 interface a <beginfold id='1'>{</beginfold id='1'>
0167     aa: <beginfold id='6'>/*</beginfold id='6'> comment
0168         <endfold id='6'>*/</endfold id='6'> string,
0169     bb: <beginfold id='6'>/*</beginfold id='6'> comment <endfold id='6'>*/</endfold id='6'>
0170         number,
0171     cc: // comment
0172         void,
0173     dd:
0174         any,
0175 <endfold id='1'>}</endfold id='1'>
0176 
0177 null, <<beginfold id='1'>{</beginfold id='1'><beginfold id='5'>[</beginfold id='5'>key<endfold id='5'>]</endfold id='5'>: () => any<endfold id='1'>}</endfold id='1'>> null
0178 null, <<beginfold id='1'>{</beginfold id='1'><beginfold id='5'>[</beginfold id='5'>key<endfold id='5'>]</endfold id='5'>: () =><beginfold id='1'>{</beginfold id='1'>a: number<endfold id='1'>}</endfold id='1'><endfold id='1'>}</endfold id='1'>> null
0179 
0180 // Correctly highlighting regular expressions
0181 dt = ((dt<beginfold id='5'>[</beginfold id='5'>0<endfold id='5'>]</endfold id='5'> * 1e9 + dt<beginfold id='5'>[</beginfold id='5'>1<endfold id='5'>]</endfold id='5'>) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms';
0182 (a<beginfold id='5'>[</beginfold id='5'>0<endfold id='5'>]</endfold id='5'> / 2) / (2)
0183 
0184 // Type guards
0185 function isNumber(x: any): x is number <beginfold id='1'>{</beginfold id='1'>
0186     return typeof x === "number";
0187 <endfold id='1'>}</endfold id='1'>
0188 
0189 // Conditional expressions (highlight keywords before ":")
0190 class C <beginfold id='1'>{</beginfold id='1'>
0191     w = () =>
0192         this.a() ? true : this.b() ? false : true;
0193     z = () =>
0194         this.b() ? hello : k;
0195 <endfold id='1'>}</endfold id='1'>
0196 
0197 function foo<T extends X>(arg: T): T extends B ? number : string <beginfold id='1'>{</beginfold id='1'>
0198   if (arg === "A") return <T extends B ? number : never>111;
0199   return <T extends B ? never : string>"returning a string";
0200 <endfold id='1'>}</endfold id='1'>
0201 
0202 let x = (foo === null || foo === undefined) ?
0203     undefined :
0204     foo.bar.baz();
0205 let y = (foo === null || foo === undefined) ? <beginfold id='6'>/*</beginfold id='6'> comment <endfold id='6'>*/</endfold id='6'> undefined :
0206     foo.bar.baz();
0207 
0208 // Operator ??
0209 let x = foo ?? bar();
0210 
0211 // Types and logical `&&` and `||` operators after `as` expression
0212 Date as any || null;
0213 
0214 //Assertions
0215 const assert: (value: unknown) => asserts value = value => <beginfold id='1'>{</beginfold id='1'><endfold id='1'>}</endfold id='1'>
0216 declare function assertIsString(value: unknown): asserts value is string;
0217 declare function assertIsArrayOfStrings(value: unknown): asserts value is string<beginfold id='5'>[</beginfold id='5'><endfold id='5'>]</endfold id='5'>;
0218 declare function assertDefined<T>(value: T): asserts value is NonNullable<T>;
0219 namespace Debug <beginfold id='1'>{</beginfold id='1'>
0220     export declare function assert(value: unknown, message?: string): asserts value;
0221     export declare function assertDefined<T>(value: T): asserts value is NonNullable<T>;
0222 <endfold id='1'>}</endfold id='1'>
0223 
0224 // Only highlight valid regular expressions, of a single line, after strings
0225 // See: https://github.com/microsoft/TypeScript-TmLanguage/issues/786
0226 "text" /No-Regex
0227 "text" /Regex[:)]*/;
0228 const a = "6" / 2; <beginfold id='6'>/*</beginfold id='6'>comment<endfold id='6'>*/</endfold id='6'> const b = 5;
0229 console.log("4" / "2"); // 2
0230 // Single quote
0231 const a = '6' / 2; <beginfold id='6'>/*</beginfold id='6'>comment<endfold id='6'>*/</endfold id='6'> const b = 5;
0232 console.log('4' / '2'); // 2
0233 // Template
0234 const a = <beginfold id='4'>`</beginfold id='4'>6<endfold id='4'>`</endfold id='4'> / 2; <beginfold id='6'>/*</beginfold id='6'>comment<endfold id='6'>*/</endfold id='6'> const b = 5;
0235 console.log(<beginfold id='4'>`</beginfold id='4'>4<endfold id='4'>`</endfold id='4'> / <beginfold id='4'>`</beginfold id='4'>2<endfold id='4'>`</endfold id='4'>); // 2
0236 
0237  <beginfold id='5'>[</beginfold id='5'>1, 2, 3<endfold id='5'>]</endfold id='5'>.reduce<readonly number<beginfold id='5'>[</beginfold id='5'><endfold id='5'>]</endfold id='5'>>((previous) => previous, <beginfold id='5'>[</beginfold id='5'><endfold id='5'>]</endfold id='5'>);
0238 
0239 // Multiline arrow assignment
0240 const h = <beginfold id='1'>{</beginfold id='1'>
0241   setSubProperty: <
0242       T extends A,
0243       K extends keyof T,
0244       J extends keyof T<beginfold id='5'>[</beginfold id='5'>K<endfold id='5'>]</endfold id='5'>
0245     >(
0246       property: K,
0247       key: J,
0248       value: T<beginfold id='5'>[</beginfold id='5'>K<endfold id='5'>]</endfold id='5'><beginfold id='5'>[</beginfold id='5'>J<endfold id='5'>]</endfold id='5'>
0249     ) =>  <beginfold id='1'>{</beginfold id='1'><endfold id='1'>}</endfold id='1'>
0250 <endfold id='1'>}</endfold id='1'>
0251 
0252 // Private-Named Instance Fields
0253 class Greeter <beginfold id='1'>{</beginfold id='1'>
0254     #name: string;
0255     constructor(name: string) <beginfold id='1'>{</beginfold id='1'>
0256         this.#name = name;
0257     <endfold id='1'>}</endfold id='1'>
0258     greet() <beginfold id='1'>{</beginfold id='1'>
0259         console.log(<beginfold id='4'>`</beginfold id='4'>hello ${this.#name}<endfold id='4'>`</endfold id='4'>);
0260     <endfold id='1'>}</endfold id='1'>
0261 <endfold id='1'>}</endfold id='1'>
0262 class Test <beginfold id='1'>{</beginfold id='1'>
0263     #NAME1: () => string;
0264     prop1 = x.#NAMEabc.#NAMEabc;
0265     prop2 = x.#NAMEabc.#NAMEabc();
0266     prop3 = this.#NAMEabc.#NAME();
0267 <endfold id='1'>}</endfold id='1'>
0268 
0269 // Type-only imports and exports
0270 import type T from "mod";
0271 import type <beginfold id='1'>{</beginfold id='1'> U, V <endfold id='1'>}</endfold id='1'> from "mod";
0272 import type * as types from "mod";
0273 import type from "mod";
0274 import type = require<beginfold id='3'>(</beginfold id='3'>"mod"<endfold id='3'>)</endfold id='3'>;
0275 import type T = require<beginfold id='3'>(</beginfold id='3'>"mod"<endfold id='3'>)</endfold id='3'>;
0276 
0277 export <beginfold id='1'>{</beginfold id='1'> a as b, x <endfold id='1'>}</endfold id='1'>;
0278 export * from "AnotherModule";
0279 export <beginfold id='1'>{</beginfold id='1'> k as m, l <endfold id='1'>}</endfold id='1'> from "AnotherModule";
0280 export type <beginfold id='1'>{</beginfold id='1'> T <endfold id='1'>}</endfold id='1'>;
0281 export type <beginfold id='1'>{</beginfold id='1'> U <endfold id='1'>}</endfold id='1'> from "AnotherModule";
0282 
0283 // 'awaited' type operator: https://github.com/microsoft/TypeScript/pull/35998
0284 let v1: awaited number;
0285 let v2: awaited Promise<number>;
0286 function f7<U>() <beginfold id='1'>{</beginfold id='1'>
0287     let v0: awaited U;
0288     let v1: awaited Promise<U>;
0289 <endfold id='1'>}</endfold id='1'>
0290 
0291 // Tagged template literals
0292 tagFunc<beginfold id='4'>`</beginfold id='4'>
0293     Hello world!
0294     ${ alert("Hello!"); }<endfold id='4'>`</endfold id='4'>;
0295 obj.something.tagFunc<beginfold id='4'>`</beginfold id='4'>Setting ${setting} is ${value + 5}!<endfold id='4'>`</endfold id='4'>;