-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve parsing for JSX blocks (including inline) #396
Conversation
This pull request is automatically deployed with Now. |
const openTag = '<[A-Za-z]*[A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>' | ||
const closeTag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>' | ||
const openTag = '<[A-Za-z]*[A-Za-z0-9\\.\\-]*' + attribute + '*\\s*\\/?>' | ||
const closeTag = '<\\/[A-Za-z][A-Za-z0-9\\.\\-]*\\s*>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows for Component.Foo
style components.
@@ -7,7 +7,7 @@ const attributeName = '[a-zA-Z_:][a-zA-Z0-9:._-]*' | |||
const unquoted = '[^"\'=<>`\\u0000-\\u0020]+' | |||
const singleQuoted = "'[^']*'" | |||
const doubleQuoted = '"[^"]*"' | |||
const objectProps = '{{[^}]*}}' | |||
const jsProps = '{[^\n]*}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accept anything inside props={/* ... */}
to handle everything from functions, to string interpolation, to nested objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit, otherwise good!
Co-Authored-By: johno <[email protected]>
* Implement support for Some.Component style JSX blocks * Add failing test for string interpolation * Add failing test for js functions as props * Add failing test for js functions as props with returns * Make value parsing for JSX props more flexible * Don't lint fixtures file * Add nested object props fixture * Add another fixture for randomly placed brackets * Add link shortcut to fixture * Remove object props since it is a subset of js props * Update packages/remark-mdx/test/fixtures/inline-parsing.js Co-Authored-By: johno <[email protected]>
JSX tag parsing was too strict for props, so it caused multiple types of JSX blocks to be missed and then escapes. Ultimately, essentially any syntax and characters can existing in a JSX prop so we just keep waiting for the matching closing curly brace.
This also adds many more complex usages of inline JSX fixtures that are being tested against.