Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4545,7 +4545,11 @@ namespace ts {
parseErrorAtRange(openingTag, Diagnostics.JSX_fragment_has_no_corresponding_closing_tag);
}
else {
parseErrorAtRange(openingTag.tagName, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
// We want the error span to cover only 'Foo.Bar' in < Foo.Bar >
// or to cover only 'Foo' in < Foo >
const tag = openingTag.tagName;
const start = skipTrivia(sourceText, tag.pos);
parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
}
return undefined;
case SyntaxKind.LessThanSlashToken:
Expand Down
23 changes: 23 additions & 0 deletions tests/baselines/reference/errorSpanForUnclosedJsxTag.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
tests/cases/compiler/errorSpanForUnclosedJsxTag.tsx(9,14): error TS17008: JSX element 'Foo.Bar' has no corresponding closing tag.
tests/cases/compiler/errorSpanForUnclosedJsxTag.tsx(11,13): error TS17008: JSX element 'Baz' has no corresponding closing tag.
tests/cases/compiler/errorSpanForUnclosedJsxTag.tsx(11,23): error TS1005: '</' expected.


==== tests/cases/compiler/errorSpanForUnclosedJsxTag.tsx (3 errors) ====
declare const React: any

let Foo = {
Bar() {}
}

let Baz = () => {}

let x = < Foo.Bar >Hello
~~~~~~~
!!! error TS17008: JSX element 'Foo.Bar' has no corresponding closing tag.

let y = < Baz >Hello
~~~
!!! error TS17008: JSX element 'Baz' has no corresponding closing tag.

!!! error TS1005: '</' expected.
21 changes: 21 additions & 0 deletions tests/baselines/reference/errorSpanForUnclosedJsxTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [errorSpanForUnclosedJsxTag.tsx]
declare const React: any

let Foo = {
Bar() {}
}

let Baz = () => {}

let x = < Foo.Bar >Hello

let y = < Baz >Hello

//// [errorSpanForUnclosedJsxTag.js]
var Foo = {
Bar: function () { }
};
var Baz = function () { };
var x = React.createElement(Foo.Bar, null,
"Hello let y = ",
React.createElement(Baz, null, "Hello"));
23 changes: 23 additions & 0 deletions tests/baselines/reference/errorSpanForUnclosedJsxTag.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
=== tests/cases/compiler/errorSpanForUnclosedJsxTag.tsx ===
declare const React: any
>React : Symbol(React, Decl(errorSpanForUnclosedJsxTag.tsx, 0, 13))

let Foo = {
>Foo : Symbol(Foo, Decl(errorSpanForUnclosedJsxTag.tsx, 2, 3))

Bar() {}
>Bar : Symbol(Bar, Decl(errorSpanForUnclosedJsxTag.tsx, 2, 11))
}

let Baz = () => {}
>Baz : Symbol(Baz, Decl(errorSpanForUnclosedJsxTag.tsx, 6, 3))

let x = < Foo.Bar >Hello
>x : Symbol(x, Decl(errorSpanForUnclosedJsxTag.tsx, 8, 3))
>Foo.Bar : Symbol(Bar, Decl(errorSpanForUnclosedJsxTag.tsx, 2, 11))
>Foo : Symbol(Foo, Decl(errorSpanForUnclosedJsxTag.tsx, 2, 3))
>Bar : Symbol(Bar, Decl(errorSpanForUnclosedJsxTag.tsx, 2, 11))

let y = < Baz >Hello
>Baz : Symbol(Baz, Decl(errorSpanForUnclosedJsxTag.tsx, 6, 3))

29 changes: 29 additions & 0 deletions tests/baselines/reference/errorSpanForUnclosedJsxTag.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/compiler/errorSpanForUnclosedJsxTag.tsx ===
declare const React: any
>React : any

let Foo = {
>Foo : { Bar(): void; }
>{ Bar() {}} : { Bar(): void; }

Bar() {}
>Bar : () => void
}

let Baz = () => {}
>Baz : () => void
>() => {} : () => void

let x = < Foo.Bar >Hello
>x : any
>< Foo.Bar >Hellolet y = < Baz >Hello : any
>Foo.Bar : () => void
>Foo : { Bar(): void; }
>Bar : () => void

let y = < Baz >Hello
>< Baz >Hello : any
>Baz : () => void
> : any
> : any

12 changes: 12 additions & 0 deletions tests/cases/compiler/errorSpanForUnclosedJsxTag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @jsx: react
declare const React: any

let Foo = {
Bar() {}
}

let Baz = () => {}

let x = < Foo.Bar >Hello

let y = < Baz >Hello