Skip to content

Feature/go explicit public prop#341

Open
LarsArtmann wants to merge 6 commits intoalloy-framework:mainfrom
LarsArtmann:feature/go-explicit-public-prop
Open

Feature/go explicit public prop#341
LarsArtmann wants to merge 6 commits intoalloy-framework:mainfrom
LarsArtmann:feature/go-explicit-public-prop

Conversation

@LarsArtmann
Copy link

@LarsArtmann LarsArtmann commented Nov 27, 2025

Fixes #330

Assisted-By: Z.ai GLM-4.6 via Crush

LarsArtmann and others added 5 commits November 23, 2025 17:56
- 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
Comment on lines +48 to +54
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);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tiny concern about only upper/lower case the first letter. Should we keep acronyms intact when doing this? For example, OSDisk <-> osDisk.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tadelesh Sorry, can you rephrase this. I do not understand you concern.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. a look up table
  2. converting all upper letters to lower letters until the first lower case letter

Do you have other ideas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. A look up table could be fine. Existing JS lib like camelcase could do that for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Go] public vs private

2 participants

Comments