()
| 318 | } |
| 319 | |
| 320 | func (ts *Typescript) parseGolangIdentifiers() error { |
| 321 | // Look for comments that indicate to ignore a type for typescript generation. |
| 322 | // Comment format to skip typescript generation: `@typescript-ignore <ignored_type>` |
| 323 | ignoreRegex := regexp.MustCompile("@typescript-ignore[:]?(?P<ignored_types>.*)") |
| 324 | |
| 325 | refPkgs := make([]*packages.Package, 0, len(ts.parsed.Pkgs)) |
| 326 | genPkgs := make([]*packages.Package, 0, len(ts.parsed.Pkgs)) |
| 327 | for _, pkg := range ts.parsed.Pkgs { |
| 328 | if ts.parsed.Reference[pkg.PkgPath] { |
| 329 | refPkgs = append(refPkgs, pkg) |
| 330 | continue |
| 331 | } |
| 332 | genPkgs = append(genPkgs, pkg) |
| 333 | } |
| 334 | |
| 335 | // always do gen packages first to know the references |
| 336 | for _, pkg := range append(genPkgs, refPkgs...) { |
| 337 | skippedTypes := make(map[string]struct{}) |
| 338 | for _, file := range pkg.Syntax { |
| 339 | for _, comment := range file.Comments { |
| 340 | for _, line := range comment.List { |
| 341 | text := line.Text |
| 342 | matches := ignoreRegex.FindStringSubmatch(text) |
| 343 | ignored := ignoreRegex.SubexpIndex("ignored_types") |
| 344 | if len(matches) >= ignored && matches[ignored] != "" { |
| 345 | arr := strings.Split(matches[ignored], ",") |
| 346 | for _, s := range arr { |
| 347 | skippedTypes[strings.TrimSpace(s)] = struct{}{} |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | allIdents := pkg.Types.Scope().Names() |
| 355 | for _, ident := range allIdents { |
| 356 | if _, ok := skippedTypes[ident]; ok { |
| 357 | continue |
| 358 | } |
| 359 | |
| 360 | obj := pkg.Types.Scope().Lookup(ident) |
| 361 | |
| 362 | if !obj.Exported() { |
| 363 | continue |
| 364 | } |
| 365 | |
| 366 | // Skip by qualified name |
| 367 | if _, ok := ts.skip[obj.Type().String()]; ok { |
| 368 | continue |
| 369 | } |
| 370 | |
| 371 | if ts.parsed.Reference[pkg.PkgPath] { |
| 372 | if !ts.parsed.referencedTypes.IsReferenced(obj) { |
| 373 | continue |
| 374 | } |
| 375 | } |
| 376 | if ts.parsed.referencedTypes.IsGenerated(obj) { |
| 377 | continue |
no test coverage detected