Commit graph

252 commits

Author SHA1 Message Date
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
overlookmotel
8ae174bd36 refactor(codegen): rename CodeBuffer::print_byte_unchecked method (#6496)
Pure refactor. `*_unchecked` is the conventional name for unsafe methods, not `*_unsafe`.
2024-10-13 09:51:49 +00:00
overlookmotel
5843e01bed refactor(codegen): shorten CodeBuffer::take_source_text (#6495)
Pure refactor.
2024-10-13 09:51:47 +00:00
overlookmotel
951def6e35 refactor(codegen): clarify safety comments in CodeBuffer (#6494) 2024-10-13 09:36:40 +00:00
overlookmotel
84a51ee576 refactor(codegen): rename vars in CodeBuffer (#6493)
Pure refactor. Just rename vars.
2024-10-13 09:36:39 +00:00
overlookmotel
05bd616d88 refactor(codegen): add line break (#6492) 2024-10-13 09:27:42 +00:00
DonIsaac
204bf5533e refactor(codegen): add CodeBuffer to fix soundness hole (#6148)
# What This PR Does

Adds `CodeBuffer`, a simple wrapper over a `Vec<u8>` with a protective and reduced API for upholding UTF-8 validity guarantees. Closes #6147.

Note that this struct is actually quite small. Most of the added lines are doc comments.
2024-10-13 09:14:48 +00:00
Dunqing
02bfbfeef5 fix(codegen): preserve parenthesis for ChainExpression (#6430)
close: #6385

The fixing way was referenced from `esbuild`, it is according to these [states](332727499e/internal/js_ast/js_ast.go (L590-L604)
)(determined in the parser) to determine whether to print parenthesis

Due to differences in implementation details, we are unable to record certain information like `esbuild` does in its parser. But fortunately, The `ParenthesisExpression` AST is actually like what `esbuild` stored states.
2024-10-13 08:03:37 +00:00
camc314
2ade16ece5 fix(codegen): invalid codegen when in inside bin expr in or loop (#6431)
https://github.com/oxc-project/monitor-oxc/actions/runs/11278829870 ??
2024-10-13 06:47:10 +00:00
camc314
6896efc00c fix(codegen): fix in in sequence expr in for loops (#6428)
not sure if this is right, but it doesn't break any existing tests so hopefully?
2024-10-13 06:47:09 +00:00
Boshen
91c87dd380 refactor(codegen)!: remove Codegen::enableSourceMap API (#6452) 2024-10-12 04:56:43 +00:00
Boshen
7645e5c34b refactor(codegen)!: remove CommentOptions API (#6451) 2024-10-11 13:53:28 +00:00
Boshen
520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Dunqing
702b574afb refactor(codegen): only print necessary parentheses in TSAsExpression (#6429)
Part of fixing #6385
2024-10-11 02:04:27 +00:00
Dunqing
84b2d072e8 fix(codegen): converts line comment to block comment if it is a PURE comment (#6356)
The last part of fixing https://github.com/rolldown/rolldown/pull/2375/files#r1789011257

In the following case, the pure comment was written by `//`
```ts
const Component = // #__PURE__
React.forwardRef((props, ref) => {});
```

The printed code looks like this
```ts
const Component =
// #__PURE__ React.forwardRef((props, ref) => {});
```

As you can see, it is broken because the code also commented, so we need to replace `//` with `/* */`
2024-10-08 05:42:42 +00:00
Boshen
020bb80b65 refactor(codegen)!: change to CodegenReturn::code and CodegenReturn::map (#6310) 2024-10-06 05:05:47 +00:00
DonIsaac
ab187d1e22 refactor(codegen): restrict visibility of internal methods (#6145)
add `pub(crate)` to `Codegen` methods that should only be used within `oxc_codegen`
2024-09-28 14:33:42 +00:00
Dunqing
05852a04ed perf(codegen): do not check whether there are annotation comments or not if we don't preserve annotation comments (#6107) 2024-09-27 11:18:42 +00:00
Dunqing
8582ae3e91 fix(codegen): missing parentheses if there is a pure comment before a NewExpression as a ComputedMemberExpression's callee (#6105)
refer to 332727499e/internal/js_printer/js_printer.go (L2544)
2024-09-27 07:12:31 +00:00
Dunqing
cca433f84a feat(codegen): print vite / webpack special comments (#6021)
Related: https://github.com/oxc-project/oxc/issues/1046#issuecomment-2347345319
Close: #6024
2024-09-26 15:19:31 +00:00
Dunqing
fe696f0dec refactor(codegen): simplify printing annotation comments (#6027)
Simplify printing annotation comments, reusing the architecture of printing JSDoc.
2024-09-25 06:27:18 +00:00
Boshen
c8682e9fcb fix(semantic,codegen,transformer): handle definite ! operator in variable declarator (#6019)
closes #5999
2024-09-24 08:32:05 +00:00
Boshen
9ca202a01e fix(codegen): preserve newlines between comments (#6014)
fixes #6010
2024-09-24 05:14:02 +00:00
camc314
4a99372c14 fix(codegen): print jsdoc comments for TSEnumMembers (#6007)
closes #6006

Boshen/Dunqing please feel free to take over this PR. it's a bit outside what i normally work on. 🙂
2024-09-24 01:12:57 +00:00
Boshen
362c427b94 fix(mangler,codegen): do not mangle top level symbols (#5965) 2024-09-22 13:45:54 +00:00
Boshen
f4aefb57d8 fix(codegen): print let[0] as (let)[0] (#5947) 2024-09-21 15:09:55 +00:00
Boshen
d901772daa feat(codegen): implement minify number from terser (#5929) 2024-09-20 14:42:28 +00:00
Boshen
cee9d0ba5f fix(codegen): fix spacing of for await (x of y) (#5890) 2024-09-19 15:15:28 +00:00
Boshen
dfbde2c602 feat(isolated_declarations): print jsdoc comments (#5858) 2024-09-18 14:09:00 +00:00
Boshen
9f6696a6aa feat(codegen): add new lines to TSTypeParameterDeclaration (#5853) 2024-09-18 11:44:24 +00:00
Boshen
bcdbba3981 feat(codegen): print jsdoc comments that are attached to statements and class elements (#5845)
I am unable to print all comments correctly. Comments have way too much semantic meaning in JavaScript.

This PR reduces the scope to only print jsdoc comments that are attached to statements and class elements, in order to get isolated declarations shipped.
2024-09-18 07:58:22 +00:00
Boshen
42dcadfccf fix(parser): hashbang comment should not keep the end newline char (#5844)
Previously it included a newline in the value

```
  "hashbang": {
    "type": "Hashbang",
    "start": 0,
    "end": 16,
    "value": "/usr/bin/node\n"
  },
```

This change will also make the lexer emit a `\n` token, which will make comment position detection correct.
2024-09-18 05:41:44 +00:00
DonIsaac
26386da01e feat(codegen): have with_source_text reserve memory for code buffer (#5823)
`Codegen::with_source_text` gives us enough information to use `Codegen::with_capacity`. This change makes the API cleaner as users have to provide less redundant information.
2024-09-18 03:27:43 +00:00
Boshen
5901d2a0f1 fix(codegen): various spacing issues (#5820) 2024-09-17 09:03:28 +00:00
Boshen
e613a3d877 refactor(codegen): prepare to add leading comments by adding a template method pattern (#5784) 2024-09-15 09:41:53 +00:00