objectName returns a JS expression that refers to the given object. If the object hasn't been previously assigned a JS variable name, it will be allocated as needed.
(o types.Object)
| 419 | // object hasn't been previously assigned a JS variable name, it will be |
| 420 | // allocated as needed. |
| 421 | func (fc *funcContext) objectName(o types.Object) string { |
| 422 | if isPkgLevel(o) { |
| 423 | var nestTArgs []types.Type |
| 424 | if typeparams.FindNestingFunc(o) == fc.instance.Object { |
| 425 | // Only set the nest type arguments for objects nested in this funcContext. |
| 426 | nestTArgs = fc.instance.TArgs |
| 427 | } |
| 428 | fc.pkgCtx.DeclareDCEDep(o, nestTArgs, nil) |
| 429 | |
| 430 | if o.Pkg() != fc.pkgCtx.Pkg || (isVarOrConst(o) && o.Exported()) { |
| 431 | return fc.pkgVar(o.Pkg()) + "." + o.Name() |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | name, ok := fc.assignedObjectName(o) |
| 436 | if !ok { |
| 437 | pkgLevel := isPkgLevel(o) |
| 438 | name = fc.newVariable(o.Name(), pkgLevel) |
| 439 | if pkgLevel { |
| 440 | fc.root().objectNames[o] = name |
| 441 | } else { |
| 442 | fc.objectNames[o] = name |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | if v, ok := o.(*types.Var); ok && fc.pkgCtx.escapingVars[v] { |
| 447 | return name + "[0]" |
| 448 | } |
| 449 | return name |
| 450 | } |
| 451 | |
| 452 | // knownInstances returns a list of known instantiations of the object. |
| 453 | // |
no test coverage detected