IWANABETHATGUY
b7db235065
fix: comments gen regression ( #5003 )
...
try to fix: https://github.com/rolldown/rolldown/issues/2013
1. Before we only considering the ast is untouched, but considering the
scenario.
```js
const a = /*__PURE__*/ test(),
// ^^^ ^^^^^^ is removed during transform
b = a();
```
Then according to the previous algorithm, `PURE` will attach to `b =
a()`
2. Now, we try to attach comments as much as possible unless the
comments are separated by comments, for the case above, `PURE` will not
be attached to `a()` since the content between `b = a()` and `/*
__PURE__*/` is not all whitespace.
3. we added back `MoveMap`, for the special case
```js
/*__NODE_SIDE_EFFECTS__*/ export const c = 100;
// ^^^^^^^^^^^^^^^^^^^^^ should be attached to first declarator,
// ^^^^^^ are not whitespace
```
2024-08-20 18:57:12 +08:00
Boshen
cd9cf5efd8
refactor(oxc): remove remove_whitespace
2024-08-20 18:27:59 +08: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
bbf9ec0774
fix(codegen): add missing declare to PropertyDefinition ( #4937 )
...
I'm seeing a broken test for
```rust
#[test]
fn dts_class_decl_prop_test() {
transform_dts_test(
"export class Foo { declare a: string }",
"export declare class Foo {
a: string;
}",
);
}
```
can you double check @Dunqing ?
2024-08-17 14:26:24 +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
4a5695416d
fix(codegen): print raw if value is number is Infinity ( #4676 )
2024-08-06 03:24:40 +00:00
overlookmotel
8dd76e4780
perf(codegen): reduce size of LineOffsetTable ( #4643 )
...
`LineOffsetTables` records mappings from byte offset to line and column numbers (with column number in UTF-16 characters).
Most lines do not contain any Unicode characters, and for these lines there is an exact correspondence between number of bytes from start of line and UTF-16 column number, so no column lookup table is required.
Reduce the data stored for each line from 32 bytes to 8 bytes by storing column offset lookup tables for the rare lines which do contain Unicode chars separately.
Additionally, store column lookup tables as a `Box<[u32]>` instead of `Vec<u32>` to reduce the size of `ColumnOffsets` by 8 bytes.
2024-08-06 01:08:12 +00:00
overlookmotel
b8e67538f8
perf(codegen): u32 indexes in LineOffsetTable for source maps ( #4641 )
...
Oxc have a limit on size of source files of 4 GiB, so `u32` is sufficient to hold line and column offsets. Use `u32` for these values in `LineOffsetTable`, which reduces size of the type by 8 bytes.
2024-08-05 02:28:50 +00:00
Boshen
e78cba6464
refactor(minifier): ast passes infrastructure ( #4625 )
...
After studying google closure compiler, I'm leaning towards a multi-ast-pass infrastructure for the minifier.
This is one of the few places where we are going to trade maintainability over performance, given the goal of the minifier is compression size not performance.
All of the terminologies and separation of concerns are aligned with google closure compiler.
Infrastructure of `terser` and `esbuild` are not suitable for us to study nor pursuit. Their code are so tightly coupled - I failed to comprehend any of them every time I try to walk through a piece of optmization. Google closure compiler despite being written in Java, it's actually the most readable minifier out there.
To improve performance between ast passes, I envision a change detection system over a portion of the code.
The benchmark will demonstrate the performance regression of running 5 ast passes instead of 2.
To complete this PR, I need to figure out "fix-point" and order of these ast passes.
2024-08-04 11:58:39 +00:00
Boshen
a40a217de4
fix(parser): parse assert keyword in TSImportAttributes ( #4610 )
...
closes #4601
2024-08-04 01:41:31 +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
DonIsaac
7585e16beb
perf(linter): remove allocations for string comparisons ( #4570 )
...
Refactors a lot of case-insensitive comparisons from
```rust
a.to_lowercase() == b.to_lowercase()
```
with
```rust
a.eq_ignore_ascii_case(b)
```
These mostly happened when checking JSX props, so I'm expecting the most benefit from JSX-related rules.
2024-07-31 00:24:12 +00:00
DonIsaac
d5c4b190aa
fix(parser): fix enum member parsing ( #4543 )
...
Closes #4449
2024-07-30 10:43:09 +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
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
e624dff1d4
fix(codegen,mangler): do not print shorthand for ObjectProperty ( #4350 )
...
I'll fix the TODO's later.
2024-07-18 16:26:33 +00:00
Boshen
3df9e697cc
fix(mangler): no shorthand BindingProperty; handle var hoisting and export variables ( #4319 )
...
Trying to pass tests in https://github.com/oxc-project/monitor-oxc
2024-07-17 18:12:42 +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
a71787572e
chore: remove unsafe_code = "warn" rust lint
...
Feels too verbose as we already have unsafe comment turned on
2024-07-15 10:39:08 +08:00
Boshen
9a094e861e
chore(codegen): add ts snapshot test
2024-07-14 20:46:22 +08:00
Boshen
d1c4be0020
refactor(codegen): clean up annotation_comment
2024-07-14 15:55:50 +08:00
Boshen
084ab7602d
fix(codegen): use ryu-js for f64 to string
2024-07-14 13:23:30 +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
Boshen
c65198fa15
fix(codegen): choose the right quote for jsx attribute string ( #4236 )
2024-07-12 17:30:24 +00:00
Boshen
be82c286d6
fix(codegen): print JSXAttributeValue::StringLiteral directly ( #4231 )
...
jsx attribute string is interpreted as is without escaping.
The transformer is responsible for converting it to plain js string.
2024-07-12 16:17:23 +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
e3e663bae4
feat(mangler): initialize crate and integrate into minifier ( #4197 )
2024-07-11 10:35:13 +00:00
Boshen
aa22073736
refactor(codegen): improve print API ( #4196 )
2024-07-11 08:41:04 +00:00
Luca Bruno
5731e3957f
refactor(ast)!: store span details inside comment struct ( #4132 )
...
This tweaks `Comment` definition in order to internally store the start
and end position of its span.
Closes: https://github.com/oxc-project/oxc/issues/4069
2024-07-09 23:23:43 +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
Boshen
5472b7c990
fix(codegen): 256 indentations level is not enough for codegen
2024-07-08 00:25:37 +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
23038ad8f8
fix(codegen): print TSFunctionType inside TSTypeAssertion ( #3999 )
2024-07-01 14:44:35 +00:00
Boshen
dac617de29
fix(codegen): print some missing typescript attributes ( #3980 )
2024-06-30 08:58:00 +00:00