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
Egor Blinov
7768d233c6
feat(isolated-declarations): support optional class methods ( #4035 )
...
Example class
```
export class A {
m1?(): void;
m2(): void {}
}
```
Before the fix:
```
export declare class A {
m1(): void;
}
```
with the fix:
```
export declare class A {
m1?(): void;
m2(): void;
}
```
2024-07-03 09:46:59 +08:00
Dunqing
7844734856
fix(codegen): missing const keyword in TSTypeParamter ( #4022 )
...
close : #4017
2024-07-02 13:47:24 +00:00
Dunqing
6254a4106f
fix(codegen): missing TypeParamters in TSCallSignature ( #4021 )
...
close : #4015
2024-07-02 11:10:15 +00:00
Boshen
dac617de29
fix(codegen): print some missing typescript attributes ( #3980 )
2024-06-30 08:58:00 +00:00
Boshen
dc6d45e2e6
feat(ast,codegen): add TSParenthesizedType and print type parentheses correctly ( #3979 )
...
closes #3916
2024-06-30 07:57:48 +00:00
Boshen
051ceb6539
chore: improve some format by running cargo +nightly fmt
2024-06-19 00:48:30 +08:00
Boshen
5c38a0fd69
feat(codegen)!: new code gen API ( #3740 )
...
This PR introduces two type alias to avoid the confusing const generic `pub struct Codegen<'a, const MINIFY: bool>`
* CodeGenerator - Code generator without whitespace removal.
* WhitespaceRemover - Code generator with whitespace removal.
Usage is changed to a builder pattern:
```rust
CodeGenerator::new()
.enable_comment(...)
.enable_sourcemap(...)
.build(&program);
```
2024-06-18 15:50:12 +00:00
Boshen
5a99d30eba
feat(codegen): improve codegen formatting ( #3735 )
2024-06-18 11:10:36 +00:00
Boshen
da1e2d0e9b
fix(codegen): improve typescript codegen ( #3708 )
...
Remaining issues are tracked in https://github.com/oxc-project/oxc/issues/3692
2024-06-17 09:34:54 +00:00
Boshen
534242a729
feat(codegen)!: remove CodegenOptions::enable_typescript ( #3674 )
...
The typescript transform pass is now required to strip typescript syntax
for codegen to print things properly.
Codegen will now print whatever is in the AST.
2024-06-14 21:56:00 +08:00
Boshen
b58d8eb88f
fix!(codegen): remove the unecessary 4th argument from Codegen::new ( #3640 )
2024-06-12 07:58:54 +00:00
Boshen
f6752b482f
feat!(ast): make Trivias clonable by adding Arc ( #3638 )
...
This makes `Trivias` cloneable and stops us from using `Rc::new` and
`Rc::clone` everywhere.
`Trivias` is rarely cloned so an `Arc` should suffice.
2024-06-12 13:16:10 +08:00
IWANABETHATGUY
9fe0863479
chore(oxc_codegen): Pass trivias reference instead of ownership in CommentGenRelated ( #3529 )
...
1. Avoid clone or move the ownership when generate comment with `oxc`
2024-06-04 23:21:06 +08:00
Dunqing
ddac2a0e12
refactor(codegen): reduce allocation for print_unquoted_str ( #3525 )
2024-06-04 16:46:56 +08:00
Dunqing
d8063b6210
fix(codegen): wrong escape string ( #3514 )
...
close : #3492
2024-06-03 15:48:01 +08:00
IWANABETHATGUY
0cdb45a1ff
feat(oxc_codegen): preserve annotate comment ( #3465 )
...
1. Copy tests from
efa3dd2d8e/internal/bundler_tests/bundler_dce_test.go (L3833-L3971)
2. Add option to preserve annotate comment like `/* #__NO_SIDE_EFFECTS__
*/` and `/* #__PURE__ */`
2024-05-30 15:25:23 +08:00
Don Isaac
a12ed0fd26
fix(codegen): using declaration in for statement ( #3285 )
...
Fixes conformance tests for `using` declarations in for statements, e.g.
```ts
for (using x = 1;;) {}
```
2024-05-14 23:10:47 -04:00
Dunqing
fd5002bc51
feat(codegen): correctly print type-only imports/exports ( #2993 )
2024-04-15 18:33:02 +08:00
underfin
d9b77d853b
refactor(sourcemap): change sourcemap name to take a reference ( #2779 )
2024-03-23 21:40:05 +08:00
Boshen
ef932a3c27
refactor(codegen): clean up API around building sourcemaps ( #2602 )
...
closes #2564
2024-03-04 16:03:33 +08:00
Andrew McClenaghan
6b3b260dcc
feat(Codegen): Improve codegen ( #2460 )
...
This gets all the new TS types working to the same level TS output was
before and fixes a bunch of other codegen
---------
Co-authored-by: Boshen <boshenc@gmail.com>
2024-02-21 14:41:57 +08:00
Andrew McClenaghan
e6d536cb9b
feat(codegen): configurable typescript codegen ( #2443 )
...
- Adds option to `CodegenOptions` - `enable_typescript` to enable output
of TS.
- Stops skipping output that is TS when `enable_typescript` is enabled
- Adds TS support to
- Function
- FormalParameter
- BindingPattern
- Adds basic tests for TS generation
---------
Co-authored-by: Boshen <boshenc@gmail.com>
2024-02-20 12:09:28 +08:00
Wenzhe Wang
384d5acd7a
fix(codegen): lower the level of precedence in TaggedTemplateExpression ( #2391 )
2024-02-11 22:56:32 +08:00
Boshen
721f6cb74e
fix(codegen): format new expression + call expression with the correct parentheses ( #2330 )
...
closes #2328
2024-02-06 22:06:12 +08:00
Wenzhe Wang
0c225a49aa
fix(codegen): print space before with clause in import ( #2278 )
2024-02-02 14:52:32 +00:00
Wenzhe Wang
fa555ceed8
feat(codegen): change back to read raw ( #2222 )
2024-01-31 12:17:52 +08:00
Wenzhe Wang
9333264428
feat(codegen): print TemplateLiteral with print_str ( #2207 )
2024-01-29 23:09:29 +08:00
Yunfei He
d34650a1ac
fix(codegen): print necessary spaces for ExportAllDeclaration ( #2190 )
2024-01-29 01:05:09 +08:00
Wenzhe Wang
1ee6d8cea9
feat(codegen): move string test to codegen ( #2150 )
2024-01-23 23:49:36 +08:00