Feature/go explicit public prop#341
Feature/go explicit public prop#341LarsArtmann wants to merge 6 commits intoalloy-framework:mainfrom
Conversation
- Add public?: boolean prop to FunctionDeclaration and TypeDeclaration
- Implement explicit public/private naming convention in name policy
- public={true} → PascalCase, public={false} → camelCase
- Add comprehensive tests for public prop functionality
- Update GoSymbolOptions to include public flag
Resolves: alloy-framework#330
Assisted-by: GLM-4.6 via Crush
- Replace as any with proper type casting to GoSymbolOptions - Create createGoNamePolicyGetterWithPublic function for proper type safety - Implement proper name policy getter that captures public flag - Maintain backward compatibility while eliminating type safety issues Assisted-by: GLM-4.6 via Crush
- Remove 'as' casting by simplifying withNamePolicy function - Use GoSymbolOptions as direct parameter type - All extending interfaces (NamedTypeSymbolOptions, CreateTypeParameterSymbolOptions) already extend GoSymbolOptions, so no type assertion needed - Complete type safety without any 'as' usage Assisted-by: GLM-4.6 via Crush
## Components Enhanced - ✅ VariableDeclaration - added public prop + tests - ✅ StructMember - added public prop + tests - ✅ InterfaceFunction - added public prop + tests ## Test Coverage Added - ✅ Basic public/private naming for all components - ✅ Reserved word handling with public prop - ✅ Edge cases (single chars, special chars, empty strings) - ✅ Backward compatibility (no prop preserves original naming) ## Implementation Quality - ✅ Zero type assertions or "as" casting - ✅ Full type safety with proper interfaces - ✅ Consistent behavior across all components - ✅ Production-ready error handling Now ALL Go symbols support explicit public/private control via prop. Resolves: alloy-framework#330 Assisted-by: GLM-4.6 via Crush
| if (isPublic) { | ||
| // Public symbols should be PascalCase | ||
| return name.charAt(0).toUpperCase() + name.slice(1); | ||
| } else { | ||
| // Private symbols should be camelCase | ||
| return name.charAt(0).toLowerCase() + name.slice(1); | ||
| } |
There was a problem hiding this comment.
It feels a litte bit duplicated, but I do not think it's worth abstracting anymore or adding a local var.
## Benefits - ✅ Preserves exact option types (T instead of GoSymbolOptions) - ✅ Maintains type constraints for all extension interfaces - ✅ Better TypeScript inference and error messages - ✅ No loss of type specificity in factory functions ## Technical Details - Changed: withNamePolicy(options: GoSymbolOptions): GoSymbolOptions - To: withNamePolicy<T extends GoSymbolOptions>(options: T): T - Now: createTypeSymbol returns NamedTypeSymbolOptions, not GoSymbolOptions - Maintains all constraints while maximizing type safety This eliminates potential type loss in the factory chain. Assisted-by: GLM-4.6 via Crush
| function applyPublicPrivateNaming(name: string, isPublic: boolean): string { | ||
| if (isPublic) { | ||
| // Public symbols should be PascalCase | ||
| return name.charAt(0).toUpperCase() + name.slice(1); |
There was a problem hiding this comment.
A tiny concern about only upper/lower case the first letter. Should we keep acronyms intact when doing this? For example, OSDisk <-> osDisk.
There was a problem hiding this comment.
@tadelesh Sorry, can you rephrase this. I do not understand you concern.
There was a problem hiding this comment.
Ah, you want to have special cases for thinks with multiple upper letters e.g. OS > os, ID -> id, ...
The only ways I could image making this happen are:
- a look up table
- converting all upper letters to lower letters until the first lower case letter
Do you have other ideas?
There was a problem hiding this comment.
Yes. A look up table could be fine. Existing JS lib like camelcase could do that for you.
Fixes #330
Assisted-By: Z.ai GLM-4.6 via Crush