oxc/crates/oxc
oxc-bot 5a1311e76c
release(crates): v0.44.0 (#8110)
## [0.44.0] - 2024-12-25

- ad2a620 ast: [**BREAKING**] Add missing
`AssignmentTargetProperty::computed` (#8097) (Boshen)

### Features

- c2daa20 ast: Add `Expression::into_inner_expression` (#8048)
(overlookmotel)
- 618b6aa codege: Minify whitespace in object getter / setter (#8080)
(Boshen)
- 4727667 codegen: Minify arrow expr `(x) => y` -> `x => y` (#8078)
(Boshen)
- 0562830 codegen: Minify string with backtick when needed (#8095)
(Boshen)
- 6237c05 codegen: Minify more whitespace (#8089) (Boshen)
- 6355b7c codegen: Minify `export { 's' as 's' }` -> `export { 's' }`
(#8093) (Boshen)
- fccfda9 codegen: Minify `class{static[computed]}` (#8088) (Boshen)
- f873139 codegen: Minify `for (_ of [])` -> `for(_ of[])` (#8086)
(Boshen)
- 8b8cbcd codegen: Minify `case "foo"` -> `case"foo"` (#8085) (Boshen)
- 414c118 codegen: Minify `yield "s"` -> `yield"s"` (#8084) (Boshen)
- f8f067b codegen: Minify class method `async*fn(){}` (#8083) (Boshen)
- 1d5ae81 codegen: Minify `const [foo] = bar` -> `const[foo]=bar`
(#8079) (Boshen)
- e3f78fb codegen: `new Foo()` -> `new Foo` when minify (#8077) (Boshen)
- d84d60a codegen: Minify numbers with large exponents (#8074) (Boshen)
- 373279b codegen: Balance string quotes when minify whitespace (#8072)
(Boshen)
- 5397fe9 minifier: Constant fold `undefined?.bar` -> `undefined`
(#8075) (Boshen)
- 1932f1e minifier: Fold `foo === undefined || foo === null` (#8063) (翠
/ green)
- 11c4bd8 span: Implement source type `{file basename}.d.{extension}.ts`
(#8109) (Boshen)
- be4feb4 syntax: Add `SymbolId::new` method (#8041) (overlookmotel)
- e632a7b transformer: Remove typescript symbols after transform (#8069)
(Boshen)

### Bug Fixes

- bdc241d codegen: Disallow template literals in object property key
(#8108) (Boshen)
- 728ed20 codegen: Print `yield * ident` correctly (Boshen)
- b605baa minifier: Constant fold strings with tab char (#8096) (Boshen)
- de82492 parser: Report syntax errors for missing constructor
implementations (#8081) (camc314)
- 55d6eb9 parser: Disallow type parameters on class constructors (#8071)
(injuly)
- be2c60d parser: Parse `import source from from 'mod'` (#8056) (Boshen)
- 708e9cf semantic: Report errors for missing class method impls (#8082)
(camc314)
- 3057686 transformer/class-properties: Unwrap parenthesised expressions
(#8049) (overlookmotel)
- e67cd05 transformer/class-properties: Correctly resolve private fields
pointing to private accessors (#8047) (overlookmotel)
- 6b08c6e transformer/class-properties: Correctly resolve private fields
pointing to private methods (#8042) (overlookmotel)
- 274f117 transformer/nullish-coalescing: Use correct scope id for
binding (#8053) (camc314)

### Performance

- 78d2e83 sourcemap: Improve perf of `search_original_line_and_column`
(#7926) (Cameron)

### Refactor

- 7110c7b codegen: Add `print_quoted_utf16` and `print_unquoted_utf16`
methods (#8107) (Boshen)
- 8b54d89 minifier: Remove parens must happen on enter (#8060) (Boshen)
- 7cb84f3 minifier: Only minify on ast node exit (#8059) (Boshen)
- 77d845a minifier: Fuse DCE AST passes (#8058) (Boshen)
- 6123f5e minifier: Fold statements on exit (#8057) (Boshen)
- cbd5169 transformer/class-properties: Do not recreate private field if
not transforming it (#8044) (overlookmotel)
- 98e8a72 transformer/class-properties: Do not take mut ref when immut
ref will do (#8040) (overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-25 21:03:09 +08:00
..
examples
src refactor(minifier): expose dce as an API instead of an option (#7957) 2024-12-17 04:47:13 +00:00
Cargo.toml release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
CHANGELOG.md release(crates): v0.42.0 (#7983) 2024-12-18 11:48:12 +08:00
README.md

OXC Logo

Crate Docs GitHub Website Playground

Oxc

The Oxidation Compiler is a high-performance web toolchain. This is an umbrella crate re-exporting all of oxc's different tools. It also adds higher-level APIs for stitching various components together that are not found in other oxc crates.

Quick Start

The easiest way to get started with oxc is by adding this to your Cargo.toml:

[dependencies]
oxc = { version = "*", features = ["full"] }

In most cases, code using oxc will follow this general pipeline:

  1. Parse source code into an AST
  2. Run semantic analysis on the AST
  3. Use the AST and semantic data in one or more other tools
  4. Generate new code for the final processed program

Example

This example performs the first two steps of this pipeline:

use std::path::Path;

use oxc::{
    allocator::Allocator,
    parser::{Parser, ParserReturn},
    span::SourceType,
    semantic::{SemanticBuilder, SemanticBuilderReturn}
};

// In real code, this will likely come from a file read from disk.
let source_path = Path::new("test.tsx");
let source_text = "
import React from 'react';
export interface Props {
    count: number;
    onInc: () => void;
    onDec: () => void;
}
export const Counter: React.FC<Props> = props => {
    return (
        <div>
            <button onClick={props.onInc}>+</button>
            <span id='count'>{props.count}</span>
            <button onClick={props.onDec}>-</button>
        </div>
    );
};
";

// Memory arena where AST nodes are allocated.
let allocator = Allocator::default();
// Infer source type (TS/JS/ESM/JSX/etc) based on file extension
let source_type = SourceType::from_path(source_path).unwrap();
let mut errors = Vec::new();

// Step 1: Parsing
// Parse the TSX file into an AST. The root AST node is a `Program` struct.
let ParserReturn { program, trivias, errors: parser_errors, panicked } =
    Parser::new(&allocator, source_text, source_type).parse();
errors.extend(parser_errors);

// Parsing failed completely. `program` is empty and `errors` isn't. If the
// parser could recover from errors, `program` will be a valid AST and
// `errors` will be populated. We can still perform semantic analysis in
// such cases (if we want).
if panicked {
    for error in &errors {
        eprintln!("{error:?}");
        panic!("Parsing failed.");
    }
}

// Step 2: Semantic analysis.
// Some of the more expensive syntax checks are deferred to this stage, and are
// enabled using `with_check_syntax_error`. You are not required to enable
// these, and they are disabled by default.
let SemanticBuilderReturn {
    semantic,
    errors: semantic_errors,
} = SemanticBuilder::new()
    .with_check_syntax_error(true) // Enable extra syntax error checking
    .with_build_jsdoc(true)        // Enable JSDoc parsing
    .with_cfg(true)                // Build a Control Flow Graph
    .build(&program);              // Produce the `Semantic`

errors.extend(semantic_errors);
if errors.is_empty() {
    println!("parsing and semantic analysis completed successfully.");
} else {
    for error in errors {
        eprintln!("{error:?}");
        panic!("Failed to build Semantic for Counter component.");
    }
}

// From here, you can now pass `program` and `semantic` to other tools.

💡 Features

These feature flags enable/disable various tools in oxc's toolchain:

  • full: Enable all features that provide access to a tool.
  • semantic: Enable the semantic module for semantic analysis on ASTs.
  • transformer: Enable the transform module for babel-like transpiling.
  • minifier: Enable the minifier and mangler modules for terser-like minification.
  • codegen: Enable the codegen module, which prints ASTs to source code.
  • mangler: Enable the mangler module without enabling minifier.
  • cfg: Expose the cfg module. CFGs may still be created in semantic without turning this on.
  • sourcemap: Enable the sourcemap module. Useful when using codegen to print both source code and source maps.
  • isolated_declarations: enable the isolated_declarations module for generating typescript type declarations

These feature flags modify the behavior of oxc's tools. None of them are enabled by the full feature.

  • serialize: Implements Serialize and Deserialize for various oxc data structures.
  • sourcemap_concurrent: Generate source maps in parallel. Only useful when the sourcemap feature is also enabled.
  • wasm: Enable WASM bindings for the transformer/transpiler. Only useful when the transformer feature is enabled.