UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

114 lines (90 loc) 6.76 kB
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>TsSimpleAst</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> <link rel="stylesheet" href="/assets/css/style.css?v=71a391c40e7283d83416a246f2c61c5fcb76068a"> <!-- <link rel="stylesheet" href="/assets/css/style.css?v=71a391c40e7283d83416a246f2c61c5fcb76068a"> <link rel="stylesheet" href="/assets/css/custom-style.css?v=71a391c40e7283d83416a246f2c61c5fcb76068a"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="/assets/js/main.js"></script>--> </head> <body> <div class="main"> <header class="container"> <div class="row"> <h1 onclick="document.location.href = '/'" class="headerLink">TsSimpleAst</h1> <!--<p class="subText">Simple way to navigate and manipulate the TypeScript AST.</p>--> </div> </header> <div class="container"> <div class="row"> <div class="col-md-3"> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <nav class="sidebar-nav" id="navbarSupportedContent"> <ul class="navbar-nav navbar-default"> <li class="nav-item"> <a class="nav-link" href="/">Overview</a> </li> <li class="nav-item active"> <a class="nav-link" href="/setup">Setup</a> <ul> <li class=""><a href="/setup/index">Instantiating</a></li> <li class="active"><a href="/setup/adding-sourcefiles">Adding SourceFiles</a></li> <li class=""><a href="/setup/diagnostics">Diagnostics</a></li> </ul> </li> <li class="nav-item"> <a class="nav-link" href="/navigation">Navigation</a> </li> <li class="nav-item"> <a class="nav-link" href="/manipulation">Manipulation</a> </li> <li class=""> <a class="nav-link" href="/details/index">Details</a> </li> <li class="nav-item"> <a class="nav-link" href="http://github.com/dsherret/ts-simple-ast">View on GitHub</a> </li> </ul> </nav> </div> <section class="container-fluid col-md-9"> <h2 id="adding-source-files">Adding Source Files</h2> <p>You will need to populate the <code class="highlighter-rouge">ast</code> object with source files.</p> <h3 id="by-file-globs-or-file-paths">By file globs or file paths</h3> <p>Specify as many file globs or file paths as you wish:</p> <div class="language-typescript highlighter-rouge"><pre class="highlight"><code><span class="nx">ast</span><span class="p">.</span><span class="nx">addSourceFiles</span><span class="p">(</span><span class="s2">"folder/**/*{.d.ts,.ts}"</span><span class="p">);</span> <span class="nx">ast</span><span class="p">.</span><span class="nx">addSourceFiles</span><span class="p">(</span><span class="s2">"otherFolder/file.ts"</span><span class="p">,</span> <span class="s2">"specifyAnotherFile.ts"</span><span class="p">,</span> <span class="s2">"orAnotherGlob/**/*.ts"</span><span class="p">);</span> </code></pre> </div> <h3 id="by-file-path">By file path</h3> <div class="language-typescript highlighter-rouge"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">sourceFile</span> <span class="o">=</span> <span class="nx">ast</span><span class="p">.</span><span class="nx">getOrAddSourceFileFromFilePath</span><span class="p">(</span><span class="s2">"path/to/file.ts"</span><span class="p">);</span> </code></pre> </div> <h3 id="by-string">By string</h3> <p>Adding source files by text to the AST will act like any other file that exists on the file system, but they will not be saved to the disk unless you ask it to be.</p> <div class="language-typescript highlighter-rouge"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">fileText</span> <span class="o">=</span> <span class="s2">"enum MyEnum {\n}\n"</span><span class="p">;</span> <span class="kd">const</span> <span class="nx">sourceFile</span> <span class="o">=</span> <span class="nx">ast</span><span class="p">.</span><span class="nx">addSourceFileFromText</span><span class="p">(</span><span class="s2">"path/for/myNewFile.ts"</span><span class="p">,</span> <span class="nx">fileText</span><span class="p">);</span> <span class="c1">// save it to the disk if you wish:</span> <span class="nx">sourceFile</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span> <span class="c1">// or saveSync();</span> </code></pre> </div> <p><strong>Next step:</strong> <a href="diagnostics">Diagnostics</a></p> </section> </div> </div> <footer> </footer> </div> <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script> <!--[if !IE]><script>fixScale(document);</script><![endif]--> </body> </html>