Skip to content

extremelylatebound/ts-parse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

ts-parse

A small utility for printing a TS AST

Given

//hello.ts
function hello(name: string) {
    console.log(`Hello, ${name}!`);
}

When

$./ts-parse.ts ./hello.ts

Then

{
  "kind": "SourceFile",
  "children": [
    {
      "kind": "FunctionDeclaration",
      "children": [
        {
          "kind": "Identifier",
          "children": [],
          "text": "hello"
        },
        {
          "kind": "Parameters",
          "children": [
            {
              "kind": "Parameter",
              "children": [
                {
                  "kind": "Identifier",
                  "children": [],
                  "text": "name"
                },
                {
                  "kind": "TypeAnnotation",
                  "children": [
                    {
                      "kind": "StringKeyword",
                      "children": []
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "kind": "Block",
          "children": [
            {
              "kind": "ExpressionStatement",
              "children": [
                {
                  "kind": "CallExpression",
                  "children": [
                    {
                      "kind": "PropertyAccessExpression",
                      "children": [
                        {
                          "kind": "Identifier",
                          "children": [],
                          "text": "console"
                        },
                        {
                          "kind": "Identifier",
                          "children": [],
                          "text": "log"
                        }
                      ]
                    },
                    {
                      "kind": "TemplateExpression",
                      "children": [
                        {
                          "kind": "TemplateHead",
                          "children": [],
                          "text": "`Hello, "
                        },
                        {
                          "kind": "TemplateSpan",
                          "children": [
                            {
                              "kind": "Identifier",
                              "children": [],
                              "text": "name"
                            },
                            {
                              "kind": "TemplateTail",
                              "children": [],
                              "text": "!`"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

About

A small utility for printing a TS AST

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published