npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rsx-parser

v0.3.2

Published

RSX file parser - parses .rsx files into AST

Readme

rsx-parser

RSX 文件的 AST 解析器,用于将 RSX 文件转换为前端可用的 AST。

安装

npm install tree-sitter tree-sitter-rust tree-sitter-typescript tree-sitter-html tree-sitter-scss

使用

const RSXParser = require('./parser')

const parser = new RSXParser()
const content = `
---
use rsx::{Request, Response};

async fn get_server_side_props(req: Request) -> Response {
    Response::json!({
        "message": "Hello"
    })
}
---

<script>
const { message } = defineProps<{ message: string }>()
</script>

<template>
    <div>{{ message }}</div>
</template>

<style>
div { color: red; }
</style>
`

const result = parser.parse(content)
console.log(parser.generateReport(result))

RSX 语法规范

文件结构

RSX 文件包含四个可选的代码块,每种代码块最多出现一次:

  • Rust Section: --- ... --- - 服务端 Rust 代码
  • Script Section: <script> ... </script> - 客户端 TypeScript 代码
  • Template Section: <template> ... </template> - HTML 模板
  • Style Section: <style> ... </style> - SCSS 样式

模板指令

条件渲染

{{@if condition}}
    <p>条件为真时显示</p>
{{:else if anotherCondition}}
    <p>另一个条件为真时显示</p>
{{:elseif yetAnotherCondition}}
    <p>elseif 也支持(无空格)</p>
{{:else}}
    <p>所有条件都为假时显示</p>
{{/if}}

列表渲染

{{@each items as item, index}}
    <li>{{ index }}: {{ item.name }}</li>
{{/each}}

原始 HTML

{{@html rawHtmlContent}}

文本插值

<p>{{ message }}</p>
<p>{{ user.name }}</p>
<p>{{ formatDate(date) }}</p>
<p>{{ isActive ? 'Active' : 'Inactive' }}</p>

客户端组件

<ReactApp client="react" users="{{ users }}" />
<VueChart client="vue" data="{{ chartData }}" />
<SvelteWidget client="svelte" items="{{ items }}" />

API

parse(content: string): RSXFile

解析 RSX 文件内容,返回解析结果。

getParseStatistics(parseResult: RSXFile): ParseStatistics

获取解析统计信息。

generateReport(parseResult: RSXFile): string

生成格式化的解析报告。

parseExpression(expression: string): ParsedExpression

解析模板表达式。

validateRSXStructure(parseResult: RSXFile): ParseError[]

验证 RSX 文件结构。

支持的表达式类型

  • 标识符: message
  • 属性访问: user.name, data.items.length
  • 函数调用: formatDate(date), items.filter(x => x.active)
  • 二元表达式: a + b, x > 0 && y < 10, a === b
  • 一元表达式: !isActive, -value
  • 条件表达式: condition ? trueValue : falseValue
  • 字面量: "string", 'string', 123, true, false

错误处理

解析器会检测以下错误:

  • 重复的代码块
  • 语法错误
  • 无效的指令
  • 不支持的客户端组件类型
  • 模板中的禁用标签
  • HTML 标签中的事件属性