Commit graph

7456 commits

Author SHA1 Message Date
Boshen
ad2a620d61 fix(ast)!: add missing AssignmentTargetProperty::computed (#8097) 2024-12-24 13:27:00 +00:00
Boshen
b605baa4ac fix(minifier): constant fold strings with tab char (#8096) 2024-12-24 12:15:06 +00:00
dalaoshu
6bd9ddb8b9
fix(linter): false positive in typescript/ban-tslint-comment (#8094)
closes #8090
2024-12-24 19:18:41 +08:00
Boshen
6237c0527f feat(codegen): minify more whitespace (#8089) 2024-12-24 09:54:13 +00:00
Boshen
6355b7ca70 feat(codegen): minify export { 's' as 's' } -> export { 's' } (#8093) 2024-12-24 09:17:51 +00:00
Boshen
fccfda91c1 feat(codegen): minify class{static[computed]} (#8088) 2024-12-24 05:06:57 +00:00
Boshen
f873139a0f feat(codegen): minify for (_ of []) -> for(_ of[]) (#8086) 2024-12-24 04:17:50 +00:00
Boshen
8b8cbcd2db feat(codegen): minify case "foo" -> case"foo" (#8085) 2024-12-24 01:07:58 +00:00
Boshen
414c118309 feat(codegen): minify yield "s" -> yield"s" (#8084) 2024-12-24 00:41:28 +00:00
Boshen
f8f067bfc6 feat(codegen): minify class method async*fn(){} (#8083) 2024-12-24 00:35:29 +00:00
injuly
55d6eb9507
fix(parser): disallow type parameters on class constructors (#8071)
TypeScript does not allow type parameters on constructors:

```ts
class A {
  constructor<T>(t: T) {} // <- should be an error
}
```

Here's a comparison snippet on:
1. [TypeScript
playground](https://www.typescriptlang.org/play/?#code/MYGwhgzhAECC0G8BQ1XWAewHYQC4CcBXYXDfAHlgD4AKASkSRTQF8kWg)
(syntax error).
2. [SWC
playground](https://play.swc.rs/?version=1.10.1&code=H4sIAAAAAAAAA0vOSSwuVnBWqOZSUEjOzysuKSpNLskvsgmx09BUqFao5aoFAOf92%2FAiAAAA&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BCIOhERP9mOVBTl7oUE0maH3xszsA5KwcwGnmotxzIkTYx0ziXhHER%2FSgKSE7IhmwRuvRWu1agd4x5tRwOiaUKpW8j3hoOLkbHjLfM22DH%2FC030iZD5ClZUh8nhVTc0Jfj4XvayfaQ%2B9tA%2F4Ad12XkxWH71TaEFh%2B0LYuVI0xQBAAA%3D)
(syntax error)
3. [OXC
playground](https://playground.oxc.rs/#eNo9T8EKwjAM/ZWSk8IOKngpInjxCzx66Wo2Cl0zkk4do/9u6+guyXshL+9lAQsarDci6qaWZ1DKUpDIk43El8d1t1+nSpWaniFBAwR6AZ5CaTKHaL6gswQb8C7EisXSiBuZh5Z8ZZFNkI54AN0ZL5gaGA0Lcr6YcblS8bb6H0A03GO2AJTT4XiGvGHphT2WMJkMLrjOVXH+JTL5u6dPEb+RW5KcaTVN6QerbleM)
(parses as valid syntax)

This PR makes OXC behave exactly like `tsc`, with a little test case.
Happy holidays!

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-24 07:38:39 +08:00
Boshen
618b6aa085 feat(codege): minify whitespace in object getter / setter (#8080) 2024-12-23 16:36:03 +00:00
Boshen
1d5ae817d7 feat(codegen): minify const [foo] = bar -> const[foo]=bar (#8079) 2024-12-23 16:20:37 +00:00
Boshen
e3f78fba0b feat(codegen): new Foo() -> new Foo when minify (#8077) 2024-12-23 15:34:31 +00:00
Boshen
5397fe978a feat(minifier): constant fold undefined?.bar -> undefined (#8075) 2024-12-23 15:20:37 +00:00
Boshen
d84d60a3a9 feat(codegen): minify numbers with large exponents (#8074) 2024-12-23 13:35:52 +00:00
Boshen
373279b7f4 feat(codegen): balance string quotes when minify whitespace (#8072) 2024-12-23 13:24:22 +00:00
Boshen
0b04288139
feat(linter): move import/named to nursery (#8068)
There are race conditions in the runtime which may cause the module to
not find any exports from `exported_bindings_from_star_export`.
2024-12-23 20:29:43 +08:00
Boshen
e632a7b158 feat(transformer): remove typescript symbols after transform (#8069)
part of #7460
2024-12-23 08:24:54 +00:00
Boshen
8b54d898b5 refactor(minifier): remove parens must happen on enter (#8060) 2024-12-23 06:56:36 +00:00
Alexander S.
10a1fd57e5
fix(linter): rule: no-restricted-imports support option patterns with group key (#8050)
one/two wierd tests are not covered

> This is also an object option whose value is an array. This option
allows you to specify multiple modules to restrict using gitignore-style
patterns or regular expressions.

_https://eslint.org/docs/latest/rules/no-restricted-imports#patterns_

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-23 14:52:38 +08:00
Cameron
78d2e837f0
perf(sourcemap): improve perf of search_original_line_and_column (#7926)
this seems to show a decent speed up on perf.
the thinking behind this change is:
1. subsequent calls to `search_original_line_and_column` will **never**
look at back at lines it has already searched
2. binary search is faster in this case as typically `idx` is only
increased by a small amount

Given this, we can skip checking a bunch of lines (that will never
return true) improving performance.

This is a very hot path. 


```
$ hyperfine --warmup=3 ./target/release-with-debug/examples/sourcemap-main ./target/release-with-debug/examples/sourcemap
Benchmark 1: ./target/release-with-debug/examples/sourcemap-main
  Time (mean ± σ):      79.5 ms ±   5.5 ms    [User: 65.1 ms, System: 12.2 ms]
  Range (min … max):    76.8 ms … 111.7 ms    37 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: ./target/release-with-debug/examples/sourcemap
  Time (mean ± σ):      72.9 ms ±   0.9 ms    [User: 59.2 ms, System: 12.2 ms]
  Range (min … max):    70.6 ms …  75.0 ms    40 runs
 
Summary
  ./target/release-with-debug/examples/sourcemap ran
    1.09 ± 0.08 times faster than ./target/release-with-debug/examples/sourcemap-main
```

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-12-23 14:51:50 +08:00
underfin
f79e9ad91e
feat(napi/parser): add crate-type: "lib" (#8067)
The rolldown need export it to instead of `rollup/parseAst`, ref
https://rollupjs.org/javascript-api/#accessing-the-parser
2024-12-23 14:47:19 +08:00
Yuji Sugiura
922670e4b7
feat(prettier): Print directive (#8066)
Part of #5068 

- [x] Directive
2024-12-23 14:46:47 +08:00
overlookmotel
3057686543 fix(transformer/class-properties): unwrap parenthesised expressions (#8049)
Unwrap parenthesised expressions everywhere where we call `duplicate_object`.

This fixes panics in conformance tests.
2024-12-23 03:44:13 +00:00
overlookmotel
c2daa20751 feat(ast): add Expression::into_inner_expression (#8048)
Add `Expression::into_inner_expression`. Does the same as `get_inner_expression` and `get_inner_expression_mut`, but operates on an owned `Expression`.
2024-12-23 03:44:12 +00:00
overlookmotel
cbd51694cd refactor(transformer/class-properties): do not recreate private field if not transforming it (#8044)
Previously we were taking private fields from AST and then generating an identical node if not transforming it. Instead, just leave it as is.
2024-12-23 03:44:11 +00:00
overlookmotel
e67cd056a8 fix(transformer/class-properties): correctly resolve private fields pointing to private accessors (#8047)
We don't transform private accessors yet, but include them in private property resolution.

This fixes some panics in TS conformance tests which use private accessors.
2024-12-23 03:44:10 +00:00
overlookmotel
6b08c6e6c4 fix(transformer/class-properties): correctly resolve private fields pointing to private methods (#8042)
We don't transform private methods yet, but in class properties transform, still need to record private methods that classes have, so can correctly resolve private fields.

```js
class Outer {
  #foo = 123;
  method() {
    class Inner {
      #foo() {}
      // Refers to `Inner`'s `#foo` method, not `Outer`'s `#foo` property
      prop = this.#foo;
    }
  }
}
```
2024-12-23 03:44:08 +00:00
翠 / green
1932f1e0a0
feat(minifier): fold foo === undefined || foo === null (#8063)
This PR implements folding `foo === undefined || foo === null` into `foo
== null`.

I checked the minified output diff this time, so hoping that there isn't
a bug.
2024-12-23 00:10:44 +08:00
Boshen
774babb7f2 refactor(linter): read exported_bindings_from_star_export lazily (#8062) 2024-12-22 08:41:42 +00:00
Boshen
547c102b6b refactor(linter): use RwLock<FxHashMap> instead of FxDashMap for module record data (#8061) 2024-12-22 07:10:42 +00:00
Boshen
7cb84f34d1 refactor(minifier): only minify on ast node exit (#8059) 2024-12-21 11:08:38 +00:00
Boshen
23b563730f
feat(tasks/minsize): save minified file 2024-12-21 18:57:36 +08:00
Boshen
77d845a6b8 refactor(minifier): fuse DCE AST passes (#8058) 2024-12-21 10:30:38 +00:00
Boshen
be2c60dd10 fix(parser): parse import source from from 'mod' (#8056) 2024-12-21 10:20:14 +00:00
Boshen
8b025e36db chore(coverage): bump test262 (#8055) 2024-12-21 10:20:14 +00:00
overlookmotel
be4feb4ad7 feat(syntax): add SymbolId::new method (#8041)
Add `SymbolId::new` method, same as `ScopeId::new`. The advantage over `SymbolId::from_usize` is that `new` can be a `const` method.
2024-12-21 10:10:56 +00:00
Boshen
6123f5e6ff refactor(minifier): fold statements on exit (#8057) 2024-12-21 10:06:04 +00:00
overlookmotel
98e8a72bad refactor(transformer/class-properties): do not take mut ref when immut ref will do (#8040)
Tiny refactor. Not need to take a `&mut` when a `&` will do.
2024-12-21 07:21:30 +00:00
camc314
274f117d4e fix(transformer/nullish-coalescing): use correct scope id for binding (#8053) 2024-12-21 07:08:29 +00:00
overlookmotel
3d83396f0b test(transformer/nullish-coalescing): failing test (#8051)
Add failing test for nullish coalescing operator. The output is correct, but temp var is created in wrong scope.

My guess is that it needs to use `current_hoist_scope_id`, not `current_scope_id`.

This test from class properties also shows the same problem: ac097e9160/tasks/transform_conformance/snapshots/oxc.snap.md (L20-L35)
2024-12-21 07:08:29 +00:00
oxc-bot
d69de3629d
release(crates): v0.43.0 (#8054)
## [0.43.0] - 2024-12-21

- de4c772 traverse: [**BREAKING**] Rename `Ancestor::is_via_*` methods
to `is_parent_of_*` (#8031) (overlookmotel)

- ed75e42 semantic: [**BREAKING**] Make SymbolTable fields `pub(crate)`
instead of `pub` (#7999) (Boshen)

### Features

- 75b775c allocator: `Vec<u8>::into_string` (#8017) (overlookmotel)
- 8547e02 ast: Implement `allocator_api2` for `Allocator` (#8043)
(Boshen)
- 63a95e4 ast: Add `AstBulder::move_property_key` (#7998)
(overlookmotel)
- 897a1a8 transformer/class-properties: Exit faster from super
replacement visitor (#8028) (overlookmotel)
- 3ea4109 transformer/class-properties: Transform super update
expressions within static prop initializer (#7997) (Dunqing)
- cc57db3 transformer/class-properties: Transform super assignment
expressions within static prop initializer (#7991) (Dunqing)
- 6b6444b traverse: Record current block scope (#8007) (overlookmotel)

### Bug Fixes

- 043252d transformer/class-properties: Replace `this` and class name in
static blocks (#8035) (overlookmotel)
- 273795d transformer/class-properties: Run other transforms on static
properties, static blocks, and computed keys (#7982) (overlookmotel)

### Performance

- c0dd3f8 ast: `move_expression` and `move_statement` produce dummy with
no span (#7995) (overlookmotel)
- 862838f codegen: Remove useless to_owned (#8014) (Dunqing)
- 2736657 semantic: Allocate `UnresolvedReferences` in allocator (#8046)
(Boshen)
- 2e8872c semantic: Allocate child scope in allocator (#8045) (Boshen)
- 414e828 semantic: Allocate symbol data in Allocator (#8012) (Boshen)
- 7aebed0 semantic: Allocate `Bindings` in allocator (#8021) (Boshen)
- 0f9308f transformer/react-refresh: Reduce allocations (#8018)
(overlookmotel)
- 0deb9e6 transformer/react-refresh: Reserve capacity in hook key string
(#8016) (overlookmotel)
- 7b70347 transformer/react-refresh: Avoid allocating string in each
hook call (#8013) (Dunqing)

### Documentation

- df5c341 ast: Improve docs for `AstBuilder::move_*` methods (#7994)
(overlookmotel)

### Refactor

- f1adf9f semantic: `ScopeTree::rename_binding` remove old binding first
(#8020) (overlookmotel)
- 02f968d semantic: Change `Bindings` to a plain `FxHashMap` (#8019)
(Boshen)
- e7476a1 semantic: Remove `serialize` (#8015) (Boshen)
- 1cf7b83 semantic: Simplify handling namespace stack (#7987) (Dunqing)
- 48cb52b semantic: Remove resetting `current_reference_flags` in visit
functions (#7986) (Dunqing)
- 3250a47 semantic: Remove unused current_symbol_flags (#7985) (Dunqing)
- efe96ec semantic: Use `Stack` for function stack node ids (#7984)
(Dunqing)
- ac097e9 transformer/class-properties: Rename file (#8036)
(overlookmotel)
- 059a5dd transformer/class-properties: Do not pass `ScopeId` into
`insert_instance_inits` (#8001) (overlookmotel)
- 0a38eea transformer/class-properties: Use `temp_var_name_base` to
generate temp var names for `super` transform (#8004) (overlookmotel)
- d1b7181 transformer/class-properties: Rename var (#8006)
(overlookmotel)
- 5a23d72 transformer/class-properties: Remove outdated comment (#8000)
(overlookmotel)
- b3a5f3e transformer/class-properties: Mark
`transform_assignment_expression_if_super_member_assignment_target` as
inline (#7993) (Dunqing)

### Testing

- bcb33c0 semantic: Add a test for catch parameters reference (#7988)
(Dunqing)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-21 15:07:21 +08:00
camc314
952d7e46bf refactor(linter): rename flat.rs to config.rs (#8033)
simply renames `flat.rs` to `config.rs` to more accurately reflect the file's purpose
2024-12-21 02:01:40 +00:00
camc314
50848ede52 refactor(linter): simplify ConfigStore to prep for nested configs (#8032) 2024-12-21 02:01:40 +00:00
Boshen
2736657dcd perf(semantic): allocate UnresolvedReferences in allocator (#8046) 2024-12-20 15:18:16 +00:00
Boshen
2e8872cc3f perf(semantic): allocate child scope in allocator (#8045) 2024-12-20 15:18:16 +00:00
Boshen
414e8285cd perf(semantic): allocate symbol data in Allocator (#8012) 2024-12-20 14:13:41 +00:00
Boshen
8547e02456 feat(ast): implement allocator_api2 for Allocator (#8043) 2024-12-20 13:26:48 +00:00
Alexander S.
b3f38aeab9
fix(linter): rule no-restricted-imports: support option allowImportNames (#8002)
waiting for #7943
2024-12-20 20:56:05 +08:00