Skip to content

Commit

Permalink
do not replace first character if number
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Aug 27, 2024
1 parent 8d33586 commit 0006a28
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,12 +1008,9 @@ func imports(m *schema.Module, aliasesMustBeExported bool) map[string]string {
break
}
imports[path.Join("ftl", n.Module)] = "ftl" + n.Module

for _, tp := range n.TypeParameters {
if tpRef, ok := tp.(*schema.Ref); ok {
if tpRef.Module != "" && tpRef.Module != m.Name {
imports[path.Join("ftl", tpRef.Module)] = "ftl" + tpRef.Module
}
if tpRef, ok := tp.(*schema.Ref); ok && tpRef.Module != "" && tpRef.Module != m.Name {
imports[path.Join("ftl", tpRef.Module)] = "ftl" + tpRef.Module
}
}

Expand Down Expand Up @@ -1067,10 +1064,16 @@ func addImports(existingImports map[string]string, newImportPathsAndDirs map[str
for i := range len(pathComponents) {
runes := []rune(pathComponents[len(pathComponents)-1-i])
for i, char := range runes {
if !unicode.IsLetter(char) && !(unicode.IsNumber(char) && i > 0) {
if !unicode.IsLetter(char) && !unicode.IsNumber(char) {
runes[i] = '_'
}
}
if unicode.IsNumber(runes[0]) {
newRunes := make([]rune, len(runes)+1)
newRunes[0] = '_'
copy(newRunes[1:], runes)
runes = newRunes
}
foldedComponent := string(runes)
if i == 0 {
currentAlias = foldedComponent
Expand Down
4 changes: 2 additions & 2 deletions go-runtime/compile/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func TestImportAliases(t *testing.T) {
"github.com/some/pkg": "uniquedir",
"github.com/example/path/to/pkg": "pkg_last",
"github.com/last": "github_com_last",
"github.com/11/numeric": "_1_numeric",
"github.com/22/numeric": "_2_numeric",
"github.com/11/numeric": "_11_numeric",
"github.com/22/numeric": "_22_numeric",
"github.com/same": "dir1",
"github.com/two/aliaseswithonepkg": "aliaseswithonepkg",
"ftl/moduleclash": "ftlmoduleclash",
Expand Down

0 comments on commit 0006a28

Please sign in to comment.