The JavaScript Oxidation Compiler -> Linter / Prettier

Overview

The JavaScript Oxidation Compiler (oxc)

Why this project?

The goal of this project is to:

  • Create a blazingly fast JavaScript Compiler written in Rust.
  • Provide good documentation on learning Rust and compiler techniques.

And mostly importantly, an invitation for you to come and learn Rust with me. We will learn a lot from each other!

You can watch this project and also follow me on twitter if you don't have the time to Rust but would like to learn things.

Call for action

We now have a fully working parser as a baseline, it is not polished yet, so it would be much appreciated if I can invite you and review any of the code and point out for improvements. I welcome all nitpickings and bikesheddings.

I have crated some discussions.

Milestone

The current objective is to improve the parser for real usage. Areas include:

  • API
  • Diagnostics reporting
  • Performance
  • Pass more conformance tests

Conformance

The cargo coverage currently reports the following summary

Test262 Summary:
AST Parsed     : 43934/43934 (100.00%)

Babel Summary:
AST Parsed     : 2044/2057 (99.37%)

TypeScript Summary:
AST Parsed     : 4290/4861 (88.25%)

(The parser is failing some of the TypeScript recoverable parser tests.)

Learning Resources

Credits

This project is inspired by the following great mentors and projects:

License

MIT

Comments
  • perf(lexer): utilize jump table for distinguishing tokens (~5% improvement)

    perf(lexer): utilize jump table for distinguishing tokens (~5% improvement)

    I had a gut feeling this will make it faster but I don't know the precise reason.

    Something along the lines of LLVM / branch prediction / cache friendliness ...

    opened by Boshen 4
  • perf(lexer): use simd to speed up multiline comment scanner

    perf(lexer): use simd to speed up multiline comment scanner

    This uses SIMD for speeding up the multiline comment lexer.

    e.g.

    babylon.max.js (10M) has 14241 occurrences of multiline comments. typescript.js (9.6M) 22183 occurrences of multiline comments.

    But I have yet to figure out

    • [x] how to detect newlines properly in this PR.
    • [x] The current hiccup is due to the multi-byte newline character LS and PS.
    opened by Boshen 2
  • perf(lexer): use SIMD to skip single line comment

    perf(lexer): use SIMD to skip single line comment

    Speeding up single line comment parsing should save a few millisecond.

    image

    On the other hand, skipping multi-line comments in chunks will give us a huge improvement.

    opened by Boshen 2
  • Perf: Use `u32` instead of `usize` for Span

    Perf: Use `u32` instead of `usize` for Span

    u32 is enough for spans.

    https://github.com/Boshen/oxc/blob/b6912513ba93ebb01ebc8882598951e26a79ea6c/crates/oxc_ast/src/node.rs#L11-L18

    This is currently using usize because miette only accepts Range in its miette::Diagnostic macro.

    https://github.com/Boshen/oxc/blob/b6912513ba93ebb01ebc8882598951e26a79ea6c/crates/oxc_diagnostics/src/lib.rs#L29-L33

    There should be a workaround but I haven't investigated in detail yet.

    opened by Boshen 2
  • docs(oxc_parser): add header symbol for `parser.unexpected`'s doc comment

    docs(oxc_parser): add header symbol for `parser.unexpected`'s doc comment

    Description

    It seems that there should exist a # symbol to make Panics be an title when user see the document comment.

    Additional Information

    I'm highly interested in this project, but I'm a newbie in Rust and compiler. Currently trying to understand the compiler concepts from the guide you wrote and trying to understand this great project :)

    I'm also not good at english writing, so if I have written anything that offend you, please accept my apologies.

    opened by jason89521 1
  • perf(parser): remove the `?` operator?

    perf(parser): remove the `?` operator?

    opened by Boshen 1
  • perf(lexer): Use SIMD to accelerate whitespace skipping

    perf(lexer): Use SIMD to accelerate whitespace skipping

    Sometime ago I drafted a version to use SIMD for skipping whitespaces:

    image

    In this good first issue, you should be able to replicate the code from above, and add it to the lexer.

    You should refactor the code above into a function and call the function just above the while loop:

    https://github.com/Boshen/oxc/blob/93993978de969589f1fb91a689594a5e5c4b8f02/crates/oxc_parser/src/lexer/mod.rs#L320-L330

    You will also need to add #![feature(portable_simd)] to the top of crates/oxc_parser/src/lib.rs

    To the run parser, you can run the example binary:

    https://github.com/Boshen/oxc/blob/3daf5bcea95f6fe2c88a7956948f4cb22711f99e/crates/oxc_parser/examples/simple.rs#L7-L10

    Background reading:

    • https://rapidjson.org/md_doc_internals.html#SkipwhitespaceWithSIMD
    • https://github.com/Tencent/rapidjson/blob/bdc49ad80a3cff89a25839dcdcd6a68b457ec9f1/include/rapidjson/reader.h#L258-L517
    • https://lemire.me/blog/2017/01/20/how-quickly-can-you-remove-spaces-from-a-string
    good first issue 
    opened by Boshen 1
  • perf: add jemallocator

    perf: add jemallocator

    The global allocator is slower.

    The final configuration should follow swc once we have a binary.

    NOTE: Replacing the allocator has not effect at the moment because all of the parser's memory is allocated by bumpalo and dropped at wholesale.

    opened by Boshen 1
  • feat(tasks): add parser benchmark

    feat(tasks): add parser benchmark

    On my 2.6 GHz 6-Core Intel Core i7 laptop.

    group                    base
    -----                    ----
    parser/babylon.max.js    1.00    104.9±3.14ms    98.4 MB/sec
    parser/d3.js             1.00     13.1±1.51ms    41.7 MB/sec
    parser/lodash.js         1.00      4.5±0.34ms   113.0 MB/sec
    parser/pdf.js            1.00      7.4±0.45ms    54.0 MB/sec
    parser/typescript.js     1.00    104.3±2.99ms    92.3 MB/sec
    
    opened by Boshen 1
  • feat: printer

    feat: printer

    It seems I need a way to verify the code is correct.

    Basically a parse -> print -> parse routine will sufficiently indicate if parsing is correct.

    opened by Boshen 0
  • feat(coverage): print parsing conformance for test262 (currently 100%)

    feat(coverage): print parsing conformance for test262 (currently 100%)

    Running cargo coverage prints

    Test262 Summary:
    AST Parsed     : 43934/43934 (100.00%)
    

    The current parser parses all of test262.

    "Positive Passed" and "Negative Passed" are commented out in the code because they not meaningful right now. They will become meaningful once semantic analysis is in place.

    opened by Boshen 0
  • Umbrella: Better Parser Diagnostics

    Umbrella: Better Parser Diagnostics

    The conformance task now snapshots all diagnostics:

    What you can do is review these diagnostics and improve them, you can checkout babel or tsc for reference, by using https://astexplorer.net/

    To begin with, it should be relative easy to fix some of the Unexpected token errors.

    good first issue 
    opened by Boshen 4
Owner
Boshen
Working on RSPack (Rust Webpack). Working on a new JavaScript / TypeScript Linter.
Boshen
A Faster(⚡) formatter, linter, bundler, and more for JavaScript, TypeScript, JSON, HTML, Markdown, and CSS Lapce Plugin

Lapce Plugin for Rome Lapce-rome is a Lapce plugin for rome, The Rome is faster ⚡ , A formatter, linter, compiler, bundler, and more for JavaScript, T

xiaoxin 7 Dec 16, 2022
Opinionated, zero-config linter for JavaScript monorepos

Sherif: Opinionated, zero-config linter for JavaScript monorepos About Sherif is an opinionated, zero-config linter for JavaScript monorepos. It runs

Tom Lienard 219 Oct 10, 2023
Just in time Oxidation. A little experimentation with inkwell and copy-and-patch compilation

Experimental Copy-and-Patch compiler backend written in Rust This is supposed to become an experimental compiler backend based on Copy and Patch to be

Michael Zinsmeister 4 Feb 27, 2024
Socket Monitor: A prettier and simpler alternative to netstat or ss for socket monitoring with the ability to scan for malicious IP addresses.

?? Somo A prettier alternative to netstat or ss for socket monitoring. ⬇️ Installation: 1. Install cargo: From crates.io. 2. Install the somo crate: c

Theodor Peifer 13 Jun 6, 2023
An extremely fast Python linter, written in Rust.

Ruff An extremely fast Python linter, written in Rust. Linting the CPython codebase from scratch. ⚡️ 10-100x faster than existing linters ?? Installab

Charlie Marsh 5.1k Dec 30, 2022
Build terminal dashboards using ascii/ansi art and javascript

blessed-contrib Build dashboards (or any other application) using ascii/ansi art and javascript. Friendly to terminals, ssh and developers.

Yaron Naveh 15k Jan 2, 2023
Js-macros - Quickly prototype Rust procedural macros using JavaScript or TypeScript!

js-macros Quickly prototype Rust procedural macros using JavaScript or TypeScript! Have you ever thought "this would be a great use case for a procedu

null 15 Jun 17, 2022
Valq - macros for querying and extracting value from structured data by JavaScript-like syntax

valq   valq provides a macro for querying and extracting value from structured data in very concise manner, like the JavaScript syntax. Look & Feel: u

Takumi Fujiwara 24 Dec 21, 2022
Eslint - Find and fix problems in your JavaScript code.

ESLint Website | Configuring | Rules | Contributing | Reporting Bugs | Code of Conduct | Twitter | Mailing List | Chat Room ESLint is a tool for ident

ESLint 22k Jan 9, 2023
Execute Javascript code in the Dioxus, and get the return value ( for Dioxus )

Golde Dioxus Execute Javascript code in the Dioxus, and get the return value. This demo can help use Javascript to calc the + operator formula. use di

YuKun Liu 15 Dec 27, 2022
Pure Rust implementation of Javascript Object Signing and Encryption (JOSE)

RustCrypto: JOSE Pure Rust implementation of Javascript Object Signing and Encryption (JOSE) License All crates licensed under either of Apache Licens

Rust Crypto 20 Dec 24, 2022
Abuse the node.js inspector mechanism in order to force any node.js/electron/v8 based process to execute arbitrary javascript code.

jscythe abuses the node.js inspector mechanism in order to force any node.js/electron/v8 based process to execute arbitrary javascript code, even if t

Simone Margaritelli 301 Jan 4, 2023
Resolve JavaScript/TypeScript module with Rust

ES Resolve JavaScript/TypeScript module resolution in Rust Installation cargo add es_resolve Get Started use std::path::{Path, PathBuf}; use es_resolv

wang chenyu 2 Oct 12, 2022
compile TypeScript or JavaScript to binaries

the powr project Development is paused until 2023. ?? powr aims to be a javascript/typescript engine to power serverless functions over the web. the j

powr.js 18 Dec 29, 2022
Demo app duplicated in 5 languages (Go/JavaScript/Python/Ruby/Rust) showing how to go from source code to container image using melange+apko

hello-melange-apko ?? This repo contains an example app duplicated across 5 languages showing how to: Package source code into APKs using melange Buil

Chainguard 16 Jan 23, 2023
High-performance Javascript color gradient library powered by Rust + WebAssembly

colorgrad-js High-performance Javascript color gradient library powered by Rust + WebAssembly. No dependencies. Faster than d3-scale, chroma-js, culor

Nor Khasyatillah 168 Apr 25, 2023
JavaScript/TypeScript runtime Deno was meant to be.

Project Bueno (temporary name) Bueno is a web-standards focused JS/TS runtime with as much tooling built-in as possible. It is meant to be both a lear

Bueno 22 Sep 3, 2023
🚀 JavaScript driver for ScyllaDB, harnessing Rust's power through napi-rs for top performance. Pre-release stage. 🧪🔧

?? JavaScript driver for ScyllaDB. Pre-release stage. ???? ⚠️ Disclaimer ⚠️ This repository and the associated npm package are currently in a ?? pre-r

Daniel Boll 16 Oct 21, 2023
Minimal Pandoc compiler -> HTML

Minimal Pandoc compiler -> HTML

/c/ympfh 1 Apr 6, 2022