You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code is generated from templates, where we insert pieces of code that user defined.
Sometimes, that means we insert imports that import user functions from user (@ext) files.
Or, we address some identifier that user defined somewhere.
This can cause problems if for example they want to import function debug and we add that import into template that already imports our own debug -> we have a conflict!
While I expect Generator to go through significant changes in the future, where we should end up with a more sophisticated model of describing specific templates, I believe this problem will remain.
The only solution I see is prefixing (or suffixing) all user-made identifiers with something like wasp123, where the number would be unique per identifier (we can just assign those numbers incrementally).
Good example of problematic situation is when setup server function is inserted into server.js. What is that function was named config by user? It would conflict with the config import that we already have in that file.
Bad side of this is that names will be somewhat obfuscated, but on the other hand, if we just prefix or suffix them, that will be relatively straight forward to remove in case devs want to eject. When I say straight forward, I mean so for the devs themselves. If we want to remove prefix/suffix, it will be tricky since we need to detect conflicts and then ask dev to resolve them. So probably best to let them do it.
The text was updated successfully, but these errors were encountered:
sodic
changed the title
In Generator, ensure user defined identifiers don't get into conflict with rest of the template as they are inserted
Prevent name conflicts between internal and user-defined imports
Dec 29, 2022
Code is generated from templates, where we insert pieces of code that user defined.
Sometimes, that means we insert imports that import user functions from user (@ext) files.
Or, we address some identifier that user defined somewhere.
This can cause problems if for example they want to import function
debug
and we add that import into template that already imports our owndebug
-> we have a conflict!While I expect Generator to go through significant changes in the future, where we should end up with a more sophisticated model of describing specific templates, I believe this problem will remain.
The only solution I see is prefixing (or suffixing) all user-made identifiers with something like
wasp123
, where the number would be unique per identifier (we can just assign those numbers incrementally).Good example of problematic situation is when setup server function is inserted into server.js. What is that function was named
config
by user? It would conflict with theconfig
import that we already have in that file.Bad side of this is that names will be somewhat obfuscated, but on the other hand, if we just prefix or suffix them, that will be relatively straight forward to remove in case devs want to eject. When I say straight forward, I mean so for the devs themselves. If we want to remove prefix/suffix, it will be tricky since we need to detect conflicts and then ask dev to resolve them. So probably best to let them do it.
The text was updated successfully, but these errors were encountered: