Commit graph

326 commits

Author SHA1 Message Date
Boshen
855c8395cf fix(codegen): shorthand assignment target identifier consider mangled names (#8536) 2025-01-16 07:26:07 +00:00
Boshen
6e64eef37c
refactor(codegen): remove match_expression! (#8450)
`match_expression!` + `self.to_expression()` seems like doing to the
same thing twice.

Incorrect matches should be caught unit tests.
2025-01-13 00:04:58 +08:00
Boshen
a1752a062c fix(codegen): fix incorrect minified return 1n output (#8374) 2025-01-09 05:01:41 +00:00
Boshen
5a648bc3cd fix(codegen): fix white space issue with do statements (#8348) 2025-01-08 13:28:10 +00:00
Boshen
a542013773 feat(minifier): minimize do{}while(true) -> do;while(true) (#8311) 2025-01-07 12:55:03 +00:00
camc314
b6d16f4d80 fix(codegen): print parenthesis on negative bigint lit when neccessary (#8258)
closes #8257

i couldn't really write a test for this, as it only happens when codegen + minifier are used together.

Regression should be prevented by the 262 suite in #8256 (failed CI run before i implemented this fix: https://github.com/oxc-project/oxc/actions/runs/12621310419/job/35168016825)
2025-01-06 02:21:24 +00:00
Dunqing
8ed976661a
fix(codegen): source map builder panicked because it attempted to subtract with overflow in search_original_line_and_column (#8185)
See:
https://github.com/oxc-project/monitor-oxc/actions/runs/12531534720/job/34949348092
Related: #7926 

This line causes panic.

46fc1a8b7d/crates/oxc_codegen/src/sourcemap_builder.rs (L147-L148)

After investigation, I found that the root cause was the code removed
in this PR. I don’t understand what the code was used for, but it was
obviously wrong. Because `idx` is always smaller than `cap`
2024-12-31 20:00:41 +08:00
Boshen
ad146bbb90 feat(codegen): print real newline when \n is inside template literals (#8178) 2024-12-29 12:20:47 +00:00
Boshen
ad61e70186 fix(codegen): print if else without block with proper indentation (#8135) 2024-12-27 00:39:52 +00:00
Boshen
bdc241d41d fix(codegen): disallow template literals in object property key (#8108) 2024-12-25 11:22:54 +00:00
Boshen
7110c7b94c refactor(codegen): add print_quoted_utf16 and print_unquoted_utf16 methods (#8107) 2024-12-25 09:19:55 +00:00
Boshen
47276679f5 feat(codegen): minify arrow expr (x) => y -> x => y (#8078) 2024-12-24 14:25:01 +00:00
Boshen
728ed20c1c
fix(codegen): print yield * ident correctly 2024-12-24 21:57:58 +08:00
Boshen
0562830549 feat(codegen): minify string with backtick when needed (#8095) 2024-12-24 13:39:31 +00:00
Boshen
ad2a620d61 fix(ast)!: add missing AssignmentTargetProperty::computed (#8097) 2024-12-24 13:27:00 +00:00
Boshen
6237c0527f feat(codegen): minify more whitespace (#8089) 2024-12-24 09:54:13 +00:00
Boshen
6355b7ca70 feat(codegen): minify export { 's' as 's' } -> export { 's' } (#8093) 2024-12-24 09:17:51 +00:00
Boshen
fccfda91c1 feat(codegen): minify class{static[computed]} (#8088) 2024-12-24 05:06:57 +00:00
Boshen
f873139a0f feat(codegen): minify for (_ of []) -> for(_ of[]) (#8086) 2024-12-24 04:17:50 +00:00
Boshen
8b8cbcd2db feat(codegen): minify case "foo" -> case"foo" (#8085) 2024-12-24 01:07:58 +00:00
Boshen
414c118309 feat(codegen): minify yield "s" -> yield"s" (#8084) 2024-12-24 00:41:28 +00:00
Boshen
f8f067bfc6 feat(codegen): minify class method async*fn(){} (#8083) 2024-12-24 00:35:29 +00:00
Boshen
618b6aa085 feat(codege): minify whitespace in object getter / setter (#8080) 2024-12-23 16:36:03 +00:00
Boshen
1d5ae817d7 feat(codegen): minify const [foo] = bar -> const[foo]=bar (#8079) 2024-12-23 16:20:37 +00:00
Boshen
e3f78fba0b feat(codegen): new Foo() -> new Foo when minify (#8077) 2024-12-23 15:34:31 +00:00
Boshen
d84d60a3a9 feat(codegen): minify numbers with large exponents (#8074) 2024-12-23 13:35:52 +00:00
Boshen
373279b7f4 feat(codegen): balance string quotes when minify whitespace (#8072) 2024-12-23 13:24:22 +00:00
Cameron
78d2e837f0
perf(sourcemap): improve perf of search_original_line_and_column (#7926)
this seems to show a decent speed up on perf.
the thinking behind this change is:
1. subsequent calls to `search_original_line_and_column` will **never**
look at back at lines it has already searched
2. binary search is faster in this case as typically `idx` is only
increased by a small amount

Given this, we can skip checking a bunch of lines (that will never
return true) improving performance.

This is a very hot path. 


```
$ hyperfine --warmup=3 ./target/release-with-debug/examples/sourcemap-main ./target/release-with-debug/examples/sourcemap
Benchmark 1: ./target/release-with-debug/examples/sourcemap-main
  Time (mean ± σ):      79.5 ms ±   5.5 ms    [User: 65.1 ms, System: 12.2 ms]
  Range (min … max):    76.8 ms … 111.7 ms    37 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: ./target/release-with-debug/examples/sourcemap
  Time (mean ± σ):      72.9 ms ±   0.9 ms    [User: 59.2 ms, System: 12.2 ms]
  Range (min … max):    70.6 ms …  75.0 ms    40 runs
 
Summary
  ./target/release-with-debug/examples/sourcemap ran
    1.09 ± 0.08 times faster than ./target/release-with-debug/examples/sourcemap-main
```

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-12-23 14:51:50 +08:00
Dunqing
862838fd28 perf(codegen): remove useless to_owned (#8014) 2024-12-19 12:06:55 +00:00
Dunqing
850dd43597 fix(codegen): missing , when generating type parameters with jsx (#7929)
close: #7917
2024-12-16 05:35:06 +00:00
overlookmotel
3858221f45 refactor(global): sort imports (#7883)
Pure refactor. Re-order imports for clarity:

1. `std`
2. External crates
3. `oxc_*` crates
4. Current crate `use crate::...`
5. Super `use super::...`
6. Local modules

This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where.

`cargo +nightly fmt` (#7877) did a lot of the work, but unfortunately `rustfmt` does not have an option to (a) put workspace crates in a separate block from external crates and (b) move `mod` statements to after `use` statements.
2024-12-14 15:07:21 +00:00
Boshen
7fb9d47460 style(rust): cargo +nightly fmt (#7877) 2024-12-14 06:03:31 +00:00
Boshen
4b2433539b perf(codegen): improve printing of statement comments (#7857)
closes #7814
2024-12-13 15:20:28 +00:00
Boshen
71a40a222f perf(codegen): guard comment printing comments when there are no comments (#7856) 2024-12-13 15:12:09 +00:00
overlookmotel
4448b63692 perf(codegen): faster writing indentation (#7820)
Write indentation faster. Previously was writing indentation to buffer with a call to `memset`, which is relatively expensive. Where indentation `<= 16` (common case), write 16 tabs with a single 16-byte XMM write, which is faster.
2024-12-13 05:17:32 +00:00
Boshen
afaaffa262 perf(codegen): fast path for options.print_comments() (#7806) 2024-12-11 15:13:30 +00:00
Boshen
a222f2b055 fix(codegen): print delete 2e308 as delete (0, Infinity) (#7761)
closes #7736
2024-12-10 08:37:50 +00:00
Boshen
b701232098 fix(codegen): print quote correctly for directive (#7735)
closes #7734
2024-12-09 07:17:02 +00:00
Boshen
72eab6cd96 feat(parser)!: stage 3 import source and import defer (#7706)
* https://github.com/tc39/proposal-defer-import-eval
* https://github.com/tc39/proposal-source-phase-imports
* https://tc39.es/proposal-source-phase-imports/#sec-ecmascript-language-expressions
* https://tc39.es/proposal-defer-import-eval/#prod-NameSpaceImport
2024-12-06 16:15:52 +00:00
Dunqing
8c3a954336 fix(codegen): missing parens for in in for in loop init (#7705)
Well, this looks like an accidental change before, `Context::empty().and_forbid_in(false)` does nothing at all.
2024-12-06 15:52:05 +00:00
Dunqing
4afbe5599e fix(codegen): missing parens for in in for loop init when it includes two binary expression (#7703)
close: #7690

I don't know the logic much, it works without `left_ctx` and no tests failed
2024-12-06 15:52:04 +00:00
Boshen
d0b78f7361 feat(codegen): minify whitespace for some expressions (#7671)
part of #7638
2024-12-05 06:59:17 +00:00
Song Gao
ebc80f6749
refactor(ast)!: change 'raw' from &str to Option<Atom> (#7547)
Fix #7254 

Changed all "raw" properties of literal types (if they have this property) to `Option<Atom>`.

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-12-05 00:34:45 +00:00
Boshen
c523ccb7ef feat(codegen): better whitespace minification for import / export statements (#7650)
part of #7638
2024-12-04 19:24:03 +00:00
Boshen
e787e9d41a fix(codegen): print parentheses correctly for ClassHeritage (#7637)
closes #7631
2024-12-04 06:43:32 +00:00
Boshen
d942a8d41a
chore: Rust v1.83.0 changes (#7535)
This PR does not upgrade rustc. Only changes are applied.

We cannot upgrade to the lastet Rust version yet due to wasm-bindgen
breaking some generated types.

THere's also some elided lifetimes in `**/generated/**`, which requires
modification to ast tools.
2024-11-29 11:59:45 +08:00
Hiroshi Ogawa
d5df615264
fix(oxc_codegen): don't emit empty span mapping (#7448) 2024-11-24 17:04:52 +08:00
Boshen
f059b0e655 fix(ast)!: add missing ChainExpression from TSNonNullExpression (#7377)
closes #7375

* `foo?.bar!`
* `foo?.[bar]!`

`TSNonNullExpression` was not wrapped inside `ChainExpression`.
2024-11-20 15:54:28 +00:00
Boshen
82773cb455 feat(codegen): remove underscore from bigint (#7367)
closes #7285
closes #7286
2024-11-20 09:08:51 +00:00
Dunqing
c587dd3cd6 fix(codegen): do not print parenthesis for in expression in ArrowFunctionExpression (#7360)
Please check out [esbuild](https://esbuild.github.io/try/#dAAwLjI0LjAAACgpID0+ICIiIGluIHt9)
2024-11-19 14:29:18 +00:00