Skip to content

Conversation

@mjambon
Copy link
Contributor

@mjambon mjambon commented Oct 6, 2020

Typescript supports unescaped newlines within string literals used as jsx attributes, like this:

<a b="hello
world">

(same code in typescript playground)

This PR adds supports for unescaped newlines in tsx attribute values.

Another, simpler solution would be to directly modify the definition of $.string in the javascript grammar. Having unescaped newlines in any string literal would not be legal javascript or typescript (outside of tsx attributes) but I don't see a big risk in doing so.

@patrickt
Copy link

patrickt commented Oct 6, 2020

Having unescaped newlines in any string literal would not be legal javascript or typescript (outside of tsx attributes) but I don't see a big risk in doing so

We tend to err on the side of simpler grammars rather than strict conformance, so this seems like a good idea if it makes the grammar simpler and (hopefully) smaller.

@maxbrunsfeld
Copy link
Contributor

Yeah, I'm guessing that if it's allowed in TSX, it may be allowed by some (non-typescript) JSX preprocessors like Babel. So I think it would make sense to just add this in the JavaScript grammar, either by modifying string, or creating a special jsx_string rule (which could be aliased as string).

@mjambon
Copy link
Contributor Author

mjambon commented Oct 6, 2020

Great, I'll move this to javascript (as a jsx_string, probably)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants