-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Do not replace starting digit with underscore when making identifier #82786
Do not replace starting digit with underscore when making identifier #82786
Conversation
aa3daf8
to
4ad5ee3
Compare
4ad5ee3
to
5cd7ca0
Compare
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.
Tested locally, it works as expected. Results from drag-and-dropping from the FileSystem dock while holding Ctrl:
const _12345 = preload("res://12345.tscn")
const _0 = preload("res://0.gd")
const __ = preload("res://__.tscn")
const _ = preload("res://_.tscn")
validate_identifier()
is only used in the script editor and for script template creation. The method isn't exposed to scripting, so it should be fine to cherry-pick for 4.1
(given the small behavior change).
@@ -3974,24 +3974,22 @@ bool String::is_absolute_path() const { | |||
} | |||
} | |||
|
|||
static _FORCE_INLINE_ bool _is_valid_identifier_bit(int p_index, char32_t p_char) { | |||
if (p_index == 0 && is_digit(p_char)) { | |||
return false; // No start with number plz. |
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.
I'll miss that comment. 👀
I'm a bit worried about the impact this may have on compatibility, notably for the import pipeline. We already broke compat in 4.1 by changing the logic that would remove CC @godotengine/import to help assess this. |
If it helps, searching on my end, it seems that
Thus, it does not provide names for nodes. Modifying it should not affect existing scripts. And as far as I know it is not involved in importing anything. I also modified At least, I don't expect issues, but of course I might be mistaken. Addendum: By searching on github (to find the links) I also found this: #67701 |
Sounds good, thanks for researching it. I expected it to be used way more, but I guess we have other similar methods in Node that partially duplicate this functionality. |
Thanks! |
Cherry-picked for 4.1.4. |
This pull request modifies
validate_identifier
to add an underscore when theString
stars with a digit (instead of replacing the digit with an underscore, which was the old behavior). Thevalidate_identifier
test cases has been updated accordingly.Since
validate_identifier
is modified, the helper method_is_valid_identifier_bit
is not necessary, to remove itis_valid_identifier
was also modified to not use it.Fixes #82773