{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/jsx/issues/28","labels_url":"https://api.github.com/repos/facebook/jsx/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/facebook/jsx/issues/28/comments","events_url":"https://api.github.com/repos/facebook/jsx/issues/28/events","html_url":"https://github.com/facebook/jsx/issues/28","id":58426897,"number":28,"title":"Non-quoted multi-line JS string literal parsing instead of JSX text","user":{"login":"syranide","id":1714255,"avatar_url":"https://avatars.githubusercontent.com/u/1714255?v=3","gravatar_id":"","url":"https://api.github.com/users/syranide","html_url":"https://github.com/syranide","followers_url":"https://api.github.com/users/syranide/followers","following_url":"https://api.github.com/users/syranide/following{/other_user}","gists_url":"https://api.github.com/users/syranide/gists{/gist_id}","starred_url":"https://api.github.com/users/syranide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syranide/subscriptions","organizations_url":"https://api.github.com/users/syranide/orgs","repos_url":"https://api.github.com/users/syranide/repos","events_url":"https://api.github.com/users/syranide/events{/privacy}","received_events_url":"https://api.github.com/users/syranide/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-20T23:51:13Z","updated_at":"2015-02-21T11:32:48Z","closed_at":null,"body":"**I propose the following:**\r\nTrim leading spaces and tabs after newlines (indentation) and then apply regular string literal parsing (but over multiple lines and without quotes). It may be advisable to trim tailing spaces and tabs too to avoid source code incompatibilities with editors auto-trimming on save.\r\n\r\n**There are lots of benefits to this:**\r\n1. (X)HTML-entities are now a thing of the past. JSX attribute strings (HTML) and JSX expression container strings (JS) are now parsed the same way.\r\n2. You can write complex strings without breaking texts up into separate children (`foo{'}'}bar`) or having to resort to using unintuitive HTML-entities (`foo&#125;bar`), just escape with `\\`.\r\n3. We can intuitively and easily control whitespace by simply escaping `\\<space>` (`\\<eol>` gives you a space too).\r\n4. A single-line JSX text behaves identically to its counter-part JS string literal.\r\n\r\n**The two practical issues I see are:**\r\n1. `&nbsp;` is common and `\\xA0` is not an overly obvious escape code. This applies if you're dealing with JS anyway, but most are probably only used to typing it as a HTML-entity inside JSX. It's a trade-off (perhaps editors will catch-up and actually render a hint for literal nbsp chars with a little persuasion too).\r\n2. It makes the most technical sense to drop the current implicit space between newlines (and I'm all for it) but it could make it seem a bit alien to some users, implicit space can be kept and will then have to be omitted if the char before the newline is a white-space char.\r\n\r\n```\r\n<>  foo  </>\r\n=> '  foo  '\r\n```\r\n```\r\n<>\r\n  foo\r\n</>\r\n=> 'foo'\r\n```\r\n```\r\n<>\r\n\\  foo \\\r\n</>\r\n=> '  foo  '\r\n```\r\n```\r\n<>\r\n  foo\r\n  bar\r\n</>\r\n=> '  foobar  '\r\n```\r\n```\r\n<>\r\n  foo\\\r\n  bar\r\n</>\r\n=> 'foo bar'\r\n```\r\n```\r\n<>\r\n  foo\\nbar\r\n</>\r\n=> 'foo\\nbar'\r\n```\r\n```\r\n<>\r\n  foo\\n\r\n  bar\r\n</>\r\n=> 'foo\\nbar'\r\n```\r\n```\r\n<>\r\n  foo\\<\\{\r\n  bar\r\n</>\r\n=> 'foo<{bar'\r\n```\r\n\r\nWhat's not to like?\r\n**PS.** It should be noted that this is easily non-destructively codemod:able too.\r\n\r\ncc @sebmarkbage @jeffmo @zpao @spicyj "},"comment":{"url":"https://api.github.com/repos/facebook/jsx/issues/comments/75367911","html_url":"https://github.com/facebook/jsx/issues/28#issuecomment-75367911","issue_url":"https://api.github.com/repos/facebook/jsx/issues/28","id":75367911,"user":{"login":"syranide","id":1714255,"avatar_url":"https://avatars.githubusercontent.com/u/1714255?v=3","gravatar_id":"","url":"https://api.github.com/users/syranide","html_url":"https://github.com/syranide","followers_url":"https://api.github.com/users/syranide/followers","following_url":"https://api.github.com/users/syranide/following{/other_user}","gists_url":"https://api.github.com/users/syranide/gists{/gist_id}","starred_url":"https://api.github.com/users/syranide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syranide/subscriptions","organizations_url":"https://api.github.com/users/syranide/orgs","repos_url":"https://api.github.com/users/syranide/repos","events_url":"https://api.github.com/users/syranide/events{/privacy}","received_events_url":"https://api.github.com/users/syranide/received_events","type":"User","site_admin":false},"created_at":"2015-02-21T11:32:48Z","updated_at":"2015-02-21T11:32:48Z","body":"> Is it true that if we implement this, is it true that the parser would accept any HTML content (i.e. legacy content) as correct? The opposite is not true because `\\<` and `\\{` cannot be valid in HTML content.\r\n>\r\n> I think that's the most pervasive arguments since it allows a simple syntax highlighter to deal with either model. Any HTML content transpiler would simply be a subset in acceptable input.\r\n\r\nI'm not 100% sure what you mean here.\r\n\r\nI'm not aware of any JS/HTML/XML-parsers out there that play even remotely nice with JSX code (not that I have tested many). There's enough flexibility in JSX that they're all easily confused by many perfectly normal JSX code practices and incorrectly highlight the remainder of the source. Parsing JSX as HTML works for the most simplistic examples but nothing else, or am I missing something?\r\n\r\n> Of course, we should do the same for attributes then.\r\n\r\nYeah, that was implied :)\r\n\r\n> Is it possible to repurpose the same whitespace logic from multiline string literals in ES6 or would it not make sense?\r\n\r\nAFAIK ES6 multiline string literals copy text content verbatim, including leading and trailing whitespace and even LR/CRLF as-is, which leads to bad practices like [this](http://stackoverflow.com/questions/25924057/multiline-strings-that-dont-break-indentation) for certain use-cases. The whitespace rules I defined above are the same used by JSX today (but managing whitespace is now easy and uninstrusive).\r\n\r\nThe problem as I see it is whitespace *cannot* be optimized away post-process. You also prevent the developer from freely indenting and structuring text content and you end up with the horrible HTML line-stuffing practices in scenarios where newline/indentation introduced unintended whitespace.\r\n\r\nThe rules I've defined above allow **any string value to be easily represented at any intendentation and over any number of lines**, which HTML nor ES6 multiline strings are unable to.\r\n\r\n*I would quote @jeffmo if I still had his message, following my initial whitespace PR for JSX he was surprised at just how much unintended whitespace would previously end up in the output.*\r\n\r\n----\r\n\r\nJust to illustrate, as parsed by HTML (and ES6 multiline string literal):\r\n\r\n```\r\n<div>\r\n  Foo\r\n\r\n  Bar\r\n</div>\r\n=> '\\n  Foo\\n\\n  Bar\\n' (OR)\r\n=> '\\r\\n  Foo\\r\\n\\r\\n  Bar\\r\\n'\r\n```\r\n\r\nThat's probably not what you meant right? Again, it cannot be optimized away post-process.\r\n"}}