Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bacon.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[jobs.example]
command = ["just", "run-example"]
command = ["just", "example"]
allow_warnings = true
need_stdout = true

Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,10 @@ impl<'a> GenExpr for NumericLiteral<'a> {

impl<'a> Gen for BigIntLiteral<'a> {
fn gen(&self, p: &mut Codegen, _ctx: Context) {
if self.raw.starts_with('-') {
p.print_space_before_operator(Operator::Unary(UnaryOperator::UnaryNegation));
}
p.print_space_before_identifier();
p.add_source_mapping(self.span.start);
p.print_str(self.raw.as_str());
}
Expand Down
10 changes: 10 additions & 0 deletions crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ mod test {
tester::test(&allocator, source_text, expected, &mut pass);
}

fn test_nospace(source_text: &str, expected: &str) {
let allocator = Allocator::default();
let mut pass = super::PeepholeFoldConstants::new();
tester::test_impl(&allocator, source_text, expected, &mut pass, true);
}

fn test_same(source_text: &str) {
test(source_text, source_text);
}
Expand Down Expand Up @@ -1312,6 +1318,10 @@ mod test {
test("x = 0 / 0", "x = NaN");
test("x = 0 % 0", "x = NaN");
test("x = (-1) ** 0.5", "x = NaN");

test_nospace("1n+ +1n", "1n + +1n");
test_nospace("1n- -1n", "1n - -1n");
test_nospace("a- -b", "a - -b");
}

#[test]
Expand Down
21 changes: 18 additions & 3 deletions crates/oxc_minifier/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,26 @@ pub fn test<'a, P: CompressorPass<'a>>(
expected: &'a str,
pass: &mut P,
) {
let result = run(allocator, source_text, Some(pass));
let expected = run::<P>(allocator, expected, None);
test_impl(allocator, source_text, expected, pass, false);
}

pub fn test_impl<'a, P: CompressorPass<'a>>(
allocator: &'a Allocator,
source_text: &'a str,
expected: &'a str,
pass: &mut P,
remove_whitespace: bool,
) {
let result = run(allocator, source_text, Some(pass), remove_whitespace);
let expected = run::<P>(allocator, expected, None, remove_whitespace);
assert_eq!(result, expected, "\nfor source\n{source_text}\nexpect\n{expected}\ngot\n{result}");
}

fn run<'a, P: CompressorPass<'a>>(
allocator: &'a Allocator,
source_text: &'a str,
pass: Option<&mut P>,
remove_whitespace: bool,
) -> String {
let source_type = SourceType::mjs();
let mut program = Parser::new(allocator, source_text, source_type).parse().program;
Expand All @@ -35,7 +46,11 @@ fn run<'a, P: CompressorPass<'a>>(
}

CodeGenerator::new()
.with_options(CodegenOptions { single_quote: true, ..CodegenOptions::default() })
.with_options(CodegenOptions {
single_quote: true,
minify: remove_whitespace,
..CodegenOptions::default()
})
.build(&program)
.code
}
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ watch:
example tool *args='':
cargo --color always run -p oxc_{{tool}} --example {{tool}} -- {{args}}

watch-example args='':
watch-example *args='':
bacon example -- {{args}}

# Generate AST related boilerplate code.
Expand Down
5 changes: 1 addition & 4 deletions tasks/coverage/snapshots/runtime.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 06454619

runtime Summary:
AST Parsed : 18446/18446 (100.00%)
Positive Passed: 17182/18446 (93.15%)
Positive Passed: 17183/18446 (93.15%)
tasks/coverage/test262/test/annexB/language/function-code/block-decl-func-block-scoping.js
minify error: ReferenceError: f is not defined

Expand Down Expand Up @@ -2088,9 +2088,6 @@ minify error: Test262Error: Expected SameValue(«"a"», «"m"») to be true
tasks/coverage/test262/test/language/expressions/subtraction/S11.6.2_A4_T5.js
minify error: Test262Error: #3.2: -0 - 0 === - 0. Actual: +0

tasks/coverage/test262/test/language/expressions/subtraction/bigint-arithmetic.js
minify error: SyntaxError: Invalid left-hand side expression in postfix operation

tasks/coverage/test262/test/language/expressions/super/call-spread-err-mult-err-obj-unresolvable.js
transform error: ReferenceError: require is not defined

Expand Down