Commit graph

192 commits

Author SHA1 Message Date
Dunqing
c78291600e feat(codegen): print type_parameters in TaggedTemplateExpression (#5438) 2024-09-04 11:24:04 +00:00
rzvxa
59abf27d95 feat(ast, parser): add oxc_regular_expression types to the parser and AST. (#5256)
closes #5060
2024-09-03 02:36:37 +00:00
Dunqing
1aa49af010 feat(ast)!: remove JSXMemberExpressionObject::Identifier variant (#5358)
close: #5353

`JSXMemberExpressionObject::Identifier` is dead code.
2024-09-02 18:35:39 +00:00
Dunqing
32f730085c feat(ast)!: add JSXElementName::IdentifierReference and JSXMemberExpressionObject::IdentifierReference (#5223)
close: #3528

part of #4746
2024-08-30 11:11: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
Dunqing
550574982f feat(ast): add accessibility field to AccessorProperty (#5290) 2024-08-28 08:42:37 +00:00
Kevin Deng 三咲智子
234a24c14d
fix(ast)!: merge UsingDeclaration into VariableDeclaration (#5270)
relate #2854
2024-08-28 11:26:05 +08:00
overlookmotel
12a7607bac perf(codegen): inline Codegen::print_list (#5221)
Revert #5192 and add a comment that it's not a perf gain.

This was really surprising to me, but the benchmarks do demonstrate it.

Please see the benchmarks commit-by-commit on this PR. Adding `#[inline]` to the function does give +1% gain, but it's no better than it was before #5192. So I think preferable to just revert to the simpler original.

I think likely explanation is that the compiler is already performing this optimization itself. And if it does it itself, then it understands the code better, and can then make better decisions about inlining.

https://godbolt.org/z/xzhWWeMoe seems to demonstrate this - there are 2 calls to `Item::gen` in the generated assembly, so it has split the loop into 2.
2024-08-26 10:28:49 +00:00
overlookmotel
d4c3778e02 refactor(codegen): rename vars (#5222)
Rename function params in default methods of `Codegen`. Makes no material difference, just nicer hints in IDE.
2024-08-26 08:40:50 +00:00
Boshen
fb847bd0ba perf(codegen): slightly faster print_list (#5192) 2024-08-26 01:37:48 +00:00
Boshen
543cad6370
refactor(codegen): remove some pub APIs 2024-08-25 13:32:55 +08:00
Boshen
7b1546bb66
fix(codegen): do not print comments when --minify 2024-08-24 13:49:34 +08:00
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