-
Notifications
You must be signed in to change notification settings - Fork 682
Port class fields transformer #1542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chengcyber
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
chengcyber:feat-class-fields-transformer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,805
−62
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,206 @@ | ||||||||||||||||||||||||||
package printer | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import "github.com/microsoft/typescript-go/internal/ast" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
type PrivateIdentifierKind int | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const ( | ||||||||||||||||||||||||||
PrivateIdentifierKindMethod PrivateIdentifierKind = iota | ||||||||||||||||||||||||||
PrivateIdentifierKindField | ||||||||||||||||||||||||||
PrivateIdentifierKindAccessor | ||||||||||||||||||||||||||
PrivateIdentifierKindUntransformed | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func (k PrivateIdentifierKind) String() string { | ||||||||||||||||||||||||||
switch k { | ||||||||||||||||||||||||||
case PrivateIdentifierKindMethod: | ||||||||||||||||||||||||||
return "m" | ||||||||||||||||||||||||||
case PrivateIdentifierKindField: | ||||||||||||||||||||||||||
return "f" | ||||||||||||||||||||||||||
case PrivateIdentifierKindAccessor: | ||||||||||||||||||||||||||
return "a" | ||||||||||||||||||||||||||
case PrivateIdentifierKindUntransformed: | ||||||||||||||||||||||||||
return "untransformed" | ||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||
panic("Unhandled PrivateIdentifierKind") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
type PrivateIdentifierInfo interface { | ||||||||||||||||||||||||||
Kind() PrivateIdentifierKind | ||||||||||||||||||||||||||
IsValid() bool | ||||||||||||||||||||||||||
IsStatic() bool | ||||||||||||||||||||||||||
BrandCheckIdentifier() *ast.Identifier | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
type PrivateIdentifierInfoBase struct { | ||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
* brandCheckIdentifier can contain: | ||||||||||||||||||||||||||
* - For instance field: The WeakMap that will be the storage for the field. | ||||||||||||||||||||||||||
* - For instance methods or accessors: The WeakSet that will be used for brand checking. | ||||||||||||||||||||||||||
* - For static members: The constructor that will be used for brand checking. | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
brandCheckIdentifier *ast.Identifier | ||||||||||||||||||||||||||
// Stores if the identifier is static or not | ||||||||||||||||||||||||||
isStatic bool | ||||||||||||||||||||||||||
// Stores if the identifier declaration is valid or not. Reserved names (e.g. #constructor) | ||||||||||||||||||||||||||
// or duplicate identifiers are considered invalid. | ||||||||||||||||||||||||||
isValid bool | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
type PrivateIdentifierAccessorInfo struct { | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase | ||||||||||||||||||||||||||
kind PrivateIdentifierKind | ||||||||||||||||||||||||||
// Identifier for a variable that will contain the private get accessor implementation, if any. | ||||||||||||||||||||||||||
GetterName *ast.Identifier | ||||||||||||||||||||||||||
// Identifier for a variable that will contain the private set accessor implementation, if any. | ||||||||||||||||||||||||||
SetterName *ast.Identifier | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func (p *PrivateIdentifierAccessorInfo) Kind() PrivateIdentifierKind { | ||||||||||||||||||||||||||
return p.kind | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierAccessorInfo) IsValid() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isValid | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierAccessorInfo) IsStatic() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isStatic | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierAccessorInfo) BrandCheckIdentifier() *ast.Identifier { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.brandCheckIdentifier | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func NewPrivateIdentifierAccessorInfo(brandCheckIdentifier *ast.Identifier, getterName *ast.Identifier, setterName *ast.Identifier, isValid bool, isStatc bool) *PrivateIdentifierAccessorInfo { | ||||||||||||||||||||||||||
return &PrivateIdentifierAccessorInfo{ | ||||||||||||||||||||||||||
kind: PrivateIdentifierKindAccessor, | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase: PrivateIdentifierInfoBase{ | ||||||||||||||||||||||||||
brandCheckIdentifier: brandCheckIdentifier, | ||||||||||||||||||||||||||
isStatic: isStatc, | ||||||||||||||||||||||||||
isValid: isValid, | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
GetterName: getterName, | ||||||||||||||||||||||||||
SetterName: setterName, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
type PrivateIdentifierMethodInfo struct { | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase | ||||||||||||||||||||||||||
kind PrivateIdentifierKind | ||||||||||||||||||||||||||
// Identifier for a variable that will contain the private method implementation. | ||||||||||||||||||||||||||
MethodName *ast.Identifier | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func (p *PrivateIdentifierMethodInfo) Kind() PrivateIdentifierKind { | ||||||||||||||||||||||||||
return p.kind | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierMethodInfo) IsValid() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isValid | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierMethodInfo) IsStatic() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isStatic | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierMethodInfo) BrandCheckIdentifier() *ast.Identifier { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.brandCheckIdentifier | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func NewPrivateIdentifierMethodInfo(brandCheckIdentifier *ast.Identifier, methodName *ast.Identifier, isValid bool, isStatc bool) *PrivateIdentifierMethodInfo { | ||||||||||||||||||||||||||
return &PrivateIdentifierMethodInfo{ | ||||||||||||||||||||||||||
kind: PrivateIdentifierKindMethod, | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase: PrivateIdentifierInfoBase{ | ||||||||||||||||||||||||||
brandCheckIdentifier: brandCheckIdentifier, | ||||||||||||||||||||||||||
isStatic: isStatc, | ||||||||||||||||||||||||||
Comment on lines
+106
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameter name 'isStatc' appears to be a typo. It should be 'isStatic' to match the field name and other similar parameters.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||
isValid: isValid, | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
MethodName: methodName, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
type PrivateIdentifierInstanceFieldInfo struct { | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase | ||||||||||||||||||||||||||
kind PrivateIdentifierKind | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func NewPrivateIdentifierInstanceFieldInfo(brandCheckIdentifier *ast.Identifier, isValid bool) *PrivateIdentifierInstanceFieldInfo { | ||||||||||||||||||||||||||
return &PrivateIdentifierInstanceFieldInfo{ | ||||||||||||||||||||||||||
kind: PrivateIdentifierKindField, | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase: PrivateIdentifierInfoBase{ | ||||||||||||||||||||||||||
brandCheckIdentifier: brandCheckIdentifier, | ||||||||||||||||||||||||||
isStatic: false, | ||||||||||||||||||||||||||
isValid: isValid, | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func (p *PrivateIdentifierInstanceFieldInfo) Kind() PrivateIdentifierKind { | ||||||||||||||||||||||||||
return p.kind | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierInstanceFieldInfo) IsValid() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isValid | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierInstanceFieldInfo) IsStatic() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isStatic | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierInstanceFieldInfo) BrandCheckIdentifier() *ast.Identifier { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.brandCheckIdentifier | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
type PrivateIdentifierStaticFieldInfo struct { | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase | ||||||||||||||||||||||||||
kind PrivateIdentifierKind | ||||||||||||||||||||||||||
// Contains the variable that will serve as the storage for the field. | ||||||||||||||||||||||||||
VariableName *ast.Identifier | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func NewPrivateIdentifierStaticFieldInfo(brandCheckIdentifier *ast.Identifier, variableName *ast.Identifier, isValid bool) *PrivateIdentifierStaticFieldInfo { | ||||||||||||||||||||||||||
return &PrivateIdentifierStaticFieldInfo{ | ||||||||||||||||||||||||||
kind: PrivateIdentifierKindField, | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase: PrivateIdentifierInfoBase{ | ||||||||||||||||||||||||||
brandCheckIdentifier: brandCheckIdentifier, | ||||||||||||||||||||||||||
isStatic: true, | ||||||||||||||||||||||||||
isValid: isValid, | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
VariableName: variableName, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func (p *PrivateIdentifierStaticFieldInfo) Kind() PrivateIdentifierKind { | ||||||||||||||||||||||||||
return p.kind | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierStaticFieldInfo) IsValid() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isValid | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierStaticFieldInfo) IsStatic() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isStatic | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierStaticFieldInfo) BrandCheckIdentifier() *ast.Identifier { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.brandCheckIdentifier | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
type PrivateIdentifierUntransformedInfo struct { | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase | ||||||||||||||||||||||||||
kind PrivateIdentifierKind | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func NewPrivateIdentifierUntransformedInfo(brandCheckIdentifier *ast.Identifier, isValid bool, isStatic bool) *PrivateIdentifierUntransformedInfo { | ||||||||||||||||||||||||||
return &PrivateIdentifierUntransformedInfo{ | ||||||||||||||||||||||||||
kind: PrivateIdentifierKindUntransformed, | ||||||||||||||||||||||||||
PrivateIdentifierInfoBase: PrivateIdentifierInfoBase{ | ||||||||||||||||||||||||||
brandCheckIdentifier: brandCheckIdentifier, | ||||||||||||||||||||||||||
isStatic: isStatic, | ||||||||||||||||||||||||||
isValid: isValid, | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func (p *PrivateIdentifierUntransformedInfo) Kind() PrivateIdentifierKind { | ||||||||||||||||||||||||||
return p.kind | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierUntransformedInfo) IsValid() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isValid | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierUntransformedInfo) IsStatic() bool { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.isStatic | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
func (p *PrivateIdentifierUntransformedInfo) BrandCheckIdentifier() *ast.Identifier { | ||||||||||||||||||||||||||
return p.PrivateIdentifierInfoBase.brandCheckIdentifier | ||||||||||||||||||||||||||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter name 'isStatc' appears to be a typo. It should be 'isStatic' to match the field name and other similar parameters.
Copilot uses AI. Check for mistakes.