Commit graph

286 commits

Author SHA1 Message Date
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
Dunqing
58db9ef322 refactor(codegen): do not print unnecessary parentheses if both sides use the same logical operator (#7325)
As shown by the changing tests, we don't need to print parentheses for them.

### Comparison
In [esbuild](https://esbuild.github.io/try/#dAAwLjI0LjAAAGEgPz8gKGIgPz8gKGMgPz8gZCkpOwooYSA/PyAoYiA/PyAoYyA/PyBkKSkpOwooYSB8fCAoYiB8fCBjKSkgfHwgZDsKYSB8fCAoYiB8fCAoYyB8fCBkKSk7CmEgJiYgKChiICYmIGMpICYmIGQp), it will print parentheses as-is, in [SWC](https://play.swc.rs/?version=1.9.2&code=H4sIAAAAAAAAA0tUsLdX0EgCk8kgMkVT05pLIxGLMES8pgYkDiSTNTVBVIo1F5IgUDFIDKQ2UUFNTUEDKAykkjVBZIomAGEbiHtuAAAA&config=H4sIAAAAAAAAA1VQzW7DIAy%2B9ykin6tlyrHXTb3ttCdA1GmpACPbSIuqvPuAJml6w9%2Bv8ePQdXAXC6fuUZ5lSIYFeZsLIlNU81cQ0CmhWHZJ4biyKpVSztiQ%2BUmAGr6iVhPK8DkMsOJsoozEYd%2BQBb9xdBHPxF%2FeiJwd%2BossuVsVo7G68xXIhUSsv5TZYi27qSY59T1K%2BJBbn56W48vAOaoLTWuyUjDqLCz0%2FPYDTyRVNxovyw4QXHTjtF%2FdUiglIu%2FCKjXx6jf%2FYc1v6RDokhu5HL0etq5U0gLFu8BLuTZu6eDkZ7W3s8%2F%2FYy0r4MUBAAA%3D), we have the same output now
2024-11-19 10:31:53 +00:00
Song Gao
cf3415b0e4
chore(doc): replace main/master to tag/commit to make the url always accessible (#7298) 2024-11-16 21:00:30 +08:00
overlookmotel
a0766e6a7f fix(codegen): fix arithmetic overflow printing unspanned nodes (#7292)
Similar to #7289. Check if `span.end` is 0 before doing `span.end - 1`, to prevent arithmetic overflow.

Also changed all checks to `span.end > 0`, just for consistency.
2024-11-15 16:04:02 +00:00
overlookmotel
33ec4e6182 fix(codegen): fix arithmetic overflow printing unspanned NewExpression (#7289)
`self.span.end - 1` overflows if the `NewExpression` is generated in transformer and has no span, so `self.span.end == 0`.
2024-11-15 02:56:49 +00:00
overlookmotel
44375a5662 refactor(ast)!: rename TSEnumMemberName enum variants (#7250)
Variants of `TSEnumMemberName` were previously only prefixed with `Static` to avoid naming conflicts with the variants inherited from `Expression` for non-static member names. #7219 removed the variants inherited from `Expression`, so all variants are now static. So we can shorten the names again (back to what they were before `inherit_variants!` was introduced).
2024-11-12 12:22:21 +00:00
Boshen
1282221e36 fix(codegen): print comments when block is empty (#7236)
part of #7190
2024-11-11 11:20:25 +00:00
Boshen
0e4adc15dd feat(ast)!: remove invalid expressions from TSEnumMemberName (#7219) 2024-11-09 08:48:14 +00:00
Boshen
d1d187417b feat(ast)!: change comment.span to real position that contain // and /* (#7154)
closes #7150
2024-11-06 05:10:33 +00:00
Boshen
40d8acfbd1 feat(codegen): improvement printing of legal comments (#7111) 2024-11-04 08:56:00 +00:00
Boshen
caa4b1fd2a feat(codegen): improve printing of comments (#7108) 2024-11-04 05:12:59 +00:00
Boshen
001058a8e4
feat(codegen): always print legal comments on its own line (#7089) 2024-11-02 15:55:23 +08:00
Boshen
dd79c1bfb3
refactor(codegen): replace daachorse with string match for annotation comment (#7064) 2024-11-02 14:16:10 +08:00
Boshen
413973df66 feat(codegen): print linked and external legal comment (#7059)
part of #7050
2024-11-02 04:08:14 +00:00
Boshen
ee27b92465 feat(codegen): print eof legal comments (#7058)
part of https://github.com/oxc-project/oxc/issues/7050
2024-11-01 16:56:57 +00:00
Boshen
6516f9eabc feat(codegen): print inline legal comments (#7054)
part of https://github.com/oxc-project/oxc/issues/7050
2024-11-01 16:56:56 +00:00
Boshen
0bb1aa4c64 refactor(codegen): move options to its own file (#7053) 2024-11-01 09:28:59 +00:00
Boshen
423d54cb74 refactor(rust): remove the annoying clippy::wildcard_imports (#6860) 2024-10-24 13:57:19 +00:00
Boshen
05ef03dbab fix(codegen): correct print __proto__ shorthand (#6802) 2024-10-23 07:16:00 +00:00
Boshen
1b7897cf01 fix(codegen): print #field in {} << 0; correctly (#6799) 2024-10-23 05:34:22 +00:00
Boshen
2f6ad42348 fix(codegen): print negative bigint 1n- -1n correctly after constant folding (#6798)
closes #6767
2024-10-23 04:56:50 +00:00
DonIsaac
374b972143 docs(codegen): add #![warn(missing_docs)] to oxc_codegen (#6711)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-21 00:13:57 +00:00
Boshen
1a90ec4b85 refactor(rust): backport v1.82.0 changes to main branch first (#6690) 2024-10-19 14:30:55 +00:00
Boshen
f4cdc56577 refactor(minifier): use constant folding unary expression from oxc_ecmascript (#6647) 2024-10-17 15:30:38 +00:00
Boshen
e5ed6a56a8 feat(codegen): print negative numbers (#6624) 2024-10-16 22:38:54 +00:00
Dunqing
ba385fc9c1 fix(codegen): panic occurred when printing the comment of the right parenthesis (#6593)
fix: https://github.com/oxc-project/monitor-oxc/actions/runs/11349185798/job/31564783192

It's hard to add a test for this because I haven't figured out caused by which plugin
2024-10-15 16:23:43 +00:00
overlookmotel
c0e9d7eb77 refactor(codegen)!: Codegen::into_source_text consume Codegen (#6539)
Breaking change. `Codegen::into_source_text` consume `Codegen`, instead of taking the `CodeBuffer` and substituting an empty one.

Keeping the `Codegen` alive seems unintuitive, as its state is then out of sync. Consuming the `CodeBuffer` is also marginally cheaper.
2024-10-14 01:09:03 +00:00
overlookmotel
7e909a7e6c docs(codegen): fix example for CodeBuffer::print_ascii_bytes (#6535)
Fix example and add a test.
2024-10-14 01:09:02 +00:00
overlookmotel
77f3a1a9dd perf(codegen): check last char with byte methods (#6509)
When checking what last char in buffer is, avoid calculating a `char` when only comparing to an ASCII char (byte) anyway.
2024-10-14 01:09:02 +00:00
overlookmotel
18b68ff90e perf(codegen): optimize CodeBuffer::print_ascii_byte (#6516)
Optimize `CodeBuffer`'s `print_byte_unchecked` and `print_ascii_byte` methods by making a fast path for when the buffer has sufficient capacity to be pushed to without growing.

As discussed in https://github.com/oxc-project/oxc/pull/6148#issuecomment-2381635390
2024-10-14 01:09:01 +00:00
overlookmotel
51fc63da45 refactor(codegen): rename CodeBuffer::print_bytes_unchecked method (#6517) 2024-10-13 13:14:49 +00:00
overlookmotel
782f0a7a69 refactor(codegen)!: rename print_char method to print_ascii_byte (#6512)
`print_ascii_byte` is more descriptive of what this method does, and makes clear the invariant that `byte` must be ASCII.
2024-10-13 12:51:37 +00:00
overlookmotel
235d357600 docs(codegen): improve doc comments for CodeBuffer (#6511) 2024-10-13 12:21:39 +00:00
overlookmotel
e7f3e28076 refactor(codegen): rename var in CodeBuffer (#6510) 2024-10-13 11:58:39 +00:00
overlookmotel
1bbd383d0f refactor(codegen): rename CodeBuffer::print_ascii_bytes method (#6507)
Pure refactor.
2024-10-13 11:19:09 +00:00
overlookmotel
cd9fe9ec03 refactor(codegen): rename vars in CodeBuffer methods (#6506)
Pure refactor. Consistently use `byte` for bytes, and `ch` for `char`s.
2024-10-13 11:10:10 +00:00
overlookmotel
c8fa2eb17a docs(codegen): correct and reformat doc comments for CodeBuffer (#6504)
Comment about `take_source_text` was erroneous. Clean up and reformat other doc comments.
2024-10-13 11:10:09 +00:00
overlookmotel
fc536a5648 refactor(codegen): inline CodeBuffer methods (#6501)
These methods are all either trivial, or delegate to another method.
2024-10-13 10:55:07 +00:00
overlookmotel
40d1ee4588 docs(codegen): fix and reformat CodeBuffer examples (#6499)
Fix examples which would not compile.
2024-10-13 10:49:37 +00:00
overlookmotel
74206204dd refactor(codegen): add CodeBuffer::as_bytes method (#6498)
`as_bytes` is clearer than `as_ref` (what kind of ref?)
2024-10-13 10:05:10 +00:00
overlookmotel
d816b0bd0e test(codegen): add test for CodeBuffer::print_byte_unchecked (#6497)
Add test, and rename the rest of the test functions for `CodeBuffer`.
2024-10-13 09:51:50 +00:00