Skip to content

Conversation

@AGMETEOR
Copy link
Contributor

Fixes #37306


let y = < Baz >Hello
~~~~~~~~~
!!! error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of these errors by adding // @jsx: react at the top of tests/cases/compiler/errorSpanForUnclosedJsxTag.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for helping me sort this out.

else {
parseErrorAtRange(openingTag.tagName, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
// We want the error to span only property identifier "Foo.Bar" e.g in < Foo.Bar >...
const tag = openingTag.tagName as any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this as any necessary?

Copy link
Contributor Author

@AGMETEOR AGMETEOR Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler was complaining about missing properties on tagName. I tried using some types from the types.ts file but that only partially solved the warnings. With your suggested changes implemented, this is not needed anymore and I have removed it.

parseErrorAtRange(openingTag.tagName, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
// We want the error to span only property identifier "Foo.Bar" e.g in < Foo.Bar >...
const tag = openingTag.tagName as any;
let start = tag.pos;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better/simpler way would be to just write

const start = skipTrivia(sourceText, openingTag.tagName.pos);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed it to use skipTrivia instead. Thanks a lot for the review.

start = tag.end - tag.escapedText.length;
}

parseErrorAtRange({ pos: start, end: tag.end }, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
Copy link
Member

@DanielRosenwasser DanielRosenwasser Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a parseErrorAt which takes a start/end pair and avoids an extra allocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed this as well to use parseErrorAt. Thanks for reviewing :)

@DanielRosenwasser
Copy link
Member

The current approach here hits all the right places - I just think there are a few fixes to take care of and once those are addressed, we can merge it in.

@AGMETEOR
Copy link
Contributor Author

The current approach here hits all the right places - I just think there are a few fixes to take care of and once those are addressed, we can merge it in.

Let me work on implementing your feedback. Thanks for the review.

@AGMETEOR
Copy link
Contributor Author

hello @DanielRosenwasser , I worked on your feedback. Issue now is that all tests pass locally for some reason the pipeline fails due to some npm error.

@@ -0,0 +1,12 @@
// @jsx: react
import React from "react";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace this with declare const React: any to avoid import errors, especially since this is a syntactic test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot.

@DanielRosenwasser
Copy link
Member

I'm not sure why this was running into CI errors but they seem to be passing now!

@AGMETEOR
Copy link
Contributor Author

I'm not sure why this was running into CI errors but they seem to be passing now!

Not sure as well. Thanks a lot for the help. I only started looking at the TS compiler code last week :)

@DanielRosenwasser DanielRosenwasser merged commit a83ce33 into microsoft:master Mar 19, 2020
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Poor error span for unclosed JSX tags in the presence of whitespace/comments

2 participants