File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -1884,11 +1884,16 @@ namespace ts {
1884
1884
if ( ! token ) return undefined ;
1885
1885
const element = token . kind === SyntaxKind . GreaterThanToken && isJsxOpeningElement ( token . parent ) ? token . parent . parent
1886
1886
: isJsxText ( token ) ? token . parent : undefined ;
1887
- if ( element && ! tagNamesAreEquivalent ( element . openingElement . tagName , element . closingElement . tagName ) ) {
1887
+ if ( element && isUnclosedTag ( element ) ) {
1888
1888
return { newText : `</${ element . openingElement . tagName . getText ( sourceFile ) } >` } ;
1889
1889
}
1890
1890
}
1891
1891
1892
+ function isUnclosedTag ( { openingElement, closingElement, parent } : JsxElement ) : boolean {
1893
+ return ! tagNamesAreEquivalent ( openingElement . tagName , closingElement . tagName ) ||
1894
+ isJsxElement ( parent ) && tagNamesAreEquivalent ( openingElement . tagName , parent . openingElement . tagName ) && isUnclosedTag ( parent ) ;
1895
+ }
1896
+
1892
1897
function getSpanOfEnclosingComment ( fileName : string , position : number , onlyMultiLine : boolean ) : TextSpan | undefined {
1893
1898
const sourceFile = syntaxTreeCache . getCurrentSourceFile ( fileName ) ;
1894
1899
const range = formatting . getRangeOfEnclosingComment ( sourceFile , position ) ;
Original file line number Diff line number Diff line change 1
1
/// <reference path='fourslash.ts' />
2
2
3
- // @Filename : /a.tsx
3
+ // Using separate files for each example to avoid unclosed JSX tags affecting other tests.
4
+
5
+ // @Filename : /0.tsx
4
6
////const x = <div>/*0*/;
7
+
8
+ // @Filename : /1.tsx
5
9
////const x = <div> foo/*1*/ </div>;
10
+
11
+ // @Filename : /2.tsx
6
12
////const x = <div></div>/*2*/;
13
+
14
+ // @Filename : /3.tsx
7
15
////const x = <div/>/*3*/;
16
+
17
+ // @Filename : /4.tsx
8
18
////const x = <div>
9
19
//// <p>/*4*/
10
20
//// </div>
11
21
////</p>;
22
+
23
+ // @Filename : /5.tsx
12
24
////const x = <div> text /*5*/;
13
25
26
+ // @Filename : /6.tsx
27
+ ////const x = <div>
28
+ //// <div>/*6*/
29
+ ////</div>;
30
+
31
+ // @Filename : /7.tsx
32
+ ////const x = <div>
33
+ //// <p>/*7*/
34
+ ////</div>;
35
+
36
+ // @Filename : /8.tsx
37
+ ////const x = <div>
38
+ //// <div>/*8*/</div>
39
+ ////</div>;
40
+
14
41
verify . jsxClosingTag ( {
15
42
0 : { newText : "</div>" } ,
16
43
1 : undefined ,
17
44
2 : undefined ,
18
45
3 : undefined ,
19
46
4 : { newText : "</p>" } ,
47
+ 5 : { newText : "</div>" } ,
48
+ 6 : { newText : "</div>" } ,
49
+ 7 : { newText : "</p>" } ,
50
+ 8 : undefined ,
20
51
} ) ;
You can’t perform that action at this time.
0 commit comments