diff --git a/autotests/folding/highlight.js.fold b/autotests/folding/highlight.js.fold --- a/autotests/folding/highlight.js.fold +++ b/autotests/folding/highlight.js.fold @@ -77,11 +77,11 @@ something.method = - function ( a, b, c ) { /* ... */ } + function ( a, b, c ) { /* ... */ } // ^ fallthrough ?! something.other = -function ( d, e, f ) { /* ... */ } +function ( d, e, f ) { /* ... */ } // fallthrough expected at col 0 ("function" should be bold) var ary = new Array(5); @@ -109,31 +109,31 @@ return; -try { bla() } catch (e) { alert("ERROR! : " + e) } +try { bla() } catch (e) { alert("ERROR! : " + e) } for (int i=0; i < j; i++) document.write("i is" + i + "
"); while (something) -{ +{ block(); picky: if (!1) break; else continue; -} +} -with (a) { - do { +with (a) { + do { stuff( b ); // a.b if it exists - } while (itmakessense); -} + } while (itmakessense); +} -switch (i) { +switch (i) { case 0: f(); break; default: break; -} +} diff --git a/autotests/folding/highlight.php.fold b/autotests/folding/highlight.php.fold --- a/autotests/folding/highlight.php.fold +++ b/autotests/folding/highlight.php.fold @@ -13,6 +13,49 @@ test"; ?> + + + > + .inputText { + width: px; + text-indent: 10px; + } + > + + + > + var some_js_var = ; + + > + + type="text/babel"> + > > /* aaa */ ?> >> + function a(i) { + + return >{ i + j }>; + } + > + + type="text/typescript"> + + class DateTime { + info: string; + constructor() { this.info = ; } + get() { return this.info; } + } + > + + type="x-tmpl-mustache"> + {{! }} + {{#movie}} + > + >{{title}}> + src="{{poster}}" alt="{{title}}"/> + - {{ratings.critics_rating}} + > + {{/movie}} + > + /* comment */ function fun() -{ - var boo = { 'key': [ 1, 2.0, 3.0e1, 004, 0x5 ] }; -} +{ + var boo = { 'key': [ 1, 2.0, 3.0e1, 004, 0x5 ] }; +} class MyClass; // reserved keywords diff --git a/autotests/folding/test.jsx.fold b/autotests/folding/test.jsx.fold --- a/autotests/folding/test.jsx.fold +++ b/autotests/folding/test.jsx.fold @@ -12,7 +12,7 @@ } function - attr1={ /> function return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> + 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() } @@ -27,16 +27,16 @@ // Detect Valid tags /* comment */ >> -{ /* comment +{ /* comment */ /> word . } return /* comment multiline */ /> /* comment */ /> && /*comment*/ /> & /*comment*/ /> -{ >Hello> } +{ >Hello> } ? />; [ /> ( /> ,/> =/> @@ -75,3 +75,22 @@ <>>hi>>bye>; // children <>>1><>>2.1>>2.2>>3>; // nested fragments <>#; // # would cause scanning error if not in jsxtext + +// Tags after substitutions in templates +`aaa${>>//comment + /*comment*//>}` + +// Don't highlight tags within variable declaration +let myIdentity: (arg: T) => T = identity; +var myIdentity: (arg: U) => U = identity; +const myIdentity: {<T>(arg: T): T} = identity; + +// Don't highlight tags within interfaces and classes +interface GenericIdentityFn { + (arg: T): T; + +} +class Handler { + info: (arg: T): T ; + > > +} 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 @@ -57,6 +57,48 @@ } } +const enum ResponseCode { + Success = 200, + BadRequest = 400 +} + +// Substitutions +export function isInOpenInterval(start: number, end: number) { + return tersible(a => a > start && a < end, () => `(${start}...${end})`) +} +const bar = `${x} ${y}`; + +// readonly +function f1(mt: [number, number], rt: readonly [number, number]) { +} + +function f2(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) { +} + +type ReadWrite = { -readonly [P in keyof T] : T[P] }; + +// const assertion +let obj = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; +let r2 = { x: 20, y: 10 } as const; +let r2 = {...p} as const; +let p1 = { x: 10, y: 20 as const }; +let p2 = { 10 as const, 'foo' as const }; + +// Definite assignment operator +class Cl { + one?: string; + two!: string; +} +let x! = 1; + +// Function with multiple arguments +const children = [].map>>(element => { + if (!this.identityProvider) { + return element; + } + return element; +}); + // Numerics var a = 0xA; var b = 0b1; @@ -71,6 +113,12 @@ var k = 1; var l = 1__.e+3_22 | .2____e2 | 0o1_23 | 11__. ; +// Bigint +const binBig = 0b101n; +const octBig = 0o567n; +const hexBig = 0xC0Bn; +const decBig = 123n; + // Types let a: null = null; let b: number = 123; @@ -109,3 +157,25 @@ aa: ( string string ) // Don't highlight aa: string +interface a { + aa: /* comment + */ string, + bb: /* comment */ + number, + cc: // comment + void, + dd: + any, +} + +null, <{[key]: () => any}> null +null, <{[key]: () =>{a: number}}> null + +// Correctly highlighting regular expressions +dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms'; +(a[0] / 2) / (2) + +// Type guards +function isNumber(x: any): x is number { + return typeof x === "number"; +} 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 @@ -12,7 +12,7 @@ } function - attr1={ /> function return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> + 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() } @@ -52,7 +52,7 @@ % /* comment*/ // TODO: Fix this (comment before the tag name): -var x = ; +var x = </**/div>; // Tag after ":" annotation: /> @@ -109,3 +109,28 @@ <>>hi>>bye>; // children <>>1><>>2.1>>2.2>>3>; // nested fragments <>#; // # would cause scanning error if not in jsxtext + +// Tags after substitutions in templates +`aaa${>>//comment + /*comment*//>}` + +// Don't highlight tags within type declaration +type T12 = ReturnType<(() => T)>; +type T13 = ReturnType<([]>() => T)>; +type T14 = ReturnType; +type T15 = ReturnType<(s: string) => void>; + +// Don't highlight tags within variable declaration +let myIdentity: (arg: T) => T = />; +var myIdentity: (arg: U) => U = identity; +const myIdentity: {(arg: T): T} = identity; + +// Don't highlight tags within interfaces and classes +interface GenericIdentityFn { + (arg: T): T; + +} +class Handler { + info: (arg: T): T ; + > > +} diff --git a/autotests/html/highlight.php.html b/autotests/html/highlight.php.html --- a/autotests/html/highlight.php.html +++ b/autotests/html/highlight.php.html @@ -19,6 +19,49 @@ <html> <? print "<title>test</title>"; ?> + + <!-- CSS --> + <style> + .inputText { + width: <?php echo $width; ?>px; + text-indent: 10px; + } + </style> + + <!-- JavaScript --> + <script> + var some_js_var = <?php echo $somevar; ?> ; + <?php echo 'alert("Hello there.");'; ?> + </script> + <!-- JavaScript React --> + <script type="text/babel"> + <Hello> <?php echo("Hello, hello!"); ?> </Hello> <?php /* aaa */ ?> <div></div> + function a(i) { + <?php echo "var j = 1;"; ?> + return <p>{ i + j }</p>; + } + </script> + <!-- TypeScript --> + <script type="text/typescript"> + <?php $timestamp = time(); ?> + class DateTime { + info: string; + constructor() { this.info = <?php echo(date("F d, Y h:i:s", $timestamp)); ?>; } + get() { return this.info; } + } + </script> + <!-- MustacheJS --> + <script type="x-tmpl-mustache"> + {{! <?php print "comment"; ?> }} + {{#movie}} + <div> + <h1>{{title}}</h1> + <img src="{{poster}}" alt="{{title}}"/> + <?php echo $movierating; ?> - {{ratings.critics_rating}} + </div> + {{/movie}} + </script> + </html> <?php diff --git a/autotests/html/test.jsx.html b/autotests/html/test.jsx.html --- a/autotests/html/test.jsx.html +++ b/autotests/html/test.jsx.html @@ -18,7 +18,7 @@ } function -<Tag attr1={ <tag/> function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> +<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() } @@ -81,4 +81,23 @@ <><span>hi</span><div>bye</div></>; // children <><span>1</span><><span>2.1</span><span>2.2</span></><span>3</span></>; // nested fragments <>#</>; // # would cause scanning error if not in jsxtext + +// Tags after substitutions in templates +`aaa${<tag></tag>//comment + /*comment*/<A/>}` + +// Don't highlight tags within variable declaration +let myIdentity: <T>(arg: T) => T = identity; +var myIdentity: <U>(arg: U) => U = identity; +const myIdentity: {<T>(arg: T): T} = identity; + +// Don't highlight tags within interfaces and classes +interface GenericIdentityFn { + <T>(arg: T): T; + <noTag /> +} +class Handler { + info: <T>(arg: T): T <noTag />; + <tag> </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 @@ -63,6 +63,48 @@ } } +const enum ResponseCode { + Success = 200, + BadRequest = 400 +} + +// Substitutions +export function isInOpenInterval(start: number, end: number) { + return tersible(a => a > start && a < end, () => `(${start}...${end})`) +} +const bar = `${x} ${y}`; + +// readonly +function f1(mt: [number, number], rt: readonly [number, number]) { +} + +function f2(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) { +} + +type ReadWrite<T> = { -readonly [P in keyof T] : T[P] }; + +// const assertion +let obj = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; +let r2 = { x: 20, y: 10 } as const; +let r2 = {...p} as const; +let p1 = { x: 10, y: 20 as const }; +let p2 = { 10 as const, 'foo' as const }; + +// Definite assignment operator +class Cl { + one?: string; + two!: string; +} +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; var b = 0b1; @@ -77,6 +119,12 @@ var k = 1; var l = 1__.e+3_22 | .2____e2 | 0o1_23 | 11__. ; +// Bigint +const binBig = 0b101n; +const octBig = 0o567n; +const hexBig = 0xC0Bn; +const decBig = 123n; + // Types let a: null = null; let b: number = 123; @@ -104,7 +152,7 @@ string // Don't highlight aa: string assa | string - string ; + string ; string aa: { string @@ -115,4 +163,26 @@ aa: ( string string ) // Don't highlight aa: string <string> +interface a { + aa: /* comment + */ string, + bb: /* comment */ + number, + cc: // comment + void, + dd: + any, +} + +null, <{[key]: () => any}> null +null, <{[key]: () =>{a: number}}> null + +// Correctly highlighting regular expressions +dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms'; +(a[0] / 2) / (2) + +// Type guards +function isNumber(x: any): x is number { + return typeof x === "number"; +} 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 @@ -18,7 +18,7 @@ } function -<Tag attr1={ <tag/> function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;"> +<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() } @@ -58,7 +58,7 @@ % /* comment*/ <noTag/> // TODO: Fix this (comment before the tag name): -var x = </**/div></div>; +var x = </**/div></div>; // Tag after ":" annotation: <tag/> @@ -115,4 +115,29 @@ <><span>hi</span><div>bye</div></>; // children <><span>1</span><><span>2.1</span><span>2.2</span></><span>3</span></>; // nested fragments <>#</>; // # would cause scanning error if not in jsxtext + +// Tags after substitutions in templates +`aaa${<tag></tag>//comment + /*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>; + +// Don't highlight tags within variable declaration +let myIdentity: <T>(arg: T) => T <noTag/> = <Tag />; +var myIdentity: <U>(arg: U) => U = identity; +const myIdentity: {<T>(arg: T): T} = identity; + +// Don't highlight tags within interfaces and classes +interface GenericIdentityFn { + <T>(arg: T): T; + <noTag /> +} +class Handler { + info: <T>(arg: T): T <noTag />; + <tag> </tag> +} diff --git a/autotests/input/highlight.php b/autotests/input/highlight.php --- a/autotests/input/highlight.php +++ b/autotests/input/highlight.php @@ -13,6 +13,49 @@ test"; ?> + + + + + + + + + + + + + hi
bye
; // children <>1<>2.12.23; // nested fragments <>#; // # would cause scanning error if not in jsxtext + +// Tags after substitutions in templates +`aaa${//comment + /*comment*/}` + +// Don't highlight tags within variable declaration +let myIdentity: (arg: T) => T = identity; +var myIdentity: (arg: U) => U = identity; +const myIdentity: {(arg: T): T} = identity; + +// Don't highlight tags within interfaces and classes +interface GenericIdentityFn { + (arg: T): T; + +} +class Handler { + info: (arg: T): T ; + +} diff --git a/autotests/input/test.ts b/autotests/input/test.ts --- a/autotests/input/test.ts +++ b/autotests/input/test.ts @@ -57,6 +57,48 @@ } } +const enum ResponseCode { + Success = 200, + BadRequest = 400 +} + +// Substitutions +export function isInOpenInterval(start: number, end: number) { + return tersible(a => a > start && a < end, () => `(${start}...${end})`) +} +const bar = `${x} ${y}`; + +// readonly +function f1(mt: [number, number], rt: readonly [number, number]) { +} + +function f2(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) { +} + +type ReadWrite = { -readonly [P in keyof T] : T[P] }; + +// const assertion +let obj = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const; +let r2 = { x: 20, y: 10 } as const; +let r2 = {...p} as const; +let p1 = { x: 10, y: 20 as const }; +let p2 = { 10 as const, 'foo' as const }; + +// Definite assignment operator +class Cl { + one?: string; + two!: string; +} +let x! = 1; + +// Function with multiple arguments +const children = [].map>>(element => { + if (!this.identityProvider) { + return element; + } + return element; +}); + // Numerics var a = 0xA; var b = 0b1; @@ -71,6 +113,12 @@ var k = 1; var l = 1__.e+3_22 | .2____e2 | 0o1_23 | 11__. ; +// Bigint +const binBig = 0b101n; +const octBig = 0o567n; +const hexBig = 0xC0Bn; +const decBig = 123n; + // Types let a: null = null; let b: number = 123; @@ -109,3 +157,25 @@ aa: ( string string ) // Don't highlight aa: string +interface a { + aa: /* comment + */ string, + bb: /* comment */ + number, + cc: // comment + void, + dd: + any, +} + +null, <{[key]: () => any}> null +null, <{[key]: () =>{a: number}}> null + +// Correctly highlighting regular expressions +dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms'; +(a[0] / 2) / (2) + +// Type guards +function isNumber(x: any): x is number { + return typeof x === "number"; +} diff --git a/autotests/input/test.tsx b/autotests/input/test.tsx --- a/autotests/input/test.tsx +++ b/autotests/input/test.tsx @@ -109,3 +109,28 @@ <>hi
bye
; // children <>1<>2.12.23; // nested fragments <>#; // # would cause scanning error if not in jsxtext + +// Tags after substitutions in templates +`aaa${//comment + /*comment*/
}` + +// Don't highlight tags within type declaration +type T12 = ReturnType<(() => T)>; +type T13 = ReturnType<(() => T)>; +type T14 = ReturnType; +type T15 = ReturnType<(s: string) => void>; + +// Don't highlight tags within variable declaration +let myIdentity: (arg: T) => T = ; +var myIdentity: (arg: U) => U = identity; +const myIdentity: {(arg: T): T} = identity; + +// Don't highlight tags within interfaces and classes +interface GenericIdentityFn { + (arg: T): T; + +} +class Handler { + info: (arg: T): T ; + +} diff --git a/autotests/reference/highlight.js.ref b/autotests/reference/highlight.js.ref --- a/autotests/reference/highlight.js.ref +++ b/autotests/reference/highlight.js.ref @@ -55,7 +55,7 @@ // the following are not regexps in E4X (=xml embedded into JavaScript)
var p = <p>Hello World>
var p = /
-var p = />/
+var p = />/

// a test if #pop back from a comment will work
re = /*/foo/*/ /bar/;
diff --git a/autotests/reference/highlight.php.ref b/autotests/reference/highlight.php.ref --- a/autotests/reference/highlight.php.ref +++ b/autotests/reference/highlight.php.ref @@ -13,6 +13,49 @@

print "test"; ?>
+
+
+
+
+
+
+
+ type="text/babel">
+ echo("Hello, hello!"); ?> /* aaa */ ?>

+ function a(i) {
+ echo "var j = 1;"; ?>
+ return

{ i + j }

;
+ }
+
+
+ type="text/typescript">
+ $timestamp = time(); ?>
+ class DateTime {
+ info: string;
+ constructor() { this.info = echo(date("F d, Y h:i:s", $timestamp)); ?>; }
+ get() { return this.info; }
+ }
+
+
+ type="x-tmpl-mustache">
+ {{! print "comment"; ?> }}
+ {{#movie}}
+

+

{{title}}


+ src="{{poster}}" alt="{{title}}"/>
+ echo $movierating; ?> - {{ratings.critics_rating}}
+

+ {{/movie}}
+
+



diff --git a/autotests/reference/test.htm.ref b/autotests/reference/test.htm.ref --- a/autotests/reference/test.htm.ref +++ b/autotests/reference/test.htm.ref @@ -20,13 +20,13 @@
type="text/typescript">
class Student {
- fullName: string;
- constructor(public firstName: string, public middleInitial: string, public lastName: string) {
+ fullName: string;
+ constructor(public firstName: string, public middleInitial: string, public lastName: string) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
- let a: null = null;
- let b: number = 12___3;
+ let a: null = null;
+ let b: number = 12___3;



diff --git a/autotests/reference/test.js.ref b/autotests/reference/test.js.ref --- a/autotests/reference/test.js.ref +++ b/autotests/reference/test.js.ref @@ -20,4 +20,4 @@ var bin = 0b1010;

ლಠ益ಠლ.ñá = 42;
-δ /No-RegExp/
+δ /No-RegExp/
diff --git a/autotests/reference/test.jsx.ref b/autotests/reference/test.jsx.ref --- a/autotests/reference/test.jsx.ref +++ b/autotests/reference/test.jsx.ref @@ -12,7 +12,7 @@ }

function
- attr1={ function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;">
+ 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() }
@@ -27,16 +27,16 @@ // Detect Valid tags

/* comment */
-{ /* comment
+{ /* comment
*/ />
- word <noTag/> . <noTag/> } <noTag/>
+ word <noTag/> . <noTag/> } <noTag/>
return /* comment
multiline */ /* comment */
&& /*comment*/
-& /*comment*/ <noTag/>
+& /*comment*/ <noTag/>


-{ Hello }
+{ Hello }
? />;
[ /> ( />
, =
@@ -46,10 +46,10 @@
return


anyWord<noTag>
-anyWord/*comment*/ <noTag/>
+anyWord/*comment*/ <noTag/>
.<noTag>
-&<notag> | <noTag/>
-% /* comment*/ <noTag/>
+&<notag> | <noTag/>
+% /* comment*/ <noTag/>

<number>/>
<number>>
@@ -75,3 +75,22 @@ <>hi
bye
; // children
<>1<>2.12.23; // nested fragments
<>#; // # would cause scanning error if not in jsxtext
+
+// Tags after substitutions in templates
+${//comment
+ /*comment*/
}
+
+// Don't highlight tags within variable declaration
+let myIdentity: <T>(arg: T) => T = identity;
+var myIdentity: <U>(arg: U) => U = identity;
+const myIdentity: {<T>(arg: T): T} = identity;
+
+// Don't highlight tags within interfaces and classes
+interface GenericIdentityFn {
+ <T>(arg: T): T;
+ <noTag />
+}
+class Handler {
+ info: <T>(arg: T): T <noTag />;
+

+}
diff --git a/autotests/reference/test.qml.ref b/autotests/reference/test.qml.ref --- a/autotests/reference/test.qml.ref +++ b/autotests/reference/test.qml.ref @@ -12,7 +12,7 @@ signal mySignal(int arg1, string arg2)
color: "lightsteelblue"
width: 320
- height: width/2
+ height: width/2

Rectangle {
id: sub
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 @@ -3,18 +3,18 @@ // TypeScript Test

class Student {
- fullName: string;
- constructor(public firstName: string, public middleInitial: string, public lastName: string) {
+ fullName: string;
+ constructor(public firstName: string, public middleInitial: string, public lastName: string) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}

interface Person {
- firstName: string;
- lastName: string;
+ firstName: string;
+ lastName: string;
}

-function greeter(person : Person) {
+function greeter(person : Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}

@@ -35,14 +35,14 @@ const rootDir = path.dirname(__dirname);

const defaultBrowser = os.platform() === "win32" ? "edge" : "chrome";
-let browser: "edge" | "chrome" | "none" = defaultBrowser;
-let grep: string | undefined;
+let browser: "edge" | "chrome" | "none" = defaultBrowser;
+let grep: string | undefined;

interface FileBasedTestConfiguration {
- [setting: string]: string;
+ [setting: string]: string;
}

-function swapCase(s: string): string {
+function swapCase(s: string): string {
return s.replace(/\w/g, (ch) => {
const up = ch.toUpperCase();
return ch === up ? ch.toLowerCase() : up;
@@ -57,6 +57,48 @@ }
}

+const enum ResponseCode {
+ Success = 200,
+ BadRequest = 400
+}
+
+// Substitutions
+export function isInOpenInterval(start: number, end: number) {
+ return tersible(a => a > start && a < end, () => ${start}${end})
+}
+const bar = ${x}${y};
+
+// readonly
+function f1(mt: [number, number], rt: readonly [number, number]) {
+}
+
+function f2(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]) {
+}
+
+type ReadWrite<T> = { -readonly [P in keyof T] : T[P] };
+
+// const assertion
+let obj = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const;
+let r2 = { x: 20, y: 10 } as const;
+let r2 = {...p} as const;
+let p1 = { x: 10, y: 20 as const };
+let p2 = { 10 as const, 'foo' as const };
+
+// Definite assignment operator
+class Cl {
+ one?: string;
+ two!: string;
+}
+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;
var b = 0b1;
@@ -71,41 +113,69 @@ var k = 1;
var l = 1__.e+3_22 | .2____e2 | 0o1_23 | 11__. ;

+// Bigint
+const binBig = 0b101n;
+const octBig = 0o567n;
+const hexBig = 0xC0Bn;
+const decBig = 123n;
+
// Types
-let a: null = null;
-let b: number = 123;
-let c: number = 123.456;
-let d: string = ;
-let e: undefined = undefined;
-let f: boolean = true;
-let g: number = 0b111001; // Binary
-let h: number = 0o436; // Octal
-let i: number = 0xadf0d; // Hexa-Decimal
-
-const query = query<[number], number>(
+let a: null = null;
+let b: number = 123;
+let c: number = 123.456;
+let d: string = ;
+let e: undefined = undefined;
+let f: boolean = true;
+let g: number = 0b111001; // Binary
+let h: number = 0o436; // Octal
+let i: number = 0xadf0d; // Hexa-Decimal
+
+const query = query<[number], number>(


)

function runQuery() {
- const query = createQuery<[number[]], Table<Columns>>(
+ const query = createQuery<[number[]], Table<Columns>>(

)
return database.execute(query)
}

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

-aa: { string
+aa: { string
string } // Don't highlight

-aa: [ string
- string ]
-aa: ( string
+aa: [ string
+ string ]
+aa: ( string
string ) // Don't highlight
-aa: string <string>
+aa: string <string>
+interface a {
+ aa: /* comment
+ */ string,
+ bb: /* comment */
+ number,
+ cc: // comment
+ void,
+ dd:
+ any,
+}
+
+null, <{[key]: () => any}> null
+null, <{[key]: () =>{a: number}}> null
+
+// Correctly highlighting regular expressions
+dt = ((dt[0] * 1e9 + dt[1]) / 1e6).toFixed(3).replace(/\.?0+$/, '') + 'ms';
+(a[0] / 2) / (2)
+
+// Type guards
+function isNumber(x: any): x is number {
+ return typeof x === "number";
+}
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 @@ -12,7 +12,7 @@ }

function
- attr1={ function <noTag/> return class var 0x123 { } &noRef; hello() React.Component() } attr2="&ref;">
+ 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() }
@@ -29,11 +29,11 @@ /* comment */
{ /* comment
*/ />
- word <noTag/> . <noTag/> } <noTag/>
+ word <noTag/> . <noTag/> } <noTag/>
return /* comment
multiline */ /* comment */
&& /*comment*/
-& /*comment*/ <noTag/>
+& /*comment*/ <noTag/>


{ Hello }
@@ -46,17 +46,17 @@ return

anyWord<noTag>
-anyWord/*comment*/ <noTag/>
+anyWord/*comment*/ <noTag/>
.<noTag>
-&<notag> | <noTag/>
-% /* comment*/ <noTag/>
+&<notag> | <noTag/>
+% /* comment*/ <noTag/>

// TODO: Fix this (comment before the tag name):
-var x = **/div>>;
+var x = </**/div>>;

// Tag after ":"
-annotation:
-annotation: text [ ]
+annotation:
+annotation: text [ ]
console.log("hello")

// Type assertion in tag
@@ -82,30 +82,55 @@ let k2 =
a={10} b="hi">
My Div

- {(name: string) =>
My name {name}
}
+ {(name: string) =>
My name {name}
}
;

-let k3 = initialValues={{ x: "y" }} nextValues={a => ({ x: a.x })} />; // No Error
+let k3 = initialValues={{ x: "y" }} nextValues={a => ({ x: a.x })} />; // No Error

// OK
let k1 = a={10} b="hi"><> /> />;
let k2 = a={10} b="hi"><> /> />;
let k3 = a={10} b="hi"><> /> />;
let k4 = a={10} b="hi"><> /> />;
// OK
let k1 =

Hello

world

;
-let k2 =

Hello

{(user: any) =>

{user.name}

}
;
+let k2 =

Hello

{(user: any) =>

{user.name}

}
;
let k3 =
{1} {"That is a number"}
;
let k4 = ;

// Empty tags
hello<>
-hello<string>
+hello<string>

<>; // no whitespace
< >; // lots of whitespace
< /*starting wrap*/ >/*ending wrap*/>; // comments in the tags
<>hi; // text inside
<>hi
bye
; // children
<>1<>2.12.23; // nested fragments
<>#; // # would cause scanning error if not in jsxtext
+
+// Tags after substitutions in templates
+${//comment
+ /*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>;
+
+// Don't highlight tags within variable declaration
+let myIdentity: <T>(arg: T) => T <noTag/> = />;
+var myIdentity: <U>(arg: U) => U = identity;
+const myIdentity: {<T>(arg: T): T} = identity;
+
+// Don't highlight tags within interfaces and classes
+interface GenericIdentityFn {
+ <T>(arg: T): T;
+ <noTag />
+}
+class Handler {
+ info: <T>(arg: T): T <noTag />;
+
+}
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 @@ -10,14 +10,16 @@ + + ]> - @@ -66,25 +72,75 @@ that contain: in the JavaScript XML file. --> - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -101,21 +157,25 @@ - + + + + + @@ -131,8 +191,6 @@ - - @@ -151,31 +209,13 @@ - - - - - - - - - - - - - - - - - - - - - + + + @@ -207,6 +247,25 @@ + + + + + + + + + + + + + + + + + + + @@ -270,8 +329,8 @@ - - + + @@ -301,6 +360,7 @@ + diff --git a/data/syntax/javascript.xml b/data/syntax/javascript.xml --- a/data/syntax/javascript.xml +++ b/data/syntax/javascript.xml @@ -6,7 +6,7 @@ - @@ -90,8 +90,6 @@ - - @@ -123,6 +121,7 @@ + @@ -146,7 +145,7 @@ - + @@ -209,6 +208,9 @@ + + + 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 @@ -10,15 +10,18 @@ + + + ]> - @@ -63,25 +70,27 @@ + that contain: in the TypeScript XML file. + NOTE: After the keyword "type" tags will not be highlighted ("TypeDeclaration" context). --> - - + + - + + @@ -92,15 +101,8 @@ - - - - - - - - - + + @@ -110,7 +112,7 @@ - + @@ -122,14 +124,15 @@ - + - + @@ -149,7 +152,7 @@ - + @@ -170,6 +173,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -195,27 +248,34 @@ + + + + + + + @@ -230,8 +290,6 @@ - - @@ -250,31 +308,13 @@ - - - - - - - - - - - - - - - - - - - - - + + + @@ -306,6 +346,25 @@ + + + + + + + + + + + + + + + + + + + @@ -369,8 +428,8 @@ - - + + @@ -401,6 +460,7 @@ + diff --git a/data/syntax/typescript.xml b/data/syntax/typescript.xml --- a/data/syntax/typescript.xml +++ b/data/syntax/typescript.xml @@ -2,14 +2,17 @@ + + + ]> primitives##JavaScript - object - + + string number boolean @@ -109,6 +116,7 @@ unknown undefined null + object @@ -1653,25 +1661,24 @@ - - + + - - - - - + - - + + + + + - - - @@ -1683,16 +1690,27 @@ - - - + + + + + + + + + + + + + + - + @@ -1705,23 +1723,32 @@ + + + + + - - - - - - + + + + + + + + + @@ -1740,33 +1767,33 @@ + - + - - - + - - - + + + @@ -1784,17 +1811,22 @@ - - + + + + + + - + @@ -1807,7 +1839,7 @@ - + @@ -1822,6 +1854,7 @@ + @@ -1837,7 +1870,7 @@ - + @@ -1873,7 +1906,7 @@ - + @@ -1996,7 +2029,8 @@ - + + @@ -2017,7 +2051,7 @@ - +