ts-simple-ast
Version:
TypeScript compiler wrapper for AST navigation and code generation.
132 lines (107 loc) • 7.86 kB
HTML
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>ts-simple-ast - Instantiating</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=502728dc7b09041e36b06c50f79a13adbfb6f1b2">
<!--
<link rel="stylesheet" href="/assets/css/style.css?v=502728dc7b09041e36b06c50f79a13adbfb6f1b2">
<link rel="stylesheet" href="/assets/css/custom-style.css?v=502728dc7b09041e36b06c50f79a13adbfb6f1b2">
<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">ts-simple-ast</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="active"><a href="/setup/index">Instantiating</a></li>
<li class=""><a href="/setup/adding-source-files">Adding Source Files</a></li>
<li class=""><a href="/setup/diagnostics">Diagnostics</a></li>
<li class=""><a href="/setup/file-system">File System</a></li>
<li class=""><a href="/setup/ast-viewers">AST Viewers</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="nav-item">
<a class="nav-link" href="/emitting">Emitting</a>
</li>
<li class="">
<a class="nav-link" href="/details/index">Details</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/utilities">Utilities</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="instantiating">Instantiating</h2>
<p>Use the default export from <code class="highlighter-rouge">"ts-simple-ast"</code>:</p>
<div class="language-typescript highlighter-rouge"><pre class="highlight"><code><span class="k">import</span> <span class="nx">Ast</span> <span class="k">from</span> <span class="s2">"ts-simple-ast"</span><span class="p">;</span>
<span class="kd">const</span> <span class="nx">ast</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Ast</span><span class="p">();</span>
</code></pre>
</div>
<h3 id="compiler-options">Compiler options</h3>
<div class="language-typescript highlighter-rouge"><pre class="highlight"><code><span class="k">import</span> <span class="o">*</span> <span class="k">as</span> <span class="nx">ts</span> <span class="k">from</span> <span class="s2">"typescript"</span><span class="p">;</span>
<span class="kd">const</span> <span class="nx">ast</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Ast</span><span class="p">({</span>
<span class="na">compilerOptions</span><span class="p">:</span> <span class="p">{</span>
<span class="na">target</span><span class="p">:</span> <span class="nx">ts</span><span class="p">.</span><span class="nx">ScriptTarget</span><span class="p">.</span><span class="nx">ES3</span>
<span class="p">}</span>
<span class="p">});</span>
</code></pre>
</div>
<h3 id="tsconfigjson">tsconfig.json</h3>
<p>If you would like to manually specify the path to a <em>tsconfig.json</em> file then specify that:</p>
<div class="language-ts highlighter-rouge"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">ast</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Ast</span><span class="p">({</span>
<span class="na">tsConfigFilePath</span><span class="p">:</span> <span class="s2">"path/to/tsconfig.json"</span>
<span class="p">});</span>
</code></pre>
</div>
<p><em>Note:</em> You can override any <code class="highlighter-rouge">tsconfig.json</code> options by also providing a <code class="highlighter-rouge">compilerOptions</code> object.</p>
<p>For your convenience, this will automatically add all the associated source files from the <em>tsconfig.json</em>. If you don’t wish to do that, then you will need to explicitly set <code class="highlighter-rouge">addFilesFromTsConfig</code> to <code class="highlighter-rouge">false</code>:</p>
<div class="language-ts highlighter-rouge"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">ast</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Ast</span><span class="p">({</span>
<span class="na">tsConfigFilePath</span><span class="p">:</span> <span class="s2">"path/to/tsconfig.json"</span><span class="p">,</span>
<span class="na">addFilesFromTsConfig</span><span class="p">:</span> <span class="kc">false</span>
<span class="p">});</span>
</code></pre>
</div>
</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>