diff --git a/autotests/folding/test.ts.fold b/autotests/folding/test.ts.fold --- a/autotests/folding/test.ts.fold +++ b/autotests/folding/test.ts.fold @@ -66,7 +66,7 @@ export function isInOpenInterval(start: number, end: number) { return tersible(a => a > start && a < end, () => `(${start}...${end})`) } -const bar = `${x} ${y}`; +const bar = `${x} ${y}`; // readonly function f1(mt: [number, number], rt: readonly [number, number]) { @@ -89,15 +89,15 @@ one?: string; two!: string; } -let x! = 1; +let x! = 1; // Function with multiple arguments const children = [].map>>(element => { if (!this.identityProvider) { return element; } return element; -}); +}); // Numerics var a = 0xA; @@ -128,7 +128,7 @@ let f: boolean = true; let g: number = 0b111001; // Binary let h: number = 0o436; // Octal -let i: number = 0xadf0d; // Hexa-Decimal +let i: number = 0xadf0d; // Hexa-Decimal const query = query<[number], number>(` SELECT * @@ -142,19 +142,19 @@ return database.execute(query) } -aa: string ? string +aa: string ? string string // Don't highlight aa: string assa | - string + string string ; string aa: { string string } // Don't highlight - + aa: [ string string ] -aa: ( string +aa: ( string string ) // Don't highlight aa: string interface a { @@ -185,5 +185,23 @@ w = () => this.a() ? true : this.b() ? false : true; z = () => - this.b() ? hello : k; + this.b() ? hello : k; +} + +function foo(arg: T): T extends B ? number : string { + if (arg === "A") return 111; + return "returning a string"; +} + +// Types and logical `&&` and `||` operators after `as` expression +Date as any || null; + +//Assertions +const assert: (value: unknown) => asserts value = value => {} +declare function assertIsString(value: unknown): asserts value is string; +declare function assertIsArrayOfStrings(value: unknown): asserts value is string[]; +declare function assertDefined(value: T): asserts value is NonNullable; +namespace Debug { + export declare function assert(value: unknown, message?: string): asserts value; + export declare function assertDefined(value: T): asserts value is NonNullable; } diff --git a/autotests/folding/test.tsx.fold b/autotests/folding/test.tsx.fold --- a/autotests/folding/test.tsx.fold +++ b/autotests/folding/test.tsx.fold @@ -9,13 +9,13 @@ function Story(props) { const SpecificStory = components[props.storyType]; return story={ props.story } attr2="&ref;" attr3="Hello\n" />; -} +} -function +function attr1={ /> function return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> /* no comment*/ function /> return class var 0x123 &ref; hello() React.Component() ./> anyWord /> - { function return class var 0x123 hello() React.Component() } + { function return class var 0x123 hello() React.Component() } > > > @@ -27,8 +27,8 @@ // Detect Valid tags /* comment */ >> -{ /* comment - */ /> +{ /* comment + */ /> word . } return /* comment multiline */ /> /* comment */ /> @@ -134,3 +134,13 @@ info: (arg: T): T ; > > } + +// Highlight "( + arg: T +) => { + const a = arg + return a +} +> text extends I/> > // Here "" is a tag diff --git a/autotests/html/test.ts.html b/autotests/html/test.ts.html --- a/autotests/html/test.ts.html +++ b/autotests/html/test.ts.html @@ -72,7 +72,7 @@ export function isInOpenInterval(start: number, end: number) { return tersible(a => a > start && a < end, () => `(${start}...${end})`) } -const bar = `${x} ${y}`; +const bar = `${x} ${y}`; // readonly function f1(mt: [number, number], rt: readonly [number, number]) { @@ -95,15 +95,15 @@ one?: string; two!: string; } -let x! = 1; +let x! = 1; // Function with multiple arguments const children = [].map<Set<Map<number, string>>>(element => { if (!this.identityProvider) { return element; } return element; -}); +}); // Numerics var a = 0xA; @@ -134,7 +134,7 @@ let f: boolean = true; let g: number = 0b111001; // Binary let h: number = 0o436; // Octal -let i: number = 0xadf0d; // Hexa-Decimal +let i: number = 0xadf0d; // Hexa-Decimal const query = query<[number], number>(` SELECT * @@ -148,19 +148,19 @@ return database.execute(query) } -aa: <sdf/> string ?<ssd/> string +aa: <sdf/> string ?<ssd/> string string // Don't highlight aa: string assa | - string + string string ; string aa: { string string } // Don't highlight - + aa: [ string string ] -aa: ( string +aa: ( string string ) // Don't highlight aa: string <string> interface a { @@ -191,6 +191,24 @@ w = () => this.a() ? true : this.b() ? false : true; z = () => - this.b() ? hello : k; + this.b() ? hello : k; +} + +function foo<T extends X>(arg: T): T extends B ? number : string { + if (arg === "A") return <T extends B ? number : never>111; + return <T extends B ? never : string>"returning a string"; +} + +// Types and logical `&&` and `||` operators after `as` expression +Date as any || null; + +//Assertions +const assert: (value: unknown) => asserts value = value => {} +declare function assertIsString(value: unknown): asserts value is string; +declare function assertIsArrayOfStrings(value: unknown): asserts value is string[]; +declare function assertDefined<T>(value: T): asserts value is NonNullable<T>; +namespace Debug { + export declare function assert(value: unknown, message?: string): asserts value; + export declare function assertDefined<T>(value: T): asserts value is NonNullable<T>; } diff --git a/autotests/html/test.tsx.html b/autotests/html/test.tsx.html --- a/autotests/html/test.tsx.html +++ b/autotests/html/test.tsx.html @@ -15,13 +15,13 @@ function Story(props) { const SpecificStory = components[props.storyType]; return <SpecificStory story={ props.story } attr2="&ref;" attr3="Hello\n" />; -} +} -function +function <Tag attr1={ <tag/> function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> /* no comment*/ function <tag/> return class var 0x123 &ref; hello() React.Component() .<tag/> anyWord <tag/> - { function <tag> return class var 0x123 hello() React.Component() } + { function <tag> return class var 0x123 hello() React.Component() } </Tag> <tag1> </tag1> @@ -33,8 +33,8 @@ // Detect Valid tags /* comment */ <tag></tag> -{ /* comment - */ <Tag /> +{ /* comment + */ <Tag /> word <noTag/> . <noTag/> } <noTag/> return /* comment multiline */ <tag/> /* comment */ <Tag/> @@ -121,10 +121,10 @@ /*comment*/<A/>}` // Don't highlight tags within type declaration -type T12 = ReturnType<(<T>() => T)>; -type T13 = ReturnType<(<T extends U, U extends number[]>() => T)>; -type T14 = ReturnType<typeof f1>; -type T15 = ReturnType<(s: string) => void>; +type T12 = ReturnType<(<T>() => T)>; +type T13 = ReturnType<(<T extends U, U extends number[]>() => T)>; +type T14 = ReturnType<typeof f1>; +type T15 = ReturnType<(s: string) => void>; // Don't highlight tags within variable declaration let myIdentity: <T>(arg: T) => T <noTag/> = <Tag />; @@ -140,4 +140,14 @@ info: <T>(arg: T): T <noTag />; <tag> </tag> } + +// Highlight "<T extends" as a type assertion, not as a tag +// (the "cast" expression works and isn't supported in the TSX file) +const goodHighlighting = <T extends I>( + arg: T +) => { + const a = arg + return a +} +<tag> text <T extends I/> </tag> // Here "<T extends I/>" is a tag diff --git a/autotests/input/test.ts b/autotests/input/test.ts --- a/autotests/input/test.ts +++ b/autotests/input/test.ts @@ -66,7 +66,7 @@ export function isInOpenInterval(start: number, end: number) { return tersible(a => a > start && a < end, () => `(${start}...${end})`) } -const bar = `${x} ${y}`; +const bar = `${x} ${y}`; // readonly function f1(mt: [number, number], rt: readonly [number, number]) { @@ -89,15 +89,15 @@ one?: string; two!: string; } -let x! = 1; +let x! = 1; // Function with multiple arguments const children = [].map>>(element => { if (!this.identityProvider) { return element; } return element; -}); +}); // Numerics var a = 0xA; @@ -128,7 +128,7 @@ let f: boolean = true; let g: number = 0b111001; // Binary let h: number = 0o436; // Octal -let i: number = 0xadf0d; // Hexa-Decimal +let i: number = 0xadf0d; // Hexa-Decimal const query = query<[number], number>(` SELECT * @@ -142,19 +142,19 @@ return database.execute(query) } -aa: string ? string +aa: string ? string string // Don't highlight aa: string assa | - string + string string ; string aa: { string string } // Don't highlight - + aa: [ string string ] -aa: ( string +aa: ( string string ) // Don't highlight aa: string interface a { @@ -185,5 +185,23 @@ w = () => this.a() ? true : this.b() ? false : true; z = () => - this.b() ? hello : k; + this.b() ? hello : k; +} + +function foo(arg: T): T extends B ? number : string { + if (arg === "A") return 111; + return "returning a string"; +} + +// Types and logical `&&` and `||` operators after `as` expression +Date as any || null; + +//Assertions +const assert: (value: unknown) => asserts value = value => {} +declare function assertIsString(value: unknown): asserts value is string; +declare function assertIsArrayOfStrings(value: unknown): asserts value is string[]; +declare function assertDefined(value: T): asserts value is NonNullable; +namespace Debug { + export declare function assert(value: unknown, message?: string): asserts value; + export declare function assertDefined(value: T): asserts value is NonNullable; } diff --git a/autotests/input/test.tsx b/autotests/input/test.tsx --- a/autotests/input/test.tsx +++ b/autotests/input/test.tsx @@ -9,13 +9,13 @@ function Story(props) { const SpecificStory = components[props.storyType]; return ; -} +} -function +function function return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> /* no comment*/ function return class var 0x123 &ref; hello() React.Component() . anyWord - { function return class var 0x123 hello() React.Component() } + { function return class var 0x123 hello() React.Component() } @@ -27,8 +27,8 @@ // Detect Valid tags /* comment */ -{ /* comment - */ +{ /* comment + */ word . } return /* comment multiline */ /* comment */ @@ -134,3 +134,13 @@ info: (arg: T): T ; } + +// Highlight "( + arg: T +) => { + const a = arg + return a +} + text // Here "" is a tag diff --git a/autotests/reference/test.ts.ref b/autotests/reference/test.ts.ref --- a/autotests/reference/test.ts.ref +++ b/autotests/reference/test.ts.ref @@ -66,7 +66,7 @@ export function isInOpenInterval(start: number, end: number) {
return tersible(a => a > start && a < end, () => ${start}${end})
}
-const bar = ${x}${y};
+const bar = ${x}${y};

// readonly
function f1(mt: [number, number], rt: readonly [number, number]) {
@@ -89,15 +89,15 @@ one?: string;
two!: string;
}
-let x! = 1;
+let x! = 1;

// Function with multiple arguments
const children = [].map<Set<Map<number, string>>>(element => {
if (!this.identityProvider) {
return element;
}
return element;
-});
+});

// Numerics
var a = 0xA;
@@ -128,7 +128,7 @@ let f: boolean = true;
let g: number = 0b111001; // Binary
let h: number = 0o436; // Octal
-let i: number = 0xadf0d; // Hexa-Decimal
+let i: number = 0xadf0d; // Hexa-Decimal

const query = query<[number], number>(

@@ -142,19 +142,19 @@ return database.execute(query)
}

-aa: <sdf/> string ?<ssd/> string
+aa: <sdf/> string ?<ssd/> string
string // Don't highlight
aa: string assa |
- string
+ string
string ;
string

aa: { string
string } // Don't highlight
-
+
aa: [ string
string ]
-aa: ( string
+aa: ( string
string ) // Don't highlight
aa: string <string>
interface a {
@@ -185,5 +185,23 @@ w = () =>
this.a() ? true : this.b() ? false : true;
z = () =>
- this.b() ? hello : k;
+ this.b() ? hello : k;
+}
+
+function foo<T extends X>(arg: T): T extends B ? number : string {
+ if (arg === "A") return <T extends B ? number : never>111;
+ return <T extends B ? never : string>"returning a string";
+}
+
+// Types and logical `&&` and `||` operators after `as` expression
+Date as any || null;
+
+//Assertions
+const assert: (value: unknown) => asserts value = value => {}
+declare function assertIsString(value: unknown): asserts value is string;
+declare function assertIsArrayOfStrings(value: unknown): asserts value is string[];
+declare function assertDefined<T>(value: T): asserts value is NonNullable<T>;
+namespace Debug {
+ export declare function assert(value: unknown, message?: string): asserts value;
+ export declare function assertDefined<T>(value: T): asserts value is NonNullable<T>;
}
diff --git a/autotests/reference/test.tsx.ref b/autotests/reference/test.tsx.ref --- a/autotests/reference/test.tsx.ref +++ b/autotests/reference/test.tsx.ref @@ -9,13 +9,13 @@ function Story(props) {
const SpecificStory = components[props.storyType];
return story={ props.story } attr2="&ref;" attr3="Hello\n" />;
-}
+}

-function
+function
attr1={ function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;">
/* no comment*/ function return class var 0x123 &ref; hello() React.Component()
. anyWord
- { function <tag> return class var 0x123 hello() React.Component() }
+ { function <tag> return class var 0x123 hello() React.Component() }



@@ -27,8 +27,8 @@ // Detect Valid tags

/* comment */
-{ /* comment
- */ />
+{ /* comment
+ */ />
word <noTag/> . <noTag/> } <noTag/>
return /* comment
multiline */ /* comment */
@@ -115,10 +115,10 @@ /*comment*/}

// Don't highlight tags within type declaration
-type T12 = ReturnType<(<T>() => T)>;
-type T13 = ReturnType<(<T extends U, U extends number[]>() => T)>;
-type T14 = ReturnType<typeof f1>;
-type T15 = ReturnType<(s: string) => void>;
+type T12 = ReturnType<(<T>() => T)>;
+type T13 = ReturnType<(<T extends U, U extends number[]>() => T)>;
+type T14 = ReturnType<typeof f1>;
+type T15 = ReturnType<(s: string) => void>;

// Don't highlight tags within variable declaration
let myIdentity: <T>(arg: T) => T <noTag/> = />;
@@ -134,3 +134,13 @@ info: <T>(arg: T): T <noTag />;

}
+
+// Highlight "
+// (the "cast" expression works and isn't supported in the TSX file)
+const goodHighlighting = <T extends I>(
+ arg: T
+) => {
+ const a = arg
+ return a
+}
+ text extends I/>
// Here "" is a tag
diff --git a/data/syntax/javascript-react.xml b/data/syntax/javascript-react.xml --- a/data/syntax/javascript-react.xml +++ b/data/syntax/javascript-react.xml @@ -1,17 +1,17 @@ - - - - + + + + + - - + + - + ]> - @@ -104,7 +104,7 @@ - + @@ -148,13 +148,13 @@ - - - + + + - + @@ -200,9 +200,9 @@ - + - + diff --git a/data/syntax/javascript.xml b/data/syntax/javascript.xml --- a/data/syntax/javascript.xml +++ b/data/syntax/javascript.xml @@ -1,12 +1,12 @@ + ]> - @@ -93,7 +93,7 @@ - + @@ -174,11 +174,11 @@ - + - + diff --git a/data/syntax/typescript-react.xml b/data/syntax/typescript-react.xml --- a/data/syntax/typescript-react.xml +++ b/data/syntax/typescript-react.xml @@ -1,19 +1,19 @@ - - - - + + + + + - - + + - + - + ]> - @@ -78,7 +79,7 @@ - + @@ -170,6 +171,7 @@ + @@ -238,13 +240,13 @@ - - - + + + - + @@ -297,6 +299,11 @@ NOTE: The highlighting of Tags after a multiline comment does not work with: lineEndContext="#pop" --> + + + + @@ -307,9 +314,9 @@ - + - + diff --git a/data/syntax/typescript.xml b/data/syntax/typescript.xml --- a/data/syntax/typescript.xml +++ b/data/syntax/typescript.xml @@ -1,10 +1,12 @@ - - - + + + + + + ]> reserved##JavaScript type arguments - readonly abstract @@ -1661,9 +1664,9 @@ - + - + @@ -1682,12 +1685,15 @@ + + - + + @@ -1709,9 +1715,9 @@ - + - + @@ -1737,6 +1743,8 @@ + + @@ -1773,17 +1781,17 @@ - - + + - + - + @@ -1800,7 +1808,7 @@ - + @@ -1810,7 +1818,7 @@ - + @@ -1844,14 +1852,23 @@ + + + + + - + + + + + @@ -1915,7 +1932,7 @@ - + @@ -1940,7 +1957,7 @@ - +