Skip to content

Commit

Permalink
Fix the ambiguity of typescript and jsx syntax (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuezk authored Dec 19, 2019
1 parent 0d07dc8 commit b2ace0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions after/syntax/typescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ if !hlexists('typescriptTypeCast')
\ fold
endif

syntax cluster typescriptExpression add=jsxRegion,typescriptParens

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

let b:current_syntax = 'typescript.tsx'

Expand Down
4 changes: 4 additions & 0 deletions test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React from 'react';

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

const foo = <string>bar;
const foo = <string>bar;
</string>

function test() {
const a = 1;
let foo;
Expand Down

0 comments on commit b2ace0c

Please sign in to comment.