Skip to content

Commit

Permalink
Merge branch 'oxc-project:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
leaysgur authored Jan 10, 2024
2 parents dc9302f + fc7dbd9 commit 5c23970
Show file tree
Hide file tree
Showing 44 changed files with 3,981 additions and 2,532 deletions.
1 change: 0 additions & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ ignore:
- "crates/oxc_type_synthesis"
- "crates/oxc_query" # Not aiming for test coverage right now with @u9g
- "crates/oxc_linter_plugin"
- "crates/oxc_formatter" # The formatter is not being actively worked on
- "crates/oxc_transformer" # not ready
- "crates/oxc_js_regex" # not ready
8 changes: 6 additions & 2 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ on:
- 'website/**'
- 'crates/oxc/**'
- 'crates/oxc_cli/**'
- 'crates/oxc_formatter/**'
- 'crates/oxc_linter/**'
- 'crates/oxc_query/**'
- 'crates/oxc_type_synthesis/**'
Expand All @@ -30,7 +29,6 @@ on:
- 'website/**'
- 'crates/oxc/**'
- 'crates/oxc_cli/**'
- 'crates/oxc_formatter/**'
- 'crates/oxc_linter/**'
- 'crates/oxc_query/**'
- 'crates/oxc_type_synthesis/**'
Expand All @@ -55,6 +53,12 @@ jobs:
- name: Set up Bun
uses: oven-sh/setup-bun@v1

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'

- run: cargo coverage
- run: cargo run --release -p oxc_transform_conformance -- --exec
- run: cargo run --release -p oxc_prettier_conformance
Expand Down
18 changes: 4 additions & 14 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ oxc_allocator = { version = "0.4.0", path = "crates/oxc_allocator" }
oxc_ast = { version = "0.4.0", path = "crates/oxc_ast" }
oxc_codegen = { version = "0.4.0", path = "crates/oxc_codegen" }
oxc_diagnostics = { version = "0.4.0", path = "crates/oxc_diagnostics" }
oxc_formatter = { version = "0.4.0", path = "crates/oxc_formatter" }
oxc_index = { version = "0.4.0", path = "crates/oxc_index" }
oxc_minifier = { version = "0.4.0", path = "crates/oxc_minifier" }
oxc_parser = { version = "0.4.0", path = "crates/oxc_parser" }
Expand Down Expand Up @@ -122,7 +121,7 @@ thiserror = { version = "1.0.56" }
tokio = { version = "1" }
tower-lsp = { version = "0.20.0", features = ["proposed"] }
unicode-id-start = { version = "1.1.2" }
ureq = { version = "2.9.1", default-features = false, features = ["tls"] }
ureq = { version = "2.9.1", default-features = false, features = ["tls", "json"] }
url = { version = "2.5.0" }
walkdir = { version = "2.4.0" }
indexmap = { version = "2.1.0" }
Expand Down
2 changes: 0 additions & 2 deletions MAINTENANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ sed -i '' 's/0.3.0/0.4.0/' crates/oxc_allocator/Cargo.toml
sed -i '' 's/0.3.0/0.4.0/' crates/oxc_ast/Cargo.toml
sed -i '' 's/0.3.0/0.4.0/' crates/oxc_codegen/Cargo.toml
sed -i '' 's/0.3.0/0.4.0/' crates/oxc_diagnostics/Cargo.toml
sed -i '' 's/0.3.0/0.4.0/' crates/oxc_formatter/Cargo.toml
sed -i '' 's/0.3.0/0.4.0/' crates/oxc_index/Cargo.toml
sed -i '' 's/0.3.0/0.4.0/' crates/oxc_minifier/Cargo.toml
sed -i '' 's/0.3.0/0.4.0/' crates/oxc_parser/Cargo.toml
Expand All @@ -60,7 +59,6 @@ cargo publish -p oxc_ast
cargo publish -p oxc_diagnostics
cargo publish -p oxc_parser
cargo publish -p oxc_semantic
cargo publish -p oxc_formatter
cargo publish -p oxc_transformer
cargo publish -p oxc_codegen
cargo publish -p oxc_minifier
Expand Down
2 changes: 0 additions & 2 deletions crates/oxc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ oxc_parser = { workspace = true }
oxc_span = { workspace = true }
oxc_syntax = { workspace = true }
oxc_semantic = { workspace = true, optional = true }
oxc_formatter = { workspace = true, optional = true }
oxc_transformer = { workspace = true, optional = true }
oxc_minifier = { workspace = true, optional = true }
oxc_codegen = { workspace = true, optional = true }

[features]
serde = ["oxc_ast/serde", "oxc_semantic/serde"]
semantic = ["oxc_semantic"]
formatter = ["oxc_formatter"]
transformer = ["oxc_transformer"]
minifier = ["oxc_minifier"]
codegen = ["oxc_codegen"]
6 changes: 0 additions & 6 deletions crates/oxc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ pub mod semantic {
pub use oxc_semantic::*;
}

#[cfg(feature = "formatter")]
pub mod formatter {
#[doc(inline)]
pub use oxc_formatter::*;
}

#[cfg(feature = "transformer")]
pub mod transformer {
#[doc(inline)]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_cli/src/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod test {
let args = &["-c", "fixtures/eslintrc_off/eslintrc.json", "fixtures/eslintrc_off/test.js"];
let result = test(args);
assert_eq!(result.number_of_files, 1);
assert_eq!(result.number_of_warnings, 0);
assert_eq!(result.number_of_warnings, 1); // triggered by no_empty_file
assert_eq!(result.number_of_errors, 0);
}

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl Context {
}

#[inline]
#[must_use]
pub fn and_in(self, include: bool) -> Self {
self.and(Self::In, include)
}
Expand Down
36 changes: 17 additions & 19 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ExpressionStatement<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, _ctx: Context) {
p.print_indent();
p.start_of_stmt = p.code_len();
self.expression.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.expression);
if self.expression.is_specific_id("let") {
p.print_semicolon();
} else {
Expand All @@ -153,7 +153,7 @@ fn print_if<const MINIFY: bool>(
p.print_str(b"if");
p.print_soft_space();
p.print(b'(');
if_stmt.test.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&if_stmt.test);
p.print(b')');
p.print_soft_space();

Expand Down Expand Up @@ -251,14 +251,14 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ForStatement<'a> {
p.print_soft_space();

if let Some(test) = self.test.as_ref() {
test.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(test);
}

p.print_semicolon();
p.print_soft_space();

if let Some(update) = self.update.as_ref() {
update.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(update);
}

p.print(b')');
Expand All @@ -277,7 +277,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ForInStatement<'a> {
p.print_space_before_identifier();
p.print_str(b"in");
p.print_hard_space();
self.right.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.right);
p.print(b')');
p.print_soft_space();
self.body.gen(p, ctx);
Expand Down Expand Up @@ -320,7 +320,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for WhileStatement<'a> {
p.print_indent();
p.print_str(b"while");
p.print(b'(');
self.test.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.test);
p.print(b')');
self.body.gen(p, ctx);
}
Expand All @@ -342,7 +342,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for DoWhileStatement<'a> {
}
p.print_str(b"while");
p.print(b'(');
self.test.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.test);
p.print(b')');
p.print_semicolon_after_statement();
}
Expand Down Expand Up @@ -384,7 +384,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for SwitchStatement<'a> {
p.print_indent();
p.print_str(b"switch");
p.print(b'(');
self.discriminant.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.discriminant);
p.print(b')');
p.print_block_start();
for case in &self.cases {
Expand All @@ -404,7 +404,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for SwitchCase<'a> {
Some(test) => {
p.print_str(b"case");
p.print_hard_space();
test.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(test);
}
None => p.print_str(b"default"),
}
Expand All @@ -425,7 +425,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ReturnStatement<'a> {
p.print_str(b"return");
if let Some(arg) = &self.argument {
p.print_hard_space();
arg.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(arg);
}
p.print_semicolon_after_statement();
}
Expand Down Expand Up @@ -465,7 +465,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ThrowStatement<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, _ctx: Context) {
p.print_indent();
p.print_str(b"throw ");
self.argument.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.argument);
p.print_semicolon_after_statement();
}
}
Expand All @@ -475,7 +475,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for WithStatement<'a> {
p.print_indent();
p.print_str(b"with");
p.print(b'(');
self.object.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.object);
p.print(b')');
self.body.gen(p, ctx);
}
Expand Down Expand Up @@ -1645,7 +1645,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TemplateLiteral<'a> {

if let Some(expr) = expressions.next() {
p.print_str(b"${");
expr.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(expr);
p.print(b'}');
}
}
Expand Down Expand Up @@ -1825,7 +1825,7 @@ impl<const MINIFY: bool> Gen<MINIFY> for JSXEmptyExpression {
impl<'a, const MINIFY: bool> Gen<MINIFY> for JSXExpression<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
match self {
Self::Expression(expr) => expr.gen_expr(p, Precedence::lowest(), Context::default()),
Self::Expression(expr) => p.print_expression(expr),
Self::EmptyExpression(expr) => expr.gen(p, ctx),
}
}
Expand Down Expand Up @@ -1853,7 +1853,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for JSXAttributeValue<'a> {
impl<'a, const MINIFY: bool> Gen<MINIFY> for JSXSpreadAttribute<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, _ctx: Context) {
p.print_str(b"{...");
self.argument.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.argument);
p.print(b'}');
}
}
Expand Down Expand Up @@ -1924,7 +1924,7 @@ impl<const MINIFY: bool> Gen<MINIFY> for JSXText {
impl<'a, const MINIFY: bool> Gen<MINIFY> for JSXSpreadChild<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, _ctx: Context) {
p.print_str(b"...");
self.expression.gen_expr(p, Precedence::lowest(), Context::default());
p.print_expression(&self.expression);
}
}

Expand All @@ -1933,9 +1933,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for JSXChild<'a> {
match self {
Self::Fragment(fragment) => fragment.gen(p, ctx),
Self::Element(el) => el.gen(p, ctx),
Self::Spread(spread) => {
spread.expression.gen_expr(p, Precedence::lowest(), Context::default());
}
Self::Spread(spread) => p.print_expression(&spread.expression),
Self::ExpressionContainer(expr_container) => expr_container.gen(p, ctx),
Self::Text(text) => text.gen(p, ctx),
}
Expand Down
14 changes: 9 additions & 5 deletions crates/oxc_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use oxc_syntax::{
symbol::SymbolId,
};

use self::{
pub use crate::{
context::Context,
gen::{Gen, GenExpr},
operator::Operator,
Expand Down Expand Up @@ -111,12 +111,12 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
}

/// Push a single character into the buffer
fn print(&mut self, ch: u8) {
pub fn print(&mut self, ch: u8) {
self.code.push(ch);
}

/// Push a string into the buffer
fn print_str(&mut self, s: &[u8]) {
pub fn print_str(&mut self, s: &[u8]) {
self.code.extend_from_slice(s);
}

Expand All @@ -126,7 +126,7 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
}
}

fn print_hard_space(&mut self) {
pub fn print_hard_space(&mut self) {
self.print(b' ');
}

Expand Down Expand Up @@ -197,7 +197,7 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
self.print_str(b"...");
}

fn print_colon(&mut self) {
pub fn print_colon(&mut self) {
self.print(b':');
}

Expand Down Expand Up @@ -256,6 +256,10 @@ impl<const MINIFY: bool> Codegen<MINIFY> {
}
}

pub fn print_expression(&mut self, expr: &Expression<'_>) {
expr.gen_expr(self, Precedence::lowest(), Context::default());
}

fn print_expressions<T: GenExpr<MINIFY>>(
&mut self,
items: &[T],
Expand Down
Loading

0 comments on commit 5c23970

Please sign in to comment.