Skip to content

Commit

Permalink
Merge branch 'main' into 10-18-refactor_transformer_typescript_insert…
Browse files Browse the repository at this point in the history
…_assignments_after_super_by_statementinjector
  • Loading branch information
Dunqing authored Oct 22, 2024
2 parents e51e2fe + eac34b6 commit 38df391
Show file tree
Hide file tree
Showing 103 changed files with 3,446 additions and 2,263 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ num-traits = "0.2.19"
once_cell = "1.20.2"
owo-colors = "4.1.0"
oxc-browserslist = "1.0.3"
oxc_resolver = "1.12.0"
oxc_resolver = "2.0.0"
petgraph = "0.6.5"
phf = "0.11.2"
pico-args = "0.5.0"
Expand Down
10 changes: 10 additions & 0 deletions apps/oxlint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this package 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.10.2] - 2024-10-22

### Refactor

- 6ffdcc0 oxlint: Lint/mod.rs -> lint.rs (#6746) (Boshen)

### Testing

- b03cec6 oxlint: Add `--fix` test case (#6747) (Boshen)

## [0.10.1] - 2024-10-21

### Refactor
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxlint"
version = "0.10.1"
version = "0.10.2"
authors.workspace = true
categories.workspace = true
edition.workspace = true
Expand Down
1 change: 1 addition & 0 deletions apps/oxlint/fixtures/linter/fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugger
26 changes: 24 additions & 2 deletions apps/oxlint/src/lint/mod.rs → apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ mod test {
let args = &["fixtures/linter"];
let result = test(args);
assert!(result.number_of_rules > 0);
assert_eq!(result.number_of_files, 2);
assert_eq!(result.number_of_warnings, 2);
assert_eq!(result.number_of_files, 3);
assert_eq!(result.number_of_warnings, 3);
assert_eq!(result.number_of_errors, 0);
}

Expand Down Expand Up @@ -564,4 +564,26 @@ mod test {
assert_eq!(result.number_of_warnings, 0);
assert_eq!(result.number_of_errors, 1);
}

#[test]
fn test_fix() {
use std::fs;
let file = "fixtures/linter/fix.js";
let args = &["--fix", file];
let content = fs::read_to_string(file).unwrap();
assert_eq!(&content, "debugger\n");

// Apply fix to the file.
let _ = test(args);
assert_eq!(fs::read_to_string(file).unwrap(), "\n");

// File should not be modified if no fix is applied.
let modified_before = fs::metadata(file).unwrap().modified().unwrap();
let _ = test(args);
let modified_after = fs::metadata(file).unwrap().modified().unwrap();
assert_eq!(modified_before, modified_after);

// Write the file back.
fs::write(file, content).unwrap();
}
}
25 changes: 25 additions & 0 deletions crates/oxc_allocator/src/address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::ptr;

use crate::Box;

/// Memory address of an AST node in arena.
///
/// `Address` is generated from a `Box<T>`.
/// AST nodes in a `Box` in an arena are guaranteed to never move in memory,
/// so this address acts as a unique identifier for the duration of the arena's existence.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Address(usize);

/// Trait for getting the memory address of an AST node.
pub trait GetAddress {
/// Get the memory address of a value allocated in the arena.
fn address(&self) -> Address;
}

impl<'a, T> GetAddress for Box<'a, T> {
/// Get the memory address of a value allocated in the arena.
#[inline]
fn address(&self) -> Address {
Address(ptr::addr_of!(**self) as usize)
}
}
16 changes: 0 additions & 16 deletions crates/oxc_allocator/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,6 @@ impl<'alloc, T: Hash> Hash for Box<'alloc, T> {
}
}

/// Memory address of an AST node in arena.
///
/// `Address` is generated from a `Box<T>`.
/// AST nodes in a `Box` in an arena are guaranteed to never move in memory,
/// so this address acts as a unique identifier for the duration of the arena's existence.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Address(usize);

impl<'a, T> Box<'a, T> {
/// Get the memory address of a value allocated in the arena.
#[inline]
pub fn address(&self) -> Address {
Address(ptr::addr_of!(**self) as usize)
}
}

#[cfg(test)]
mod test {
use std::hash::{DefaultHasher, Hash, Hasher};
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ use std::{
pub use bumpalo::collections::String;
use bumpalo::Bump;

mod address;
mod boxed;
mod clone_in;
mod convert;
mod vec;

pub use boxed::{Address, Box};
pub use address::{Address, GetAddress};
pub use boxed::Box;
pub use clone_in::CloneIn;
pub use convert::{FromIn, IntoIn};
pub use vec::Vec;
Expand Down
49 changes: 0 additions & 49 deletions crates/oxc_ast/src/address.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,6 @@ pub struct TryStatement<'a> {
/// The `catch` clause, including the parameter and the block statement
pub handler: Option<Box<'a, CatchClause<'a>>>,
/// The `finally` clause
#[visit(as(FinallyClause))]
pub finalizer: Option<Box<'a, BlockStatement<'a>>>,
}

Expand Down Expand Up @@ -1839,7 +1838,6 @@ pub struct Class<'a> {
/// class Foo extends Bar {}
/// // ^^^
/// ```
#[visit(as(ClassHeritage))]
pub super_class: Option<Expression<'a>>,
/// Type parameters passed to super class.
///
Expand Down
43 changes: 42 additions & 1 deletion crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![warn(missing_docs)]
use std::{borrow::Cow, cell::Cell, fmt};

use oxc_allocator::{Box, FromIn, Vec};
use oxc_allocator::{Address, Box, FromIn, GetAddress, Vec};
use oxc_span::{Atom, GetSpan, Span};
use oxc_syntax::{
operator::UnaryOperator,
Expand Down Expand Up @@ -768,6 +768,47 @@ impl<'a> FromIn<'a, Expression<'a>> for Statement<'a> {
}
}

impl<'a> GetAddress for Statement<'a> {
// `#[inline]` because compiler should boil this down to a single assembly instruction
#[inline]
fn address(&self) -> Address {
match self {
Statement::BlockStatement(s) => s.address(),
Statement::BreakStatement(s) => s.address(),
Statement::ContinueStatement(s) => s.address(),
Statement::DebuggerStatement(s) => s.address(),
Statement::DoWhileStatement(s) => s.address(),
Statement::EmptyStatement(s) => s.address(),
Statement::ExpressionStatement(s) => s.address(),
Statement::ForInStatement(s) => s.address(),
Statement::ForOfStatement(s) => s.address(),
Statement::ForStatement(s) => s.address(),
Statement::IfStatement(s) => s.address(),
Statement::LabeledStatement(s) => s.address(),
Statement::ReturnStatement(s) => s.address(),
Statement::SwitchStatement(s) => s.address(),
Statement::ThrowStatement(s) => s.address(),
Statement::TryStatement(s) => s.address(),
Statement::WhileStatement(s) => s.address(),
Statement::WithStatement(s) => s.address(),
Statement::VariableDeclaration(s) => s.address(),
Statement::FunctionDeclaration(s) => s.address(),
Statement::ClassDeclaration(s) => s.address(),
Statement::TSTypeAliasDeclaration(s) => s.address(),
Statement::TSInterfaceDeclaration(s) => s.address(),
Statement::TSEnumDeclaration(s) => s.address(),
Statement::TSModuleDeclaration(s) => s.address(),
Statement::TSImportEqualsDeclaration(s) => s.address(),
Statement::ImportDeclaration(s) => s.address(),
Statement::ExportAllDeclaration(s) => s.address(),
Statement::ExportDefaultDeclaration(s) => s.address(),
Statement::ExportNamedDeclaration(s) => s.address(),
Statement::TSExportAssignment(s) => s.address(),
Statement::TSNamespaceExportDeclaration(s) => s.address(),
}
}
}

impl<'a> Directive<'a> {
/// A Use Strict Directive is an ExpressionStatement in a Directive Prologue whose StringLiteral is either of the exact code point sequences "use strict" or 'use strict'.
/// A Use Strict Directive may not contain an EscapeSequence or LineContinuation.
Expand Down
3 changes: 0 additions & 3 deletions crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ impl<'a> AstKind<'a> {

Self::SwitchCase(_) => "SwitchCase".into(),
Self::CatchClause(_) => "CatchClause".into(),
Self::FinallyClause(_) => "FinallyClause".into(),

Self::VariableDeclaration(_) => "VariableDeclaration".into(),
Self::VariableDeclarator(v) => format!(
Expand Down Expand Up @@ -298,7 +297,6 @@ impl<'a> AstKind<'a> {
Self::AssignmentTargetWithDefault(_) => "AssignmentTargetWithDefault".into(),
Self::SpreadElement(_) => "SpreadElement".into(),
Self::Elision(_) => "Elision".into(),
Self::ExpressionArrayElement(_) => "ExpressionArrayElement".into(),
Self::BindingRestElement(_) => "BindingRestElement".into(),

Self::Function(x) => format!("Function({})", or_anonymous(x.id.as_ref())).into(),
Expand All @@ -314,7 +312,6 @@ impl<'a> AstKind<'a> {
Self::Class(c) => format!("Class({})", or_anonymous(c.id.as_ref())).into(),
Self::TSClassImplements(_) => "TSClassImplements".into(),
Self::ClassBody(_) => "ClassBody".into(),
Self::ClassHeritage(_) => "ClassHeritage".into(),
Self::StaticBlock(_) => "StaticBlock".into(),
Self::PropertyDefinition(_) => "PropertyDefinition".into(),
Self::MethodDefinition(_) => "MethodDefinition".into(),
Expand Down
Loading

0 comments on commit 38df391

Please sign in to comment.