Commit graph

7421 commits

Author SHA1 Message Date
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
overlookmotel
ac097e9160 refactor(transformer/class-properties): rename file (#8036)
Pure refactor. Rename file to make filename more descriptive of what it does.
2024-12-20 10:07:24 +00:00
overlookmotel
043252dcd1 fix(transformer/class-properties): replace this and class name in static blocks (#8035)
Transform `this`, class name, and `super` in static blocks.
2024-12-20 10:07:23 +00:00
overlookmotel
273795d471 fix(transformer/class-properties): run other transforms on static properties, static blocks, and computed keys (#7982)
Large re-architecting of class properties transform. Split transform into 3 phases:

1. Transform instance properties when entering class.
2. Transform private fields during traversal of class body.
3. Transform static properties and static blocks when exiting class.

This ensures that code which has to be moved outside of the class (static property initializers, static blocks, computed keys) can get transformed by other transforms before they're moved out.

Also fixes a problem where we previously registered private properties too early - on entering the class, rather than the class *body*, so private fields in `extends` clause of a nested class were misinterpretted.
2024-12-20 10:07:23 +00:00
overlookmotel
6b6444b523 feat(traverse): record current block scope (#8007)
Record "block" scope ID along with "hoist" scope ID in `Traverse`.

"Block" scope is the scope where a `let` statement would be inserted above current position in AST.

Block scope and current scope differ from each other inside classes. For example, if want to create a `let` temp var for `foo()` or `bar()` in example below, should use block scope not current scope. Current scope is the class itself, but the `let` statement will be inserted *outside* the class.

```js
class C {
  [foo()]: bar();
}
```

All transforms which create `let` bindings should use block scope not current scope. We should add `VarDeclarationsStore::insert_let` method which uses block scope, to accompany `insert_var` (which uses hoist scope).

This is implemented in a rather hacky way, and we should improve it later. Notably, we're not considering `for` statements as block scopes because we currently have no way to insert `let` statements into them if they don't have a body block.
2024-12-20 03:50:44 +00:00
overlookmotel
059a5dd56a refactor(transformer/class-properties): do not pass ScopeId into insert_instance_inits (#8001)
No need to pass this var through various functions, as they already have access to `self` to get it itself.
2024-12-20 03:10:24 +00:00
overlookmotel
c0dd3f8e32 perf(ast): move_expression and move_statement produce dummy with no span (#7995)
The purpose of `AstBuilder::move_*` methods is to create dummy nodes which will later be replaced again. Give the dummy nodes empty spans as it's faster, and no point in them having a real span.
2024-12-20 03:10:23 +00:00
overlookmotel
897a1a8946 feat(transformer/class-properties): exit faster from super replacement visitor (#8028)
When inserting instance property initializers into class constructor, need to search for and transform `super()`. Exit that visit earlier in some cases, for better performance and smaller output.
2024-12-20 03:10:22 +00:00
overlookmotel
de4c7726f9 refactor(traverse)!: rename Ancestor::is_via_* methods to is_parent_of_* (#8031)
Rename these methods. `is_via_*` is confusing as hell. `is_parent_of_*` is more descriptive.

`Ancestor::is_parent_of_statement` tells you if *previous* `Ancestor` is a `Statement`.
2024-12-20 03:10:22 +00:00
overlookmotel
f1adf9fa18 refactor(semantic): ScopeTree::rename_binding remove old binding first (#8020)
#8019 changed scope bindings from an ordered `IndexMap` to an unordered `FxHashMap`.

`ScopeTree::rename_binding` no longer needs to preserve order, so can remove the old binding before adding the new one. This makes it less likely that the hash map will need to reallocate.

Also remove comments about preserving ordering of bindings, which are now outdated.
2024-12-20 02:38:30 +00:00
Alexander S.
340cc90f12
fix(linter): rule no-restricted-imports: fix option "importNames" (#7943)
all test cases with `importNames` are now passing.

Now working on the other options
2024-12-20 10:37:23 +08:00
Alexander S.
5722346ee0
refactor(language_server)!: use .oxlintrc.json when no config path provided (#8027)
Will break for other IDEs when they do not self provide an default value
2024-12-20 10:30:03 +08:00
Alexander S.
de8246b96f
refactor(language_server): move structs into own file (#8026)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-20 10:29:44 +08:00
camc314
b2a4a786ae refactor(linter): remove unused with_rules and set_rule methods (#8029)
this method is unused, hence it makes sense to remove.
furthermore, keeping it makes it tricky to work the nested config stuff
2024-12-19 21:43:28 +00:00
camc314
6344b934ae fix(lsp): improve err handling when loading source text (#8025)
note i didn't test this, but it's panicing because `fs::read_to_string` is returning an error as the path no longer exists.

fixes https://github.com/oxc-project/oxc/issues/8023
2024-12-19 19:07:49 +00:00
overlookmotel
0f9308f152 perf(transformer/react-refresh): reduce allocations (#8018)
Small optimization. When generating hash of hooks key, build the hash string directly in arena, avoiding an intermediate heap-allocated `String`, by using `base64` crate's `encode_slice` method which writes directly into a slice.

`base64` crate is rather inefficient - there are various optimizations that could be made. But not worth getting into that, as this is only place we use `base64` crate in a performance-sensitive context.
2024-12-19 17:46:31 +00:00
overlookmotel
75b775c055 feat(allocator): Vec<u8>::into_string (#8017)
Bumpalo has a method `String::from_utf8_unchecked` to covert a `Vec<u8>` to a `String`. But we can't use it because we use Bumpalo's `String` as our arena string type, but allocator_api2's `Vec` as our arena vec.

Provide the same functionality, that works around this incompatibility. Also use the faster `simdutf8` for checking that `Vec` contains a valid UTF-8 string.
2024-12-19 17:46:30 +00:00
overlookmotel
0deb9e6c2e perf(transformer/react-refresh): reserve capacity in hook key string (#8016)
Follow-on after #8013. Reserve sufficient capacity in `String` used to store hook key, before pushing to it.

Also refactor so code for constructing key is only included once.
2024-12-19 17:46:29 +00:00
overlookmotel
69b1ef3c16
style(tools): remove line break from deny.toml (#8022)
Extra line break is triggering autofix.
2024-12-19 15:46:43 +00:00
Boshen
c24f102255
chore: add Zlib license to deny.toml 2024-12-19 23:36:12 +08:00
Boshen
7aebed012d perf(semantic): allocate Bindings in allocator (#8021) 2024-12-19 15:16:03 +00:00
Boshen
02f968d02d refactor(semantic): change Bindings to a plain FxHashMap (#8019)
`IndexMap` was needed for the insertion order requirement in mangler.

Bindings (symbol ids) are monotonically increasing by binding
positions, which means we can get insertion order by sorting the symbol ids in
mangler.

Previous attempt: https://github.com/oxc-project/oxc/pull/4228
2024-12-19 14:16:28 +00:00
Dunqing
862838fd28 perf(codegen): remove useless to_owned (#8014) 2024-12-19 12:06:55 +00:00
Dunqing
7b703471b1 perf(transformer/react-refresh): avoid allocating string in each hook call (#8013)
related: https://github.com/oxc-project/oxc/pull/7970#issuecomment-2551294930;

Just realized this can be simplified to that
2024-12-19 12:06:54 +00:00
Boshen
e7476a1a28 refactor(semantic): remove serialize (#8015) 2024-12-19 09:51:12 +00:00
overlookmotel
0a38eea95c refactor(transformer/class-properties): use temp_var_name_base to generate temp var names for super transform (#8004)
Follow-on after #7997.

Generate "base name" for temp var using `temp_var_name_base` and then create the 2 temp bindings from it.

This is a bit more efficient than creating 2nd temp binding from name of the first temp binding, because the first binding's name has `_` added to start, and may have digits on the end, which have to be trimmed off again. Whereas the "base name" is ready to go.

Incidentally, changing the timing of when temp bindings are created also aligns output with Babel.
2024-12-19 02:24:58 +00:00
overlookmotel
63a95e4aa2 feat(ast): add AstBulder::move_property_key (#7998)
Add `AstBuilder::move_property_key` method, same as the rest of `move_*` methods.
2024-12-18 23:17:54 +00:00
overlookmotel
d1b7181452 refactor(transformer/class-properties): rename var (#8006)
Give var more descriptive name.
2024-12-18 21:59:47 +00:00
overlookmotel
87ea928e17 test(transformer/class-properties): failing test for super.prop as assignment target (#8005)
Add failing test for syntax we can't support yet.
2024-12-18 19:07:24 +00:00
Dunqing
3ea4109d14 feat(transformer/class-properties): transform super update expressions within static prop initializer (#7997) 2024-12-18 18:29:05 +00:00
overlookmotel
5a23d72b37 refactor(transformer/class-properties): remove outdated comment (#8000) 2024-12-18 16:51:35 +00:00
Boshen
ed75e42ed6 refactor(semantic)!: make SymbolTable fields pub(crate) instead of pub (#7999)
SymbolTable needs some internal changes.
2024-12-18 16:38:58 +00:00
overlookmotel
df5c341c38 docs(ast): improve docs for AstBuilder::move_* methods (#7994) 2024-12-18 15:07:25 +00:00
Dunqing
b3a5f3eb59 refactor(transformer/class-properties): mark transform_assignment_expression_if_super_member_assignment_target as inline (#7993)
I forgot to mark it as inline like other methods do.
2024-12-18 13:59:40 +00:00
overlookmotel
5cf253c216 test(transformer/class-properties): more testing for assignment to super[prop] (#7992)
Amend test added in #7991 to test transform of `super[prop] = value` where `prop` is not bound.

We should ideally have the `_unbound` temp vars *inside* the arrow function rather than outside, as Babel does, but that's not possible with our double-visitor scheme at present, and I think current output will operate correctly anyway.

Probably these temp vars could be hoisted even higher up - to very top level of the file, even if the class and `super[prop]` were deeply nested in many functions - and it'd still be correct. That'd be good for transformer performance as less `var` statements to insert, and also slightly smaller output size - less `var`s in code. But I don't know if that would be worse for runtime performance, as it makes the arrow function more impure. 🤔
2024-12-18 12:49:42 +00:00
Dunqing
cc57db38e1 feat(transformer/class-properties): transform super assignment expressions within static prop initializer (#7991)
Alternative of #7956 and #7959. Unlike the previous method, adapting duplicating the same logic rather than making the same logic transform function to be generic
2024-12-18 11:28:39 +00:00