mirror of
https://github.com/vlang/v.git
synced 2025-09-15 10:27:19 -04:00
fmt: simplify const name formatting (#21143)
This commit is contained in:
parent
d5afce3171
commit
a63a7333cf
@ -2248,18 +2248,14 @@ pub fn (mut f Fmt) ident(node ast.Ident) {
|
|||||||
// This makes it clear that a module const is being used
|
// This makes it clear that a module const is being used
|
||||||
// (since V's consts are no longer ALL_CAP).
|
// (since V's consts are no longer ALL_CAP).
|
||||||
// ^^^ except for `main`, where consts are allowed to not have a `main.` prefix.
|
// ^^^ except for `main`, where consts are allowed to not have a `main.` prefix.
|
||||||
mod := f.cur_mod
|
if obj := f.file.global_scope.find('${f.cur_mod}.${node.name}') {
|
||||||
full_name := mod + '.' + node.name
|
|
||||||
if obj := f.file.global_scope.find(full_name) {
|
|
||||||
if obj is ast.ConstField {
|
if obj is ast.ConstField {
|
||||||
// "v.fmt.foo" => "fmt.foo"
|
// "v.fmt.foo" => "fmt.foo"
|
||||||
vals := full_name.split('.')
|
const_name := node.name.all_after_last('.')
|
||||||
mod_prefix := vals[vals.len - 2]
|
if f.cur_mod == 'main' {
|
||||||
const_name := vals.last()
|
|
||||||
if mod_prefix == 'main' {
|
|
||||||
f.write(const_name)
|
f.write(const_name)
|
||||||
} else {
|
} else {
|
||||||
short := mod_prefix + '.' + const_name
|
short := '${f.cur_mod.all_after_last('.')}.${const_name}'
|
||||||
f.write(short)
|
f.write(short)
|
||||||
f.mark_import_as_used(short)
|
f.mark_import_as_used(short)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user