<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrew Branch</title>
    <description>The latest articles on DEV Community by Andrew Branch (@andrewbranch).</description>
    <link>https://dev.to/andrewbranch</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F258148%2F36821cb6-d3f9-4d87-88fe-3ab292322a75.jpeg</url>
      <title>DEV Community: Andrew Branch</title>
      <link>https://dev.to/andrewbranch</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andrewbranch"/>
    <language>en</language>
    <item>
      <title>Debugging the TypeScript Codebase</title>
      <dc:creator>Andrew Branch</dc:creator>
      <pubDate>Wed, 23 Oct 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/andrewbranch/debugging-the-typescript-codebase-576o</link>
      <guid>https://dev.to/andrewbranch/debugging-the-typescript-codebase-576o</guid>
      <description>&lt;p&gt;When I joined the TypeScript team, debugging quickly became my most valuable skill, and by the same token, the debugability of the compiler became one of the codebase’s most valuable assets. The TypeScript compiler is just a Node app so it’s pretty easy to debug, but I’ve found a few useful tricks specific to the TypeScript codebase. Thanks to a &lt;a href="https://twitter.com/JoshuaKGoldberg/status/1174770454743179265"&gt;request over Twitter&lt;/a&gt;, here they are.&lt;/p&gt;

&lt;p&gt;The first section of this post is like a quick-start: I’ll get you a debug session running as quickly as possible. If you’re already somewhat familiar with the compiler, this might be all you need. But if you find yourself struggling to navigate that debug session or figure out what part of the code you want to debug, hang in there! The second section provides tips for finding strategic breakpoint locations and inspecting the compiler state while paused.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick-Start: Three Ways to Attach
&lt;/h2&gt;

&lt;p&gt;The first step for any method of debugging is to clone and build TypeScript from source so we can step through the original TypeScript source instead of the bundled JavaScript files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone git@github.com:microsoft/TypeScript.git
cd TypeScript
npm install
npm run build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Debugging from tsc
&lt;/h3&gt;

&lt;p&gt;The built compiler and source maps are now in &lt;code&gt;built/local&lt;/code&gt;, including a file called &lt;code&gt;tsc.js&lt;/code&gt;. Anywhere you would normally use &lt;code&gt;tsc&lt;/code&gt;, you can now use &lt;code&gt;node built/local/tsc.js&lt;/code&gt;. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ node --inspect-brk built/local/tsc.js -p ../MyBuggyProject

Debugger listening on ws://127.0.0.1:9229/60b1b25a-f29d-4568-8619-b5e29b6dee25
For help, see: https://nodejs.org/en/docs/inspector
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Node is paused at the beginning of tsc.js and waiting for you to attach the debugger of your choice. I’ll be demonstrating use of VS Code’s built-in debugger&lt;sup id="fnref1"&gt;1&lt;/sup&gt;, but any Node debugger that can attach to a listening debug port will work.&lt;/p&gt;

&lt;p&gt;If you haven’t already, open the TypeScript codebase in VS Code. Open the command palette and select “Debug: Attach to Node Process,” then select the process you just started (on port 9229 by default).&lt;/p&gt;

&lt;p&gt;&lt;a href="///static/d8ccbddae1f06bb7df51aae82f0b2c19/51c08/attach-to-node-process.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ab1brpKa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.andrewbran.ch/static/d8ccbddae1f06bb7df51aae82f0b2c19/db64a/attach-to-node-process.png" alt="A screenshot of VS Code with the command palette open, searching “debug.” A list of results is shown with “Debug: Attach to Node Process” focused."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;VS Code will open tsc.js and show that the debugger is paused on the first line. From here, you can continue or step the debugger and hit breakpoints in the TypeScript source files.&lt;sup id="fnref2"&gt;2&lt;/sup&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Debugging from TS Server
&lt;/h3&gt;

&lt;p&gt;If you need to debug a language service feature (like a refactor, a code fix, the formatter, or code completion), debugging VS Code’s TS Server instance is often the most convenient approach. Again, you’ll need the TypeScript codebase cloned, built, and opened in one VS Code window. You’ll also need &lt;em&gt;another&lt;/em&gt; VS Code window opened to a project of your choice. (I have a dedicated project filled with nonsense TypeScript and JavaScript files for this purpose.) We’ll use the former VS Code window to debug the latter. (Impressively, a single VS Code instance &lt;em&gt;can&lt;/em&gt; debug its own TS Server process, but TypeScript-powered editor features like go-to-definition don’t work while the process is paused, so it’s much easier to use two windows.)&lt;/p&gt;

&lt;p&gt;The window you want to debug needs to be opened with the environment variable &lt;code&gt;TSS_DEBUG&lt;/code&gt; set to a port number. If you have the &lt;code&gt;code&lt;/code&gt; CLI tool, you can do this from the command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd example-project
TSS_DEBUG=9559 code .
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, you need to tell that VS Code window where to find the version of TypeScript that you built locally so it can be used for TS Server. Create or modify your example project’s &lt;code&gt;.vscode/settings.json&lt;/code&gt; file with the following setting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "typescript.tsdk": "../path/to/TypeScript/built/local"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, back in the window with the TypeScript codebase, open the command palette and select “Debug: Attach to Node Process,” then select the process running on the port you selected for &lt;code&gt;TSS_DEBUG&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This time, you’re connected to a long-running process that’s not paused. To pause on something useful, you’ll need to set a breakpoint in an interesting function and trigger that function from your example project window. A good place to start is &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/services/services.ts#L2121-L2176"&gt;services.ts&lt;/a&gt;. As an example, to step through quick info generation, set a breakpoint in the function called &lt;code&gt;getQuickInfoAtPosition&lt;/code&gt;, then in the example project window, hover a variable in a TypeScript or JavaScript file. The debugger in the other window should pause on that breakpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c7Kryf8S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://blog.andrewbran.ch/static/attach-to-language-server-bc6a20f10a5d9b0be9d026a501bc217c.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c7Kryf8S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://blog.andrewbran.ch/static/attach-to-language-server-bc6a20f10a5d9b0be9d026a501bc217c.gif" alt="A screen capture showing one VS Code window attach to another’s TS Server process by using the “Debug: Attach to Node Process command.”"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Debugging tests
&lt;/h3&gt;

&lt;p&gt;The last method of debugging I’ll cover is perhaps the most expedient of all, especially if you’re working on actually contributing a bug fix or feature to the compiler. To do so, you’ll of course want to write tests, and it turns out that debugging those tests is really easy.&lt;/p&gt;

&lt;p&gt;All the files in &lt;code&gt;tests/cases/compiler&lt;/code&gt; and &lt;code&gt;tests/cases/conformance&lt;/code&gt; are just snippets of TypeScript (or JavaScript) that the compiler runs against. You won’t find any assertions in them; instead, info about how the compiler runs on these snippets is saved to &lt;code&gt;tests/baselines/reference&lt;/code&gt;, and the assertion is that future compilations always match the info saved there. (This is exactly the same concept as snapshot testing, which you might be familiar with in Jest.)&lt;/p&gt;

&lt;p&gt;The TypeScript codebase includes a VS Code debugger configuration file for working with these files. To use it, simply copy &lt;code&gt;.vscode/launch.template.json&lt;/code&gt; to &lt;code&gt;.vscode/launch.json&lt;/code&gt;. Set breakpoints in the part of the compiler you’re interested in (I’ll cover some tips on how to find this shortly), then, open any test file in &lt;code&gt;tests/cases/compiler&lt;/code&gt; or &lt;code&gt;tests/cases/conformance&lt;/code&gt; (or &lt;code&gt;tests/cases/fourslash&lt;/code&gt;, but those can be a bit trickier). Open VS Code’s debug panel, and click the play button. After a few moments, you should hit your first breakpoint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Going Deeper: Debugging Strategies
&lt;/h2&gt;

&lt;p&gt;Now you know the mechanics of how to start debugging, but how do you debug productively? Stepping through every line of a typical TypeScript compiler run would take… tens of hours, perhaps? How do you determine the relevant parts?&lt;/p&gt;

&lt;h3&gt;
  
  
  Brief Architecture Review
&lt;/h3&gt;

&lt;p&gt;The answer is that it comes with time spent in the codebase, but having a high-level understanding of the organization of the compiler helps.&lt;/p&gt;

&lt;p&gt;Earlier, we saw how to debug &lt;a href="https://github.com/microsoft/TypeScript/blob/master/src/tsc/tsc.ts"&gt;&lt;code&gt;tsc&lt;/code&gt;&lt;/a&gt; and the language service. These are the two most common entry points into the compiler. In a code editor scenario, as we saw before, the language service sits behind &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/tsserver/server.ts#L479"&gt;TS Server&lt;/a&gt;, which &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/server/session.ts#L2120-L2469"&gt;translates messages into language service calls&lt;/a&gt;. If you want to debug an editor-related feature like a &lt;a href="https://github.com/microsoft/TypeScript/tree/master/src/services/codefixes"&gt;code fix&lt;/a&gt; (e.g., &lt;a href="https://github.com/microsoft/TypeScript/pull/32356"&gt;inserting a missing &lt;code&gt;await&lt;/code&gt;&lt;/a&gt;), the place to start is in the functions returned by &lt;code&gt;createLanguageService&lt;/code&gt; in &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/services/services.ts#L2121-L2176"&gt;services.ts&lt;/a&gt;. Otherwise, you’re probably interested in the &lt;a href="https://github.com/microsoft/TypeScript/tree/master/src/compiler"&gt;core compiler&lt;/a&gt;, which is invoked both by the language service and by &lt;code&gt;tsc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Both &lt;code&gt;tsc&lt;/code&gt; and the language service use the &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/program.ts#L710"&gt;Program&lt;/a&gt; object as the entryway into the core of the compiler. It takes some &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/types.ts#L4703"&gt;configuration options&lt;/a&gt; (usually from a &lt;code&gt;tsconfig.json&lt;/code&gt;) and a bunch of file paths and pipe them through the compiler to answer important questions like “&lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/program.ts#L1625-L1631"&gt;do my files have any errors&lt;/a&gt;” and “&lt;a href="https://github.com/microsoft/TypeScript/blob/e8782aef226fc2631f0e7f872e3bea7fbc3d1b9f/src/compiler/program.ts#L1574"&gt;what’s the JavaScript equivalent of all this TypeScript&lt;/a&gt;.” It does that by using the following major components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;a href="https://github.com/microsoft/TypeScript/blob/master/src/compiler/scanner.ts"&gt;scanner&lt;/a&gt; converts the string text into &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/types.ts#L120-L280"&gt;syntax tokens&lt;/a&gt; (read: groups characters into meaningful chunks, like &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;"doggo"&lt;/code&gt;), and the &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/parser.ts#L584"&gt;parser&lt;/a&gt; converts those tokens into a tree structure of &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/types.ts#L622-L2561"&gt;nodes&lt;/a&gt;. (The root node is called a &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/types.ts#L2682"&gt;SourceFile&lt;/a&gt;.)&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://github.com/microsoft/TypeScript/blob/master/src/compiler/binder.ts"&gt;binder&lt;/a&gt; walks through the parse tree and finds declarations (read: places where names of stuff get introduced into some scope, e.g. variable declarations), creating &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/types.ts#L3776"&gt;symbols&lt;/a&gt; for them, links subsequent usages of those names to existing symbols, and builds a control flow graph.&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://github.com/microsoft/TypeScript/blob/master/src/compiler/checker.ts"&gt;checker&lt;/a&gt; gathers all the SourceFiles and walks their parse trees, creating &lt;a href="https://github.com/microsoft/TypeScript/blob/10e3f11c0d88b991eaca600ff71d01a603a769a3/src/compiler/types.ts#L4074"&gt;types&lt;/a&gt; for symbols and ensuring that the relationships between them make sense.&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://github.com/microsoft/TypeScript/blob/master/src/compiler/transformer.ts"&gt;transformer&lt;/a&gt; transforms the TypeScript parse tree to a plain JavaScript syntax tree and/or a declaration file syntax tree (stripping away type annotations, converting fancy new syntax ES5-compatible syntax, etc.), and the &lt;a href="https://github.com/microsoft/TypeScript/blob/master/src/compiler/emitter.ts"&gt;emitter&lt;/a&gt; writes those trees to text.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="///static/08eec80d0ea81a2f66db40c5e622c6cb/1d52b/ts-diagram-light.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NAMsLiON--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.andrewbran.ch/static/08eec80d0ea81a2f66db40c5e622c6cb/db64a/ts-diagram-light.png" alt="A rough, hand-drawn architecture diagram of the TypeScript codebase"&gt;&lt;/a&gt;&lt;/p&gt;
Whiteboarding the compiler structure. Not scientific. Not complete. Don’t @ me. Get out of here with your diagram nitpicking.



&lt;h3&gt;
  
  
  Know Your Nodes!
&lt;/h3&gt;

&lt;p&gt;If most of that review was new to you, don’t worry! You don’t need to know much more than that to start debugging, and it will make more sense once you dive in. A lot can be picked up on the fly. But, if there’s one thing you might not want to skimp on, it’s learning the proper terminology for syntax. By way of example, you might see the construct &lt;code&gt;x ? y : z&lt;/code&gt; and think of the term “ternary operator,” but this sequence is properly called a &lt;em&gt;ConditionalExpression&lt;/em&gt;. TypeScript uses the names from the &lt;a href="https://www.ecma-international.org/ecma-262/9.0/index.html"&gt;ECMAScript language specification&lt;/a&gt; for grammar productions that are valid in JavaScript, but it can be a little tricky to read, and there’s no corresponding document for TypeScript-specific grammar. I often use &lt;a href="https://astexplorer.net"&gt;astexplorer.net&lt;/a&gt; (language set to JavaScript, parser set to TypeScript) to jog my memory of what a certain syntax is called and how it’s structured. If you need the reverse, and you’re really stuck—you have a SyntaxKind you’re not familiar with and want to know what code produces it—you can always &lt;em&gt;read the parser&lt;/em&gt;! By way of example, if you’re not sure what a &lt;code&gt;TypeQueryNode&lt;/code&gt; is, can you get an idea from this?&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;parseTypeQuery&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;TypeQueryNode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SyntaxKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TypeQuery&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;TypeQueryNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;parseExpected&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SyntaxKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TypeOfKeyword&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exprName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;parseEntityName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/*allowReservedWords*/&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;finishNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;SyntaxKind.TypeOfKeyword&lt;/code&gt; followed by an &lt;code&gt;exprName&lt;/code&gt; of something called an “entity name”? Yep, it’s the bit after the colon token in &lt;code&gt;const x: typeof y&lt;/code&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Breakpoints by Syntax
&lt;/h3&gt;

&lt;p&gt;The reason you want to be familiar with proper names for syntax is that the parser, binder, checker, transformer, and emitter are in large part a collection of functions with names in the form &lt;em&gt;[verb][SyntaxKind]&lt;/em&gt;. Some examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/microsoft/TypeScript/blob/8cf13249eab1562de81bc4c426aa8aa8a979b6fb/src/compiler/parser.ts#L5749"&gt;&lt;code&gt;parseVariableDeclaration&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/microsoft/TypeScript/blob/8cf13249eab1562de81bc4c426aa8aa8a979b6fb/src/compiler/binder.ts#L3002"&gt;&lt;code&gt;bindCallExpression&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;checkComputedPropertyName&lt;/code&gt; (GitHub can’t render checker.ts, so I can’t link to the line)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/microsoft/TypeScript/blob/8cf13249eab1562de81bc4c426aa8aa8a979b6fb/src/compiler/transformers/ts.ts#L2396"&gt;&lt;code&gt;transformEnumMember&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/microsoft/TypeScript/blob/8cf13249eab1562de81bc4c426aa8aa8a979b6fb/src/compiler/emitter.ts#L2427"&gt;&lt;code&gt;emitConditionalExpression&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is very frequently the strategy I use to start debugging a problem. We should issue an error on &lt;code&gt;x.badProperty&lt;/code&gt; but we don’t? Look for a function in checker.ts called &lt;code&gt;checkPropertyAccessExpression&lt;/code&gt;. An expando property assignment fails to create a declaration on its container? Assignment is a form of binary expression, and there are only eight references to &lt;code&gt;SyntaxKind.BinaryExpression&lt;/code&gt; in the binder, so one of them should be near the culprit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Breakpoints by Diagnostic Message
&lt;/h3&gt;

&lt;p&gt;If you have a test case that emits a diagnostic message (read: red squiggly error) you don’t understand, finding the place to set a breakpoint is &lt;em&gt;really&lt;/em&gt; easy. Simply run a find-all inside the &lt;code&gt;src&lt;/code&gt; directory for a few words of the error message, with spaces replaced by underscores. For example, if you want to find out why you got the message “JSX element 'a' has no corresponding closing tag,” try searching for &lt;code&gt;has_no_corresponding_closing&lt;/code&gt; and you’ll &lt;a href="https://github.com/microsoft/TypeScript/blob/8cf13249eab1562de81bc4c426aa8aa8a979b6fb/src/compiler/parser.ts#L4412"&gt;find it&lt;/a&gt;. Set a breakpoint and work backwards by inspecting up the call stack if necessary.&lt;/p&gt;

&lt;p&gt;Be aware that substitutions like &lt;code&gt;'a'&lt;/code&gt; in that error are represented as numerals in the diagnostic property (&lt;code&gt;Diagnostics.JSX_element_0_has_no_corresponding_closing_tag&lt;/code&gt;), so you might want to avoid areas of the message that look dynamic or highly specific in your search terms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspecting Stuff while Paused
&lt;/h3&gt;

&lt;p&gt;Finally, now that you know where to pause the debugger, you’ll want to be able to inspect the current state of the compiler. Sure, you’re paused on &lt;code&gt;checkPropertyAccessExpression&lt;/code&gt;, but is this the property access expression you’re interested in? Here are a few of the most useful tips for determining just what you’re looking at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every Node object has a &lt;code&gt;__debugKind&lt;/code&gt; property (since &lt;code&gt;kind&lt;/code&gt; is just a number) and a &lt;code&gt;__debugGetText()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;You can get a node’s parent node through its &lt;code&gt;parent&lt;/code&gt; property. This is really useful in combination with &lt;code&gt;__debugGetText()&lt;/code&gt;, as it gives you a printout of the node you’re interested in, surrounded by some context.&lt;/li&gt;
&lt;li&gt;You can skip all the way up to a node’s source file by its &lt;code&gt;getSourceFile()&lt;/code&gt; method. A source file has a &lt;code&gt;fileName&lt;/code&gt; property, which is really handy for setting conditional breakpoints.&lt;/li&gt;
&lt;li&gt;Many types of object have some sort of bit flags property, set to an inscrutable number at runtime. These &lt;em&gt;usually&lt;/em&gt; have an accompanying property like &lt;code&gt;__debugFlags&lt;/code&gt; containing a string representation of the flags, but sometimes you wind up in a function with &lt;em&gt;just&lt;/em&gt; a variable with the flags value. In those circumstances, you can often find helper functions to format that number into a string under &lt;code&gt;ts.Debug&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="///static/57843d442573af90118faf6efd6cdfe4/83cbb/debugging-symbol-flags.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yPaaM92T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.andrewbran.ch/static/57843d442573af90118faf6efd6cdfe4/83cbb/debugging-symbol-flags.png" alt="A screenshot of a VS Code debug session, paused inspecting a variable `symbolFlags`, which is a long, inscrutable number. The debug console is open showing the user typed the command, `ts.Debug.formatSymbolFlags(symbolFlags)`. The evaluation shows the string value `Property|Module|Assignment`."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can access a function exported from the &lt;code&gt;ts&lt;/code&gt; namespace in another file by writing its fully qualified name in the debug console. I feel like this is worth mentioning because at most places in the source code, you can drop the &lt;code&gt;ts&lt;/code&gt; prefix and write functions like &lt;code&gt;isIdentifier(node)&lt;/code&gt;, but in the debug console, you have to write &lt;code&gt;ts.isIdentifier(node)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  You’re an expert! Now what?
&lt;/h2&gt;

&lt;p&gt;If this has made contributing to TypeScript feel less daunting, peruse through the issues labeled “&lt;a href="https://github.com/microsoft/TypeScript/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22"&gt;good first issue&lt;/a&gt;” or “&lt;a href="https://github.com/microsoft/TypeScript/issues?utf8=%E2%9C%93&amp;amp;q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+"&gt;help wanted&lt;/a&gt;.” Maybe you’ll find something that inspires you!&lt;sup id="fnref3"&gt;3&lt;/sup&gt;&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;VS Code’s &lt;a href="https://code.visualstudio.com/docs/editor/debugging"&gt;docs on debugging&lt;/a&gt; are good if you’re not familiar with it. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;li id="fn2"&gt;
&lt;p&gt;I’m not sure why the debugger starts in the built tsc.js file instead of the source tsc.ts file, but once you step into a different file, the debugger will bring up the TypeScript source instead of the built JavaScript. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;li id="fn3"&gt;
&lt;p&gt;Orta’s &lt;a href="https://github.com/orta/typescript-notes"&gt;typescript-notes&lt;/a&gt; also serve well as a first-time contributor’s guide. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
