Skip to content

Commit b2ace0c

Browse files
authored
Fix the ambiguity of typescript and jsx syntax (#115)
1 parent 0d07dc8 commit b2ace0c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

after/syntax/typescript.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ if !hlexists('typescriptTypeCast')
4646
\ fold
4747
endif
4848

49-
syntax cluster typescriptExpression add=jsxRegion,typescriptParens
50-
5149
runtime syntax/jsx_pretty.vim
50+
syntax cluster typescriptExpression add=jsxRegion,typescriptParens,tsCast
51+
" Fix type casting ambiguity with JSX syntax
52+
syntax match typescriptTypeBrackets +[<>]+ contained
53+
syntax match typescriptTypeCast +<\([_$A-Za-z0-9]\+\)>\%(\s*\%([_$A-Za-z0-9]\+\s*;\?\|(\)\%(\_[^<]*</\1>\)\@!\)\@=+ contains=typescriptTypeBrackets,@typescriptType
5254

5355
let b:current_syntax = 'typescript.tsx'
5456

test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import React from 'react';
22

33
const head = <T>(arr: T[]): T => arr[0]
44

5+
const foo = <string>bar;
6+
const foo = <string>bar;
7+
</string>
8+
59
function test() {
610
const a = 1;
711
let foo;

0 commit comments

Comments
 (0)