HerringtonDarkholme / yats.vim

Yet Another TypeScript Syntax: The most advanced TypeScript Syntax Highlighting in Vim
Vim License
648 stars 68 forks source link

Whitespace before type parameter list breaks parsing #289

Open tobil4sk opened 4 weeks ago

tobil4sk commented 4 weeks ago

The syntax does not accept type parameters if there is a space before <.

image

This patch seems to solve the issue:

--- a/syntax/ts-common/type.vim
+++ b/syntax/ts-common/type.vim
@@ -26,7 +26,7 @@ syntax match typescriptGenericDefault /=/
 " class A extend B<T> {} // ClassBlock
 " func<T>() // FuncCallArg
 syntax region typescriptTypeArguments matchgroup=typescriptTypeBrackets
-  \ start=/\></ end=/>/
+  \ start=/</ end=/>/
   \ contains=@typescriptType
   \ nextgroup=typescriptFuncCallArg,@typescriptTypeOperator
   \ contained skipwhite

image

HerringtonDarkholme commented 3 weeks ago

This is done on purpose. func < T > (3) is a valid JavaScript and users should avoid adding undesirable spaces.

tobil4sk commented 3 weeks ago

func<T>(3) is also valid JavaScript syntax. The TypeScript compiler intentionally parses both as a generic call, regardless of spaces: https://github.com/Microsoft/TypeScript/issues/1121.