Skip to content

Commit aeb887d

Browse files
doc: add blog
1 parent 437cee0 commit aeb887d

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

website/blog/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Blog
22

3-
* [Design Space for Code Search](/blog/code-search-design-space.html)
3+
* [Design Space for Code Search](/blog/code-search-design-space.html)

website/blog/typed-napi.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
sidebar: false
33
---
44

5-
# Improve Napi Typing
5+
# ast-grep's Journey to Type Safety in Node API
66

7-
> _Design, Define, Refine, and Confine: Crafting Balanced TypeScript Types_
7+
> Recipe to Craft Balanced Types: _Design, Define, Refine, and Confine_
88
99
We're thrilled to introduce typed AST in [@ast-grep/napi], addressing a [long-requested feature](https://github.com/ast-grep/ast-grep/issues/48) for AST manipulation from the early days of this project.
1010

1111
In this blog post, we will delve into the challenges addressed by this feature and explore [the design](https://github.com/ast-grep/ast-grep/issues/1669) that shaped its implementation. _We also believe this post can serve as a general guide to crafting balanced TypeScript types._
1212

13-
## Why Type Safety Matters in AST
13+
![napi screenshot](/image/blog/napi.jpeg)
14+
15+
## Type Safety in AST
1416

1517
Working with Abstract Syntax Trees (ASTs) is complex. Even with AST [excellent](https://astexplorer.net/) [AST](https://ast-grep.github.io/playground.html) [tools](https://github.com/sxzz/ast-kit), handling all edge cases remains challenging.
1618

1719
Type information serves as a crucial safety net when writing AST manipulation code. It guides developers toward handling all possible cases and enables exhaustive checking to ensure complete coverage.
1820

1921
While `ast-grep/napi` has been a handy tool for programmatic AST processing, it previously lacked type information to help users write robust code. Thank to [Mohebifar](https://github.com/mohebifar) from [codemod](https://codemod.com/), we've now bridged this gap. Our solution generates types from parsers' metadata and employs TypeScript tricks to create an idiomatic API.
2022

21-
## Qualities of Good TypeScript Types
23+
## Qualities of Good Types
2224

2325
Before diving into our implementation, let's explore what makes TypeScript definitions truly effective. In today's JavaScript ecosystem, creating a great library involves more than just intuitive APIs and thorough documentation – it requires thoughtful type definitions that enhance developer experience.
2426

@@ -236,7 +238,7 @@ This approach, inspired by [Biome's Rowan API](https://github.com/biomejs/biome/
236238
237239
This hybrid approach gives developers the best of both worlds: strict type checking when types are known, with the flexibility to fall back to string-based typing when needed.
238240
239-
## Refine Type
241+
## Refine Types
240242
241243
Now let's talk about how to refine the general node to a specific node in ast-grep/napi.
242244
We've implemented two concise and idiomatic approaches in TypeScript: manual and automatic refinement.
@@ -409,6 +411,8 @@ sgNode.find({
409411
})
410412
```
411413

414+
![napi screenshot](/image/blog/rule.jpeg)
415+
412416
## Ending
413417

414418
I'm incredibly excited about the future of AST manipulation in TypeScript.
@@ -419,4 +423,4 @@ As Theo aptly puts it in [his video](https://www.youtube.com/clip/Ugkxn2oomDuyQj
419423

420424
> There are very few devs that understands Rust deeply enough and compiler deeply enough that also care about TypeScript in web dev enough to build something for web devs in Rust
421425
422-
ast-grep is determined to bridge that gap between Rust and TypeScript!
426+
ast-grep is determined to bridge that gap between Rust and TypeScript!

website/public/image/blog/napi.jpeg

191 KB
Loading

website/public/image/blog/rule.jpeg

158 KB
Loading

website/src/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Remove all the styles of the "User-Agent-Stylesheet", except for the 'display' property
88
- The "symbol *" part is to solve Firefox SVG sprite bug
99
*/
10-
*:where(:not(html, iframe, canvas, img, svg, video, audio, s):not(svg *, symbol *)) {
10+
*:where(:not(html, iframe, canvas, img, svg, video, audio, s, em):not(svg *, symbol *)) {
1111
all: unset;
1212
display: revert;
1313
}

0 commit comments

Comments
 (0)