From 6550da62966e7829a0a44d48f7d6418f17b00241 Mon Sep 17 00:00:00 2001 From: imteekay Date: Thu, 20 Jul 2023 07:31:19 -0300 Subject: [PATCH] * --- .../en/index.mdx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/content/building-emptystatement-and-semicolon-as-statement-ender-for-the-typescript-compiler/en/index.mdx b/content/building-emptystatement-and-semicolon-as-statement-ender-for-the-typescript-compiler/en/index.mdx index 65eee1ac..6961cb89 100644 --- a/content/building-emptystatement-and-semicolon-as-statement-ender-for-the-typescript-compiler/en/index.mdx +++ b/content/building-emptystatement-and-semicolon-as-statement-ender-for-the-typescript-compiler/en/index.mdx @@ -149,6 +149,35 @@ Let's go to the type checker. ## `Type Checker`: checking empty statements +As we created a new AST node for statements, we need to return a new type for it in the type checking process. This is the new type for empty statements: + +```tsx +const empty: Type = { id: 'empty' }; +``` + +And when the compiler is checking the empty statement, we just need to return this new type. + +```tsx +case Node.EmptyStatement: + return empty; +``` + +## Transforming and emitting JS + +In the transformation process, we don't need to do anything extra in terms of transformation, it should just return the actual empty statement. + +```tsx +case Node.EmptyStatement: + return [statement]; +``` + +The emitting process is pretty similar. When handling the emit for empty statements, the compiler will return an empty string so it doesn't return anything. + +```tsx +case Node.EmptyStatement: + return ''; +``` + ## Final words In this piece of content, my goal was to show the whole implementation of string literals: