diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7a1efbdec5f8c..4bc1f217b53ed 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6011,7 +6011,7 @@ namespace Parser { // 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); + const start = Math.min(skipTrivia(sourceText, tag.pos), tag.end); parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName)); } return undefined; diff --git a/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.errors.txt b/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.errors.txt new file mode 100644 index 0000000000000..640a20cc6f435 --- /dev/null +++ b/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/a.js(1,3): error TS17008: JSX element '' has no corresponding closing tag. +tests/cases/compiler/a.js(1,4): error TS1003: Identifier expected. +tests/cases/compiler/a.js(1,5): error TS1005: '...' expected. +tests/cases/compiler/a.js(3,1): error TS1005: ' + +!!! error TS17008: JSX element '' has no corresponding closing tag. + ~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: '...' expected. + + + +!!! error TS1005: ' + + + +//// [a.js] +!< {...}> + +; diff --git a/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.symbols b/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.symbols new file mode 100644 index 0000000000000..9ad03d63ec3e1 --- /dev/null +++ b/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/a.js === + +!< {:> + + diff --git a/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.types b/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.types new file mode 100644 index 0000000000000..60cd86bd73b15 --- /dev/null +++ b/tests/baselines/reference/parseJsxElementInUnaryExpressionNoCrash3.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/a.js === +!< {:> +>!< {:> : boolean +>< {:> : any +> : any +> : any + + +> : any + diff --git a/tests/cases/compiler/parseJsxElementInUnaryExpressionNoCrash3.ts b/tests/cases/compiler/parseJsxElementInUnaryExpressionNoCrash3.ts new file mode 100644 index 0000000000000..82316d060773b --- /dev/null +++ b/tests/cases/compiler/parseJsxElementInUnaryExpressionNoCrash3.ts @@ -0,0 +1,5 @@ +// @allowJs: true +// @outDir: ./out +// @filename: a.js +!< {:> +