-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Replace invalid variable characters for import name #4293
Conversation
Hi @JingLi1998! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Thanks for looking at this! The approach does not seem robust though, since there may be other characters that are valid for filenames for but not for JS variables. What about using |
@captbaritone thank you for the suggestion it makes a lot of sense. I've updated the implementation to use the existing variable and added a prefix of Here is the output when testing locally:
|
@@ -1860,12 +1860,14 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> { | |||
provider.module_path().to_str().unwrap().intern(), | |||
) | |||
}; | |||
|
|||
let variable_name = ["__relay_internal__pv__", &provider.original_variable_name.to_string()].join("").intern(); |
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.
Can we replace the slice+join with a simpler concatenation using the +
operator?
Also, can we go with <variableName>_provider
. A suffix instead of a prefix and avoid the cryptic "pv" dimminution.
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.
@captbaritone Thanks for the feedback I've updated it to reflect the changes you requested. I had assumed that the __relay_internal__pv
was the preferred way to prefix variables since I saw it used elsewhere in the codebase 😅
@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@captbaritone merged this pull request in 04005db. |
Closes: #4294
When using provided variables, with ESM, the Relay compiler incorrectly assumes that the module path can also be reused for the default import name.
This is not valid Javascript as variables cannot use '.' or '-' characters.
To fix, simply replace '.' and '-' with underscores.
Before:
After:
I'm unfamiliar with Rust so am unsure if there is a better approach.