Skip to content

sxzz/ast-explorer

Folders and files

NameName
Last commit message
Last commit date
Mar 11, 2025
Feb 2, 2025
Mar 28, 2025
Mar 24, 2025
Mar 11, 2025
Mar 11, 2025
Mar 18, 2025
Mar 11, 2025
Mar 24, 2025
Mar 24, 2025
Mar 13, 2025
Sep 3, 2023
Feb 13, 2025
Sep 3, 2023
Sep 3, 2023
Feb 3, 2025
Sep 3, 2023
Mar 24, 2025
Mar 3, 2025
Mar 10, 2025
Mar 26, 2025
Apr 1, 2025
Apr 1, 2025
Sep 2, 2023
Sep 2, 2023
Mar 3, 2025

Repository files navigation

AST Explorer

AST Explorer - A web tool to explore the ASTs generated by parsers.

Feel free to add more languages and parsers via PR!

Screenshot

Features

  • 🦾 Enable code highlighting, suggestions, and formatting with Monaco Editor.
  • 🤩 Support most popular front-end languages and parsers.
  • 🗒️ Save your code via URL. No database, no server downtime.
  • 🐙 Customize parser version via CDN, e.g., @babel/parser alpha.
  • 🌈 Set custom parser options with a GUI.
  • 🌚 Good-looking dark mode theme.
  • 📱 Even compatible with mobile devices.

Languages and Parsers

URL Encode Algorithm

The input code and options are stored in the URL as a hash fragment, which is the string following the # symbol and is not transmitted to the server.

Implementation

const code = 'code'
const parserId = 'acorn'
const optionsString = JSON.stringify({
  ecmaVersion: 'latest',
  sourceType: 'module',
})
const serialized = utoa(
  // utoa, or compress() if want to compress the data
  JSON.stringify({
    c: code,
    p: parserId,
    o: optionsString,
  }),
)
const url = `https://ast-explorer.dev/#${serialized}`

// no compress
function utoa(data: string): string {
  return btoa(unescape(encodeURIComponent(data)))
}

// compress is optional
import { strFromU8, strToU8, unzlibSync, zlibSync } from 'fflate'
function compress(data: string) {
  const buffer = strToU8(data)
  const zipped = zlibSync(buffer, { level: 9 })
  const binary = strFromU8(zipped, true)
  return btoa(binary)
}

Contributing

To contribute to the project, see Contribution Guide.

Credits

Sponsors

License

AGPL-3.0 License © 2023-PRESENT 三咲智子