-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
[react] Fix scoping issue with sx dynamic value transform #286
Conversation
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.
Looks good. Is it possible to add a test case for this?
Not specifically for this. The motivation here was also that existing tests do not break regardless of the internal changes. |
I see. |
// eslint-disable-next-line no-nested-ternary | ||
const cssKey = key.isIdentifier() | ||
? key.node.name | ||
: key.isStringLiteral() | ||
? key.node.value | ||
: ''; |
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.
better to remove ternary or remove this lint config.
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.
For this sample component -
In the current sx transform, we were transforming the dynamic part to an arrow function with the same arguments that it was using internally and then later in the
sx.ts
based wyw transform, we were just replacing the arrow function with just its body (to be same as user code). This was being done to play well with wyw were it throws an error if it tries to evaluate an object that references local variables.Current transform -
This did not play well with minifiers where the variables in transformed function would be renamed like -
So later when we were trying to revert back to user code, it'll just be
resulting in an issue trying to use a variable that does not exist. This was more apparent when using webpack with it's terser based uglifier.
This PR fixes the issue by serializing the AST as a string and later on deserializing it and generating the code from the AST.
Partially fixes #43597