MCPcopy Create free account
hub / github.com/microsoft/typescript-go / makeIdentifierFromModuleName

Function makeIdentifierFromModuleName

internal/printer/utilities.go:691–713  ·  view source on GitHub ↗
(moduleName string)

Source from the content-addressed store, hash-verified

689}
690
691func makeIdentifierFromModuleName(moduleName string) string {
692 moduleName = tspath.GetBaseFileName(moduleName)
693 var builder strings.Builder
694 start := 0
695 pos := 0
696 for pos < len(moduleName) {
697 ch := rune(moduleName[pos])
698 if pos == 0 && stringutil.IsDigit(ch) {
699 builder.WriteByte('_')
700 } else if !isASCIIWordCharacter(ch) {
701 if start < pos {
702 builder.WriteString(moduleName[start:pos])
703 }
704 builder.WriteByte('_')
705 start = pos + 1
706 }
707 pos++
708 }
709 if start < pos {
710 builder.WriteString(moduleName[start:pos])
711 }
712 return builder.String()
713}
714
715func findSpanEndWithEmitContext[T any](c *EmitContext, array []T, test func(c *EmitContext, value T) bool, start int) int {
716 i := start

Calls 5

GetBaseFileNameFunction · 0.92
IsDigitFunction · 0.92
lenFunction · 0.85
isASCIIWordCharacterFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected