Repository navigation
Lift C# member aliases out of their type and nest JS classes as statics [patch] - #227
Merged
Merged
Conversation
…cs [patch]
A class member that is a UsingAlias or a nested ClassDeclaration came out
where neither target accepts it. CSharpGenerator.GenerateUsingAlias wrote
`using Id = int;` inside the type body (CS1513, CS1529, CS1022), despite
its own remark. JavaScriptGenerator wrote `const Id = int;` and a bare
`class Inner { }` into the class body, both syntax errors there.
C#: a type's aliases, and those of the types nested in it, are now
written in the namespace or file that encloses it, ahead of everything
else in that scope, which is the only place C# takes a using alias. The
scope's own aliases move there too, so one declared after a type no
longer fails with CS1529. A type generated on its own writes its aliases
in front of itself.
JavaScript: a nested class becomes `static Inner = class Inner { ... };`
and a member alias `static Id = int;`, the shape a nested enum already
takes.
TypeMemberDeclarationTests compiles the C# with dotnet build and parses
the JavaScript with node --check.
Fixes #179
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NW9fJSB9VKsuPv7M2UmznC
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #179
What was wrong
A
UsingAliasor nestedClassDeclarationinside a class came out where neither target accepts it:GenerateUsingAliaswroteusing Id = int;inside the type body. The build failed with CS1513, CS1529 and CS1022, even though the method's own remark said member aliases would be "said rather than written".const Id = int;and a bareclass Inner { … }.node --checkrejects both withSyntaxError: Unexpected identifier.Change
Idstill resolve inside the type. The scope's own aliases move up as well, so an alias declared after a type no longer fails with CS1529. A type generated on its own (no enclosing scope) writes its aliases just before itself. The remarks are updated to say this.static Inner = class Inner { … };and a member alias becomesstatic Id = int;. Nested enums already used this shape. The class heading and member loop are split out ofGenerateClassDeclarationso the nested form can reuse them.Tests
TypeMemberDeclarationTests(5 tests):dotnet buildof a namespace containing a class-member alias, a nested class with its own alias, and a namespace alias declared after a type.node --checkof a class holding an alias and a class holding a nested class.Coder.Testsuite: 1269 passed, 0 failed.dotnet format --verify-no-changeson the touched files reports only the CHARSET/IMPORTS findings thatmainalready has.Known limit
Hoisting a member alias to the enclosing scope means two types in the same scope can't declare same-named aliases to different types; that would now be a duplicate alias. C# has no member-scoped alias, so the alternative is writing the aliased type in place of the name at every use. I didn't do that here because no reported case needs it.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NW9fJSB9VKsuPv7M2UmznC
Generated by Claude Code