diff --git a/bacon.toml b/bacon.toml index 4dab8c6db..b93078c38 100644 --- a/bacon.toml +++ b/bacon.toml @@ -1,5 +1,5 @@ [jobs.example] -command = ["just", "run-example"] +command = ["just", "example"] allow_warnings = true need_stdout = true diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index c9758d2bd..8c308e2d9 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -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()); } diff --git a/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs index c392410a5..fa8d40122 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs @@ -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); } @@ -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] diff --git a/crates/oxc_minifier/src/tester.rs b/crates/oxc_minifier/src/tester.rs index 6daeec536..393f199fa 100644 --- a/crates/oxc_minifier/src/tester.rs +++ b/crates/oxc_minifier/src/tester.rs @@ -13,8 +13,18 @@ pub fn test<'a, P: CompressorPass<'a>>( expected: &'a str, pass: &mut P, ) { - let result = run(allocator, source_text, Some(pass)); - let expected = run::

(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::

(allocator, expected, None, remove_whitespace); assert_eq!(result, expected, "\nfor source\n{source_text}\nexpect\n{expected}\ngot\n{result}"); } @@ -22,6 +32,7 @@ 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; @@ -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 } diff --git a/justfile b/justfile index 3b4702988..bb2e67c3d 100755 --- a/justfile +++ b/justfile @@ -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. diff --git a/tasks/coverage/snapshots/runtime.snap b/tasks/coverage/snapshots/runtime.snap index 48abc94d3..03193de5f 100644 --- a/tasks/coverage/snapshots/runtime.snap +++ b/tasks/coverage/snapshots/runtime.snap @@ -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 @@ -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