-
Notifications
You must be signed in to change notification settings - Fork 2k
normalize special characters in module names to allow variable access #14353
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
normalize special characters in module names to allow variable access #14353
Conversation
|
@sgvictorino is on fire 🔥!!! We appreciate all your PRs. Thanks. |
|
Thanks! But there is one thing I'm not sure: module foo-bar { export const baz = 1 }
use foo-bar
$foo-bar.bazPersonally I think it's better to export use |
|
How will this play out with |
The filename stem must be a valid module name. Out of the invalid identifier characters, someone might try to name files like I'm also fine with normalizing certain symbols to a valid variable name like @WindSoilder prefers. The "did you mean" fuzzy search helps with that UX. |
|
I think normalizing would be the best option, since then it can align with typical variable name rules and can possibly catch more cases than just hyphens and the dot issue you bring up. |
|
Yeah, @sgvictorino can you update the code to use |
99f4337 to
c446b74
Compare
WindSoilder
left a comment
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.
Sorry for a delay. Finally I take time to review it.
And I think the solution can be easier.
44f74bc to
5ddc69d
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.
Thanks! Just one thing left.
# User-Facing Changes
- Special characters in module names are replaced with underscores when
importing constants, preventing "expected valid variable name":
```nushell
> module foo-bar { export const baz = 1 }
> use foo-bar
> $foo_bar.baz
```
- "expected valid variable name" errors now include a suggestion list:
```nushell
> module foo-bar { export const baz = 1 }
> use foo-bar
> $foo-bar
Error: nu::parser::parse_mismatch_with_did_you_mean
× Parse mismatch during operation.
╭─[entry #1:1:1]
1 │ $foo-bar;
· ────┬───
· ╰── expected valid variable name. Did you mean '$foo_bar'?
╰────
```
5ddc69d to
7aedc8b
Compare
WindSoilder
left a comment
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.
Thank you! LGTM
Fixes #14252
User-Facing Changes
importing constants, preventing "expected valid variable name":