Skip to content

Commit

Permalink
[TypeScript] Fix generic parameters in namespaced types
Browse files Browse the repository at this point in the history
  • Loading branch information
Thom1729 committed Oct 30, 2023
1 parent dbb6471 commit 3afa3ac
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
14 changes: 10 additions & 4 deletions JavaScript/TypeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,9 @@ contexts:
push:
- match: '{{identifier_name}}'
scope: support.class.js
set: ts-type-expression-end-no-line-terminator
set:
- ts-type-expression-end-no-line-terminator
- ts-optional-generic-type-arguments

- match: extends{{identifier_break}}
scope: keyword.operator.type.extends.js
Expand Down Expand Up @@ -1063,9 +1065,13 @@ contexts:
ts-type-basic:
- match: '{{identifier_name}}'
scope: support.class.js
set:
- include: ts-generic-type-arguments
- include: else-pop
set: ts-optional-generic-type-arguments

ts-optional-generic-type-arguments:
- match: $
pop: 1
- include: ts-generic-type-arguments
- include: else-pop

ts-type-template-string:
- match: '`'
Expand Down
9 changes: 9 additions & 0 deletions JavaScript/tests/syntax_test_tsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ let x : T.U<V>;
// ^^^ meta.generic
// ^ support.class

let x : T.U
// ^^^ meta.type
// ^ support.class
// ^ punctuation.accessor
// ^ support.class

<V />;
// <- meta.jsx - meta.type

// This is invalid TSX as the TypeScript type assertion is parsed as a JSX tag
let strLength: number = (<string>someValue).length; // </string> );
// ^^^^^^^^ meta.tag - meta.assertion
Expand Down
32 changes: 32 additions & 0 deletions JavaScript/tests/syntax_test_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,38 @@ let x: import ( "foo" ) . Bar ;
// ^ punctuation.accessor
// ^^^ support.class

let x: T.U;
// ^^^^ meta.type
// ^ support.class
// ^ punctuation.accessor
// ^ support.class
// ^ punctuation.terminator.statement

let x: T.U[];
// ^^^^ meta.type
// ^ support.class
// ^ punctuation.accessor
// ^ support.class
// ^^ storage.modifier.array
// ^ punctuation.terminator.statement

let x: T.U<V>[];
// ^^^^ meta.type
// ^ support.class
// ^ punctuation.accessor
// ^ support.class
// ^^^ meta.generic
// ^^ storage.modifier.array
// ^ punctuation.terminator.statement

let x: T.U
// ^^^^ meta.type
// ^ support.class
// ^ punctuation.accessor
// ^ support.class
[];
//<- meta.sequence - meta.type

foo < bar > ();
// ^^^ variable.function
// ^^^^^^^ meta.generic
Expand Down

0 comments on commit 3afa3ac

Please sign in to comment.