-
Notifications
You must be signed in to change notification settings - Fork 840
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
feat: add code transformer to <Demo>
component
#7894
feat: add code transformer to <Demo>
component
#7894
Conversation
…rapper so that EuiDataGrid and other components look correct
💚 Build Succeeded
|
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.
🚢 🐈⬛ Works like a charm! Awesome and straight forward code transformer! 🤖
} | ||
|
||
// If the demo is more than just JSX wrap in an immediately invoked function expression | ||
return `(() => { ${code} })()`; |
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.
🧠
const COMPONENT_ONLY_REGEX = /^\(?</; | ||
|
||
/** | ||
* Transforms input JS/TS source code to a react-live compatible syntax. |
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.
Thanks for the great description, that's really helpful for understanding! 🙏
Summary
Resolves #7866.
This adds a custom code transformer to our
<Demo>
component that makes the existing component examples work withreact-live
. The major factor was thatreact-live
only supports code that's just a JSX component or render function declaration. There's no way to define variables outside of the render function or have import/export statements.The new code transformer removes any import statements because all externals should always come from the
scope
, and wraps the source code in an IIFE to support defining variables and functions outside of the render function as we often do in our examples.QA