Commit graph

79 commits

Author SHA1 Message Date
Dunqing
585cdd5bcd chore(codegen): add more tests for comments from esbuild (#6357)
Copy from https://github.com/rolldown-rs/rolldown/blob/main/crates/rolldown/tests/esbuild/dce/remove_unused_pure_comment_calls/entry.js
2024-10-08 05:42:43 +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
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
93d509db2b chore(codegen): test function reports duplicate error information (#6067)
<img width="649" alt="image" src="https://github.com/user-attachments/assets/7789a7b4-56fb-40a2-a76d-52a55fe2bfad">
2024-09-27 05:51: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
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
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
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
5901d2a0f1 fix(codegen): various spacing issues (#5820) 2024-09-17 09:03:28 +00:00
Boshen
bb95306efd refactor(codegen): change annotation comment tests to snapshot (#5800) 2024-09-16 05:03:43 +00:00
Boshen
4a8aec1605 feat(span)!: change SourceType::js to SourceType::cjs and SourceType::mjs (#5606) 2024-09-08 14:11:02 +00:00
Boshen
d62defb42d fix(codegen): do not print trailing commas for ArrayExpression (#5551)
closes #5532
2024-09-06 16:35:10 +00:00
Boshen
1bed5ce2a5 chore: run cargo +nightly fmt to sort imports (#5503)
They are never going to be stable are they ... cedf7a4daa/.rustfmt.toml (L8-L16)
2024-09-06 04:04:26 +00:00
rzvxa
0df1d9d97b fix(ast, codegen, linter): panics in fixers. (#5431)
Closes #5434

https://github.com/oxc-project/oxlint-ecosystem-ci/actions/runs/10685877915/job/29619941099
2024-09-05 05:59:22 +00:00
Dunqing
c78291600e feat(codegen): print type_parameters in TaggedTemplateExpression (#5438) 2024-09-04 11:24:04 +00:00
Boshen
5c4c00123d fix(codegen): print export @decorator declare abstract class Foo correctly (#5303) 2024-08-28 15:30:39 +00:00
Dunqing
292d162b23 feat(codegen): print missing fields for AccessorProperty (#5291)
Found in https://github.com/oxc-project/monitor-oxc/actions/runs/10592050362/job/29350666018
2024-08-28 08:42:39 +00:00
Boshen
ce4d4698b4 feat(codegen)!: remove const generic MINIFY (#5001)
This is a premature optimization, makes the code complicated, and bloats the final binary size.

The minify option is moved to `CodegenOptions`
2024-08-20 08:13:27 +00:00
Boshen
f210cf7873 fix(codegen): print TSSatisfiesExpression and TSInstantiationExpression (#4936)
I can't figure out the precedence so printing extra parentheses instead ...
2024-08-16 09:53:17 +00:00
IWANABETHATGUY
d49fb160e3 feat(oxc_codegen): support generate range leading comments (#4898)
1. Support print range leading comments for specific expr or stmt
2024-08-15 04:20:48 +00:00
Boshen
21f576252a fix(codegen): minify large numbers (#4889) 2024-08-14 06:52:17 +00:00
Boshen
e8de4bde41 fix(codegen): fix whitespace issue when minifying x in new Error() (#4886) 2024-08-14 04:29:17 +00:00
Boshen
a2269625cc fix(codegen): print TSNonNullExpression (#4869) 2024-08-13 08:47:07 +00:00
Boshen
3da33d3647 fix(codegen): missing parenthesis for PrivateInExpression (#4865) 2024-08-13 06:54:26 +00:00
IWANABETHATGUY
1808529a0c
fix(codegen): dedupe pure annotation comments (#4862)
Close https://github.com/oxc-project/oxc/issues/4843
2024-08-13 13:53:28 +08:00
Boshen
b58ed80a55 fix(codegen): enable more test cases (#4585) 2024-07-31 12:58:28 +00:00
Boshen
a558492bf9 feat(codegen): implement BinaryExpressionVisitor (#4548)
part of https://github.com/oxc-project/backlog/issues/58

`monitor-oxc` run: https://github.com/oxc-project/monitor-oxc/actions/runs/10179047831
binary expression stack length tally using `counts` in top 100 npm packages from monitor-oxc:

```
29772 counts
(  1)    17652 (59.3%, 59.3%): 0
(  2)     5772 (19.4%, 78.7%): 1
(  3)     3204 (10.8%, 89.4%): 2
(  4)     1276 ( 4.3%, 93.7%): 3
(  5)      616 ( 2.1%, 95.8%): 4
(  6)      308 ( 1.0%, 96.8%): 5
(  7)      202 ( 0.7%, 97.5%): 6
(  8)      168 ( 0.6%, 98.1%): 7
(  9)      114 ( 0.4%, 98.5%): 9
( 10)       90 ( 0.3%, 98.8%): 8
( 11)       84 ( 0.3%, 99.0%): 13
( 12)       58 ( 0.2%, 99.2%): 10
( 13)       48 ( 0.2%, 99.4%): 12
( 14)       32 ( 0.1%, 99.5%): 11
( 15)       20 ( 0.1%, 99.6%): 134
( 16)       16 ( 0.1%, 99.6%): 18
( 17)       16 ( 0.1%, 99.7%): 20
( 18)       12 ( 0.0%, 99.7%): 19
( 19)       12 ( 0.0%, 99.8%): 35
( 20)       12 ( 0.0%, 99.8%): 51
( 21)       10 ( 0.0%, 99.8%): 15
( 22)        6 ( 0.0%, 99.9%): 17
( 23)        6 ( 0.0%, 99.9%): 21
( 24)        6 ( 0.0%, 99.9%): 45
( 25)        4 ( 0.0%, 99.9%): 14
( 26)        4 ( 0.0%, 99.9%): 26
( 27)        4 ( 0.0%, 99.9%): 53
( 28)        2 ( 0.0%, 99.9%): 172
( 29)        2 ( 0.0%, 99.9%): 214
( 30)        2 ( 0.0%,100.0%): 22
( 31)        2 ( 0.0%,100.0%): 27
( 32)        2 ( 0.0%,100.0%): 28
( 33)        2 ( 0.0%,100.0%): 29
( 34)        2 ( 0.0%,100.0%): 31
( 35)        2 ( 0.0%,100.0%): 36
( 36)        2 ( 0.0%,100.0%): 46
( 37)        2 ( 0.0%,100.0%): 55
```
2024-07-31 12:44:19 +00:00
Boshen
7446e986c3 feat(codegen): align more esbuild implementations (#4510) 2024-07-28 13:35:37 +00:00
Boshen
35654e665c feat(codegen): align operator precedence with esbuild (#4509)
closes #4339
2024-07-28 11:48:51 +00:00
Boshen
6a94e3f573 fix(codegen): fixes for esbuild test cases (#4503) 2024-07-28 08:57:15 +00:00
Boshen
e1ca4122d8 chore(codegen): port over esbuild codegen tests (all ignored right now) (#4457) 2024-07-25 10:00:34 +00:00
Boshen
44a10c4b91 fix(codegen): object shorthand with parens ({x: (x)}) -> ({ x }) (#4391) 2024-07-21 14:04:17 +00:00
Boshen
3d88f20cbb
fix(codegen): print shorthand for all { x } variants (#4374)
closes #4340
2024-07-21 19:54:21 +08:00
Boshen
bf3d8d3e8f fix(codegen): print annotation comment inside parens for new and call expressions (#4290) 2024-07-16 06:55:36 +00:00
Boshen
9a094e861e
chore(codegen): add ts snapshot test 2024-07-14 20:46:22 +08:00
Boshen
06197b8be4
refactor(codegen): separate tests 2024-07-14 12:56:02 +08:00
Boshen
e167ef79c6 fix(codegen): print parenthesis properly (#4245)
`TSParenthesizedType` handles parenthesis in ts types.

It should be considered a bug if parenthesis is not printed correctly after this PR.
2024-07-14 04:13:10 +00:00
IWANABETHATGUY
66b455a2b2
fix(oxc_codegen): avoid print same pure comments multiple time (#4230)
## Before 
```bash
Original:
const builtInSymbols = new Set(
  /*#__PURE__*/
  Object.getOwnPropertyNames(Symbol)
    .filter(key => key !== 'arguments' && key !== 'caller')
)


Printed:
const builtInSymbols = new Set(/*#__PURE__*/ /*#__PURE__*/ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller"));

Minified:
const builtInSymbols=new Set(Object.getOwnPropertyNames(Symbol).filter((key)=>key!=="arguments"&&key!=="caller"))

```

## After
```bash
Original:
const builtInSymbols = new Set(
  /*#__PURE__*/
  Object.getOwnPropertyNames(Symbol)
    .filter(key => key !== 'arguments' && key !== 'caller')
)


Printed:
const builtInSymbols = new Set(/*#__PURE__*/  Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller"));

Minified:
const builtInSymbols=new Set(Object.getOwnPropertyNames(Symbol).filter((key)=>key!=="arguments"&&key!=="caller"))

```
2024-07-12 23:07:43 +08:00
Boshen
83c2c62f7b feat(codegen): add option for choosing quotes; remove slow choose_quot method (#4219) 2024-07-12 03:08:22 +00:00
IWANABETHATGUY
1c117eb20d
fix: avoid print extra semicolon after accessor property (#4199)
## Before
```js
export default class Foo { @x @y accessor #aDef = 1 }
```
**output** 
```bash
Original:
export default class Foo { @x @y accessor #aDef = 1 }


Printed:
export default class Foo {
        accessor #aDef=1;;
}

```
2024-07-11 20:16:02 +08:00
Boshen
083fe38971
chore(codegen): add a for loop special case 2024-07-11 01:35:05 +08:00
IWANABETHATGUY
365d9ba252
feat(oxc_codegen): generate annotation comments before CallExpression and NewExpression (#4119)
1. test case copy from `vue/core`, here are all usages of `#__PURE__` in
`vue/core`
https://gist.github.com/IWANABETHATGUY/c7911ecd98467a2969b2a994a34d32bc#file-pure_annotation_in_vue_repo-sh
2. Also took a look in other codebase,
https://github.com/search?q=%23__PURE__&type=code, most of the usage of
`#__PURE__` attached as leading comment before `CallExpression` and
`NewExpression`
2024-07-09 00:22:28 +08:00
michaelm
564a75ab37
fix(codegen): missing TypeParameters in TSConstructSignature (#4063) 2024-07-06 13:59:49 +08:00
Boshen
aaac2d8775
fix(codegen): preserve parentheses from AST instead calculating from operator precedence (#4055)
…operator precedence

Calculating from operator precedence is currently unsafe and will result
incorrect semantics.
2024-07-05 14:01:17 +08:00
Egor Blinov
5e5b1b14a1
fix(codegen): correct accessibility emit for class formal-parameters/methods/properties (#4042) 2024-07-03 17:27:41 +08:00