Skip to content

Commit

Permalink
Merge branch 'main' into plugin-jsdoc/check-access
Browse files Browse the repository at this point in the history
  • Loading branch information
leaysgur authored Apr 4, 2024
2 parents 36d926b + 6823482 commit ab77d00
Show file tree
Hide file tree
Showing 55 changed files with 3,132 additions and 1,772 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[alias]
# Do not append `--` or it will break IDEs
ck = "check --workspace --all-targets --locked"
ck = "check --workspace --all-features --all-targets --locked"
lint = "clippy --workspace --all-targets --all-features"
codecov = "llvm-cov --workspace --ignore-filename-regex tasks"
coverage = "run -p oxc_coverage --release --"
Expand Down
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ repository = "https://github.com/oxc-project/oxc"
rust-version = "1.74"

[workspace.lints.rust]
unsafe_code = "warn"

[workspace.lints.clippy]
all = { level = "warn" }
Expand Down Expand Up @@ -66,19 +67,19 @@ cargo_common_metadata = "allow" # TODO: fix this

[workspace.dependencies]
# publish = true
oxc = { version = "0.11.0", path = "crates/oxc" }
oxc_allocator = { version = "0.11.0", path = "crates/oxc_allocator" }
oxc_ast = { version = "0.11.0", path = "crates/oxc_ast" }
oxc_codegen = { version = "0.11.0", path = "crates/oxc_codegen" }
oxc_diagnostics = { version = "0.11.0", path = "crates/oxc_diagnostics" }
oxc_index = { version = "0.11.0", path = "crates/oxc_index" }
oxc_minifier = { version = "0.11.0", path = "crates/oxc_minifier" }
oxc_parser = { version = "0.11.0", path = "crates/oxc_parser" }
oxc_semantic = { version = "0.11.0", path = "crates/oxc_semantic" }
oxc_span = { version = "0.11.0", path = "crates/oxc_span" }
oxc_syntax = { version = "0.11.0", path = "crates/oxc_syntax" }
oxc_transformer = { version = "0.11.0", path = "crates/oxc_transformer" }
oxc_sourcemap = { version = "0.11.0", path = "crates/oxc_sourcemap" }
oxc = { version = "0.12.1", path = "crates/oxc" }
oxc_allocator = { version = "0.12.1", path = "crates/oxc_allocator" }
oxc_ast = { version = "0.12.1", path = "crates/oxc_ast" }
oxc_codegen = { version = "0.12.1", path = "crates/oxc_codegen" }
oxc_diagnostics = { version = "0.12.1", path = "crates/oxc_diagnostics" }
oxc_index = { version = "0.12.1", path = "crates/oxc_index" }
oxc_minifier = { version = "0.12.1", path = "crates/oxc_minifier" }
oxc_parser = { version = "0.12.1", path = "crates/oxc_parser" }
oxc_semantic = { version = "0.12.1", path = "crates/oxc_semantic" }
oxc_span = { version = "0.12.1", path = "crates/oxc_span" }
oxc_syntax = { version = "0.12.1", path = "crates/oxc_syntax" }
oxc_transformer = { version = "0.12.1", path = "crates/oxc_transformer" }
oxc_sourcemap = { version = "0.12.1", path = "crates/oxc_sourcemap" }

# publish = false
oxc_macros = { path = "crates/oxc_macros" }
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxc"
version = "0.11.0"
version = "0.12.1"
publish = true
authors.workspace = true
description.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_allocator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxc_allocator"
version = "0.11.0"
version = "0.12.1"
authors.workspace = true
description.workspace = true
edition.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_allocator/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::Allocator;
pub struct Box<'alloc, T: ?Sized>(pub &'alloc mut T);

impl<'alloc, T> Box<'alloc, T> {
#[allow(unsafe_code)]
pub fn unbox(self) -> T {
// SAFETY:
// This pointer read is safe because the reference `self.0` is
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_ast/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this crate will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0.

## [0.11.1] - 2024-04-03

### Bug Fixes

- `FinallyClause` won't get visited as `BlockStatement` anymore. (#2881)

## [0.11.0] - 2024-03-30

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxc_ast"
version = "0.11.0"
version = "0.12.1"
authors.workspace = true
description.workspace = true
edition.workspace = true
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_ast/src/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ impl<'a> AstBuilder<'a> {
// SAFETY:
// This should be safe as long as `src` is an reference from the allocator.
// But honestly, I'm not really sure if this is safe.
unsafe { std::mem::transmute_copy(src) }
#[allow(unsafe_code)]
unsafe {
std::mem::transmute_copy(src)
}
}

/// Moves the expression out by replacing it with a null expression.
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_ast/src/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ ast_kinds! {
TSPropertySignature(&'a TSPropertySignature<'a>),
}

#[allow(unsafe_code)]
// SAFETY:
// The AST is part of the bump allocator,
// it is our responsibility to never simultaneously mutate across threads.
unsafe impl<'a> Send for AstKind<'a> {}
#[allow(unsafe_code)]
// SAFETY:
// The AST is part of the bump allocator,
// it is our responsibility to never simultaneously mutate across threads.
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_ast/src/visit/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub trait Visit<'a>: Sized {
// SAFETY:
// This should be safe as long as `src` is an reference from the allocator.
// But honestly, I'm not really sure if this is safe.
unsafe { std::mem::transmute(t) }
#[allow(unsafe_code)]
unsafe {
std::mem::transmute(t)
}
}

fn visit_program(&mut self, program: &Program<'a>) {
Expand Down
16 changes: 16 additions & 0 deletions crates/oxc_codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this crate will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project does not adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) until v1.0.0.

## [0.11.2] - 2024-04-03

### Bug Fixes

- avoid unsafe code search original name (#2895)

## [0.11.1] - 2024-04-03

### Bug Fixes

- Using serde_json::to_string to quote sourcemap string (#2889)

### Refactor

- Make codegen sourcemap builder clearer (#2894)

## [0.11.0] - 2024-03-30

### Features
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxc_codegen"
version = "0.11.0"
version = "0.12.1"
publish = true
authors.workspace = true
description.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/examples/sourcemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> std::io::Result<()> {
.build(&ret.program);

if let Some(source_map) = source_map {
let result = source_map.to_json_string();
let result = source_map.to_json_string().unwrap();
let hash = BASE64_STANDARD.encode(format!(
"{}\0{}{}\0{}",
source_text.len(),
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,10 @@ fn print_non_negative_float<const MINIFY: bool>(value: f64, _p: &Codegen<{ MINIF
let dot = chars.iter().position(|&c| c == b'.');
let u8_to_string = |num: &[u8]| {
// SAFETY: criteria of `from_utf8_unchecked`.are met.
unsafe { String::from_utf8_unchecked(num.to_vec()) }
#[allow(unsafe_code)]
unsafe {
String::from_utf8_unchecked(num.to_vec())
}
};

if dot == Some(1) && chars[0] == b'0' {
Expand Down
29 changes: 19 additions & 10 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ mod gen;
mod gen_ts;
mod operator;
mod sourcemap_builder;
use std::str::from_utf8_unchecked;

#[allow(clippy::wildcard_imports)]
use oxc_ast::ast::*;
Expand Down Expand Up @@ -72,7 +71,7 @@ pub struct Codegen<const MINIFY: bool> {
/// Track the current indentation level
indentation: u8,

sourcemap_builder: SourcemapBuilder,
sourcemap_builder: Option<SourcemapBuilder>,
}

#[derive(Debug, Clone, Copy)]
Expand All @@ -89,10 +88,12 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
let source_len = source_text.len();
let capacity = if MINIFY { source_len / 2 } else { source_len };

let mut sourcemap_builder = SourcemapBuilder::default();
if options.enable_source_map {
let sourcemap_builder = options.enable_source_map.then(|| {
let mut sourcemap_builder = SourcemapBuilder::default();
sourcemap_builder.with_name_and_source(source_name, source_text);
}
sourcemap_builder
});

Self {
options,
// mangler: None,
Expand All @@ -117,13 +118,16 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
pub fn build(mut self, program: &Program<'_>) -> CodegenReturn {
program.gen(&mut self, Context::default());
let source_text = self.into_source_text();
let source_map = self.sourcemap_builder.into_sourcemap();
let source_map = self.sourcemap_builder.map(SourcemapBuilder::into_sourcemap);
CodegenReturn { source_text, source_map }
}

pub fn into_source_text(&mut self) -> String {
// SAFETY: criteria of `from_utf8_unchecked` are met.
unsafe { String::from_utf8_unchecked(std::mem::take(&mut self.code)) }
#[allow(unsafe_code)]
unsafe {
String::from_utf8_unchecked(std::mem::take(&mut self.code))
}
}

fn code(&self) -> &Vec<u8> {
Expand Down Expand Up @@ -178,8 +182,9 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
}

fn peek_nth(&self, n: usize) -> Option<char> {
#[allow(unsafe_code)]
// SAFETY: criteria of `from_utf8_unchecked` are met.
unsafe { from_utf8_unchecked(self.code()) }.chars().nth_back(n)
unsafe { std::str::from_utf8_unchecked(self.code()) }.chars().nth_back(n)
}

fn indent(&mut self) {
Expand Down Expand Up @@ -409,11 +414,15 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
}

fn add_source_mapping(&mut self, position: u32) {
self.sourcemap_builder.add_source_mapping(&self.code, position, None);
if let Some(sourcemap_builder) = self.sourcemap_builder.as_mut() {
sourcemap_builder.add_source_mapping(&self.code, position, None);
}
}

fn add_source_mapping_for_name(&mut self, span: Span, name: &str) {
self.sourcemap_builder.add_source_mapping_for_name(&self.code, span, name);
if let Some(sourcemap_builder) = self.sourcemap_builder.as_mut() {
sourcemap_builder.add_source_mapping_for_name(&self.code, span, name);
}
}
}

Expand Down
Loading

0 comments on commit ab77d00

Please sign in to comment.