Skip to content

sdcb/TypeScriptAST

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sdcb.TypeScriptAST NuGet

TypeScript AST Parser, .NET Core standard 2.0 library, forked from: https://github.com/ToCSharp/TypeScriptAST

Usage

// ShootR code is forked from: https://github.com/NTaylorMullen/ShootR
Directory.EnumerateFiles(path: @"C:\Users\flysha.zhou\source\repos\ShootR\ShootR\ShootR\Client\Ships", "*.ts")
    .Select(x => new TypeScriptAST(File.ReadAllText(x), x))
    .SelectMany(x => x.OfKind(SyntaxKind.ClassDeclaration))
    .Select(x => new
    {
        Name = x.OfKind(SyntaxKind.Identifier).FirstOrDefault().GetText(),
        Properties = x.OfKind(SyntaxKind.PropertyDeclaration)
            .Select(x => new
            {
                Name = x.IdentifierStr,
                IsPublic = x.First.Kind != SyntaxKind.PrivateKeyword,
                Type = GetType(x),
            }),
        Methods = x.OfKind(SyntaxKind.Constructor).Concat(x.OfKind(SyntaxKind.MethodDeclaration))
            .Select(x => new
            {
                Name = x is ConstructorDeclaration ctor ? ".ctor" : x.IdentifierStr,
                IsPublic = x.First.Kind != SyntaxKind.PrivateKeyword,
                Args = ((ISignatureDeclaration)x).Parameters.Select(x => new
                {
                    Name = x.Children.OfKind(SyntaxKind.Identifier).FirstOrDefault().GetText(), 
                    Type = x.Children.OfKind(SyntaxKind.TypeReference).FirstOrDefault()?.GetText(), 
                }), 
            }), 
    })
    .Dump();

string GetType(Node x)
{
    var typeReference = x.Children.OfType<TypeReferenceNode>().FirstOrDefault();
    if (typeReference != null)
        return typeReference.IdentifierStr;

    if (x.Last is LiteralExpression literal)
        return literal.Kind.ToString()[..^7].ToLower();

    return Regex.Match(x.Last.GetText(), "<(.+?)>").Groups[1].Value;
}

Result

5(7 items)44
NamePropertiesMethods
Ship
5(11 items)44
NameIsPublicType
SIZETruenull
DAMAGE_INCREASE_RATETruenumeric
IDTrue 
GraphicTrueShipGraphic
MovementControllerTrueShipMovementController
AbilityHandlerTrueShipAbilityHandler
AnimationHandlerTrueShipAnimationHandler
LifeControllerTrueShipLifeController
LevelManagerTrueShipLevelManager
_destroyedFalse 
OnExplosionTruenull
5(4 items)44
NameIsPublicArgs
.ctorTrue
5(2 items)44
NameType
payloadServer.IShipData
contentManagereg.Content.ContentManager
UpdateTrue
5(1 item)44
NameType
gameTimeeg.GameTime
LoadPayloadTrue
5(2 items)44
NameType
payloadServer.IShipData
forceMovementnull
DestroyTrue
5(1 item)44
NameType
explodenull
ShipFireController
5(1 item)44
NameIsPublicType
MIN_FIRE_RATETruenull
5(1 item)44
NameIsPublicArgs
.ctorTrue
5(2 items)44
NameType
keyboardeg.Input.KeyboardHandler
onFirenull
ShipInputController
5(4 items)44
NameIsPublicType
DOUBLE_TAP_AFTERTruenull
_directionsFalseIMoving
_lastBoostTapFalseDate
_fireControllerFalseShipFireController
5(2 items)44
NameIsPublicArgs
.ctorTrue
5(3 items)44
NameType
_keyboardeg.Input.KeyboardHandler
_onMovenull
_onFirenull
BindKeysFalse
5(4 items)44
NameType
keyListnull
bindingActionnull
directionnull
startMovingnull
ShipInterpolationManager
5(6 items)44
NameIsPublicType
PAYLOAD_BUFFERTruenumeric
InterpolatingTrue 
_positionInterpolationFalsenull
_rotationInterpolationFalsenull
_interpolationDurationFalsenull
_payloadBufferFalseArray
5(6 items)44
NameIsPublicArgs
.ctorTrue
5(1 item)44
NameType
_movementControllerShipMovementController
LoadPayloadTrue
5(1 item)44
NameType
payloadServer.IShipMovementControllerData
UpdateTrue
5(1 item)44
NameType
gameTimeeg.GameTime
BufferPayloadFalse
5(1 item)44
NameType
payloadServer.IShipMovementControllerData
StartInterpolationPayloadFalse
5(1 item)44
NameType
payloadServer.IShipMovementControllerData
InterpolateFalse
(0 items)
ShipLifeController
5(9 items)44
NameIsPublicType
START_LIFETruenumeric
BAD_COLORTruenull
HURT_COLORTruenull
GOOD_COLORTruenull
BAD_THRESHOLDTruenumeric
HURT_THRESHOLDTruenumeric
AliveTrue 
HealthTrue 
MaxHealthTrue 
5(1 item)44
NameIsPublicArgs
.ctorTrue
5(1 item)44
NameType
payloadServer.IShipData
ShipManager
5(2 items)44
NameIsPublicType
UserShipManagerTrueUserShipManager
_shipsFalse 
5(7 items)44
NameIsPublicArgs
.ctorTrue
5(4 items)44
NameType
_viewporteg.Bounds.BoundingRectangle
_sceneeg.Rendering.Scene2d
_collisionManagereg.Collision.CollisionManager
_contentManagereg.Content.ContentManager
InitializeTrue
5(1 item)44
NameType
userShipManagerUserShipManager
UpdateViewportTrue
5(1 item)44
NameType
viewporteg.Size2d
GetShipTrue
5(1 item)44
NameType
idnull
RemoveShipTrue
5(1 item)44
NameType
shipIDnull
LoadPayloadTrue
5(1 item)44
NameType
payloadServer.IPayloadData
UpdateTrue
5(1 item)44
NameType
gameTimeeg.GameTime
ShipMovementController
5(16 items)44
NameIsPublicType
MASSTruenumeric
ENGINE_POWERTruenumeric
DRAG_AREATruenumeric
DRAG_COEFFICIENTTruenumeric
ROTATE_SPEEDTrue 
MOVING_DIRECTIONSTrue 
MovingTrueIMoving
MassTrue 
PowerTrue 
ForcesTruenull
ControllableTrue 
UserControlledTrue 
_accelerationFalsenull
_moveablesFalseArray
_interpolationManagerFalseShipInterpolationManager
OnMoveTruenull
5(10 items)44
NameIsPublicArgs
.ctorTrue
5(1 item)44
NameType
movablesArray<eg.IMoveable>
LoadPayloadTrue
5(2 items)44
NameType
payloadServer.IShipMovementControllerData
forceMovementnull
IsMovingInDirectionTrue
5(1 item)44
NameType
directionnull
StartMovingTrue
5(1 item)44
NameType
directionnull
StopMovingTrue
5(1 item)44
NameType
directionnull
StopAllMovementTrue
(0 items)
ApplyForceTrue
5(1 item)44
NameType
forceeg.Vector2d
UpdateTrue
5(1 item)44
NameType
gameTimeeg.GameTime
MoveTrue
5(2 items)44
NameType
directionnull
startMovingnull
DisposeTrue
(0 items)

About

TypeScript AST Parser, .NET Core standard 2.0 library, forked from: https://github.com/ToCSharp/TypeScriptAST

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages