11.09.2015 Views

Typescript Deep Dive by Basarat Ali Syed

Typescript Deep Dive by Basarat Ali Syed

Typescript Deep Dive by Basarat Ali Syed

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TypeScript <strong>Deep</strong> <strong>Dive</strong><br />

}<br />

}<br />

return emitImportDeclaration(node);<br />

case SyntaxKind.ImportEqualsDeclaration:<br />

return emitImportEqualsDeclaration(node);<br />

case SyntaxKind.ExportDeclaration:<br />

return emitExportDeclaration(node);<br />

case SyntaxKind.ExportAssignment:<br />

return emitExportAssignment(node);<br />

case SyntaxKind.SourceFile:<br />

return emitSourceFileNode(node);<br />

Recursion is done <strong>by</strong> simply calling other emitFoo function from these functions as needed e.g. from<br />

emitFunctionDeclaration :<br />

function emitFunctionDeclaration(node: FunctionLikeDeclaration) {<br />

if (nodeIsMissing(node.body)) {<br />

return emitOnlyPinnedOrTripleSlashComments(node);<br />

}<br />

if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) {<br />

// Methods will emit the comments as part of emitting method declaration<br />

emitLeadingComments(node);<br />

}<br />

// For targeting below es6, emit functions-like declaration including arrow function using function keyword.<br />

// When targeting ES6, emit arrow function natively in ES6 <strong>by</strong> omitting function keyword and using fat arrow instead<br />

if (!shouldEmitAsArrowFunction(node)) {<br />

if (isES6ExportedDeclaration(node)) {<br />

write("export ");<br />

if (node.flags & NodeFlags.Default) {<br />

write("default ");<br />

}<br />

}<br />

}<br />

write("function");<br />

if (languageVersion >= ScriptTarget.ES6 && node.asteriskToken) {<br />

write("*");<br />

}<br />

write(" ");<br />

if (shouldEmitFunctionName(node)) {<br />

emitDeclarationName(node);<br />

}<br />

}<br />

emitSignatureAndBody(node);<br />

if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node<br />

emitExportMemberAssignments((node).name);<br />

}<br />

if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) {<br />

emitTrailingComments(node);<br />

}<br />

Emitter Functions<br />

100

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!