Commit graph

6428 commits

Author SHA1 Message Date
Boshen
d49716bc3b
ci(release_types): changes for ready to publish 2024-10-25 11:16:03 +08:00
Boshen
fe28bae1e0
chore: remove unnecessary packageManager from package.json 2024-10-25 10:38:02 +08:00
leaysgur
90c786c420 feat(regular_expression)!: Support ES2025 Duplicated named capture groups (#6847)
Closes #6358

@preyneyv I know you've been working on this problem.

This is an implementation that has been dormant on my local for a while.

- All tests are passing
- However, the approach is simple but not general, so there might be some edge cases that were missed
- There's also room for improvement in terms of performance

For these reasons, it was marked as WIP for me.

I believe the test cases and other parts are usable, so feel free to fork and replace them with your implementation if you'd like.
2024-10-25 02:13:57 +00:00
DonIsaac
f49b3e2088 fix(linter): react/iframe-missing-sandbox ignores vanilla JS APIs (#6872)
> Closes #6750

Fixes a false positive in `react/iframe-missing-sandbox` on `document.createElement`, which is not react and has no way of passing a sandbox prop/attribute on creation.
2024-10-25 01:43:55 +00:00
camc314
c26020e553 feat(minifier): implement folding String.prototype.replaceAll (#6871) 2024-10-25 01:29:57 +00:00
camc314
50744f341b feat(minifier): implement folding String.prototype.replace (#6870) 2024-10-25 01:29:57 +00:00
camc314
fccf82e4df feat(minifier): implement folding substring string fns (#6869) 2024-10-25 01:29:56 +00:00
ottomated
b075982eaa fix(types): Change @oxc/types package name (#6874)
Closes #6862.

Possible options:
- `oxc-types`
- `@oxc-project/types`
- `@oxc-ast/types`
- `oxc-ast-types`
2024-10-24 20:04:09 +00:00
camc314
322f9d44b7 chore(minifier): remove planned minification for String.substr as its deprecated (#6868)
According to mdn, `String.prototype.substr()` has been deprecated, hence i do not think it makes sense to attempt to optimize this code.

This pull request removes the test cases along with the placeholder code for minification of this method

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr
2024-10-24 14:53:22 +00:00
camc314
e6a5a1b11c feat(minifier): implement folding charCodeAt string fns (#6475) 2024-10-24 14:37:50 +00:00
overlookmotel
4348eae157 refactor(transformer/typescript): re-order visitor methods (#6864)
It makes more sense for `exit_statement` to be after `enter_statement`.
2024-10-24 14:14:25 +00:00
Boshen
423d54cb74 refactor(rust): remove the annoying clippy::wildcard_imports (#6860) 2024-10-24 13:57:19 +00:00
ottomated
99e3b32d43
docs(napi): Remove JSON.parse from example (#6836)
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-10-24 14:49:44 +01:00
ottomated
67a7bde4c6 feat(napi/parser)!: add typings to napi/parser (#6796)
- Added TypeScript annotation for `ParseResult.program`
- Modified the entrypoint for `oxc-parser` to allow wrapping the napi functions
- Updated `index.js` to parse the `program` string into a JSON object
- Updated tests
- Added a dependency on `@oxc/types`
2024-10-24 13:08:59 +00:00
ottomated
1145341a92 feat(ast_tools): output typescript to a separate package (#6755)
Part of #6347.

Moves typescript logic from derive_estree into a new ast_tools generator.
2024-10-24 13:08:57 +00:00
Boshen
1c27a2c36c
ci(benchmark): do not skip linter benchmark
closes #6859
2024-10-24 21:01:55 +08:00
overlookmotel
333b758b49 refactor(transformer): StatementInjectorStore methods take &Statement as target (#6858)
This makes the use of `Address` an internal implementation detail of `StatementInjectorStore`. The caller shouldn't need to care about how `StatementInjectorStore` achieves its work. In future it might use `NodeId`, for instance.

We could broaden this in future so these methods take a `&A where A: GetAddress` if we need to, but for now taking a `&Statement` seems OK.
2024-10-24 12:38:57 +00:00
overlookmotel
c19996c2e7 refactor(transformer): add StatementInjectorStore::insert_many_before method (#6857)
This method is not used yet, but it seems natural to provide it as a counterpart to `insert_many_after`.
2024-10-24 12:38:56 +00:00
overlookmotel
7339dde473 refactor(transformer): StatementInjectorStore::insert_many_after take an iterator (#6856)
Follow-on after #6654.

Taking an `IntoIterator` avoids caller needing to construct a temporary `Vec`.
2024-10-24 12:38:54 +00:00
Boshen
a47c70e425 fix(minifier): fix remaining runtime bugs (#6855) 2024-10-24 12:22:18 +00:00
overlookmotel
a366fae8b7 refactor(traverse): rename TraverseScoping::generate_binding_in_current_scope (#6832)
Rename `generate_in_current_scope` to `generate_binding_in_current_scope` - more descriptive name.
2024-10-24 11:00:46 +00:00
Boshen
686727fc96 fix(minifier): reference read has side effect (#6851) 2024-10-24 08:32:38 +00:00
Boshen
c658d9336d fix(minifier): keep template literals with expressions (#6849) 2024-10-24 08:12:44 +00:00
Dunqing
076f5c39f4 fix(transformer/typescript): retain ExportNamedDeclaration without specifiers and declaration (#6848)
close: #6825
2024-10-24 07:59:07 +00:00
Cam McHenry
04b4bae5c5
feat(rulegen): add module definitions for new rules (#6845)
Makes new rule creation a little bit easier by automatically adding the
rule definition to `rules.rs` with the proper alphabetical order.

Example:



https://github.com/user-attachments/assets/c9584986-7d08-4f91-bce2-501a8441e446
2024-10-24 15:47:07 +08:00
Boshen
fd57e00108 feat(ecmascript): add abstract_relational_comparison to dce (#6846)
I removed bigint comparisons because they were incorrect
2024-10-24 06:46:07 +00:00
overlookmotel
3b99fe6d59 refactor(traverse): move generate_binding to TraverseScoping (#6831)
Follow-up after #6830.

Now that `generate_binding` doesn't need access to `AstBuilder`, it can move into `TraverseScoping`.

Occasionally this is helpful when you need to borrows 2 parts of `TraverseCtx` simultaneously. e.g.:

```rs
// This fails to compile because we try to mutably borrow `TraverseCtx`
// while it's already borrowed
if let Ancestor::ProgramBody(body) = ctx.parent() {
    //                               ^^^ immutable borrow
    let binding = ctx.generate_binding(name, scope_id, flags);
    //            ^^^ mutable borrow
}

// Borrow-checker allows this because we borrow fields of `TraverseCtx` separately
if let Ancestor::ProgramBody(body) = ctx.ancestry.parent() {
    let binding = ctx.scoping.generate_binding(name, scope_id, flags);
}
```
2024-10-24 06:19:39 +00:00
Dunqing
3a56d59dce refactor(transformer/typescript): insert assignments after super by StatementInjector (#6654) 2024-10-24 05:14:43 +00:00
overlookmotel
60f487a203 refactor(traverse): TraverseCtx::generate_binding take an Atom (#6830)
Follow-up after #6805.

`TraverseCtx::generate_binding` take an `Atom` instead of a `CompactStr`. If it's an existing var name (which it must be, otherwise we'd be using `TraverseCtx::generate_uid`), an `Atom` will already exist in the arena for this symbol name, so we'd be better off reusing it, rather than writing the same `Atom` into the arena again.
2024-10-24 02:47:08 +00:00
oxc-bot
8f392e828e
release(crates): v0.33.0 (#6843) 2024-10-24 10:29:22 +08:00
Boshen
6bc40c9321
chore(deps): update crate-ci/typos action to v1.26.1 (#6841)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-24 10:13:24 +08:00
Boshen
fb01208891
ci(benchmark): fix linter benchmark triggering on unrelated files (#6840)
fixes #6824
2024-10-24 10:10:33 +08:00
DonIsaac
63ce9bec24 docs(ast): enable crate-wide warnings on missing doc comments (#6716)
Part of https://github.com/oxc-project/backlog/issues/130
2024-10-24 01:40:39 +00:00
Boshen
ca799936b0 fix(minifier): do not dce object literals yet (#6839)
closes #6769
2024-10-24 01:05:07 +00:00
Dmitry Zakharov
3923e63b61
docs(linter): add schema to config examples (#6838)
closes #6762
2024-10-24 08:44:04 +08:00
overlookmotel
d48e008e47
docs(napi): simplify + reformat README (#6834)
In particular:

* the long comment was scrolling off side of screen on
[npm.com](https://www.npmjs.com/package/oxc-parser).
* the example is ESM, so can simplify it by using top level await.
2024-10-24 08:34:46 +08:00
Alexander S.
dcddbeb689
chore(linter): add line break for consistent (#6837)
This regex expects always a line break before the closing bracet:
https://github.com/oxc-project/eslint-plugin-oxlint/blob/main/scripts/traverse-rules.ts#L110
2024-10-24 07:36:58 +08:00
Boshen
ec5a19b880 fix(minifier): do not remove binary expressions (#6829) 2024-10-23 16:07:29 +00:00
Tapan Prakash
2aa763c803
feat(linter): warn unmatched rule names (#6782)
Fixes https://github.com/oxc-project/oxc/issues/6763
2024-10-24 00:05:01 +08:00
Dunqing
fdd69e4b3f refactor(transformer/typescript): use TraverseCtx::generate_binding to create a symbol (#6806)
Obviously, we reduce much code after using this API
2024-10-23 15:50:11 +00:00
Dunqing
c96e739b96 feat(traverse): add generate_binding and generate_binding_current_scope APIs in context (#6805)
These two APIs are used to create a symbol with the provided symbol name, The difference from `generate_uid` is that we don't need to create a unique name for the symbol.

If you have a better method name for this, Feel free to edit this PR directly
2024-10-23 15:50:09 +00:00
Boshen
22355f73f3 fix(minifier): do not remove undefined for destructuring patterns (#6828) 2024-10-23 15:42:04 +00:00
Dunqing
5928f043b5 feat(semantic): add move_binding API in ScopeTree (#6808)
Part of #6658

This API is useful when we want to move a scope to another scope
2024-10-23 15:36:30 +00:00
Dunqing
e7e60dab68 feat(semantic): add change_parent_id API in ScopeTree (#6807)
Part of #6658

This API is useful when we want to move a scope to another scope
2024-10-23 15:29:28 +00:00
Boshen
088c1b6460 fix(coverage): turn off mangle for runtime test (#6827) 2024-10-23 15:05:36 +00:00
Boshen
7291f71019 fix(coverage): enable only_remove_type_imports for runtime transform test (#6826) 2024-10-23 14:26:48 +00:00
overlookmotel
e5f4b4a333 refactor(transformer/react-refresh): dereference ScopeId as soon as possible (#6820)
Style nit. Dereference `&ScopeId` to `ScopeId` as early as possible. `&ScopeId` is 8 bytes, whereas `ScopeId` is 4 bytes.

In simple cases like this, compiler will optimize it anyway, but still I think it's a better pattern to dererence early. In more complicated cases, it will be better for performance, and in my opinion, it makes things clearer if vars called `scope_id` are always a `ScopeId`, not sometimes a `&ScopeId`.
2024-10-23 13:26:24 +00:00
overlookmotel
57685b28e8 refactor(transformer/react-refresh): unwrap BindingIdentifier::symbol_id (#6817)
Nit. `BindingIdentifier::symbol_id` should always be `Some`. Panic rather than exiting early  if it's not.
2024-10-23 13:26:23 +00:00
overlookmotel
4f6dc22a38 refactor(transformer/react-refresh): avoid re-creating Atoms (#6816)
Store `BoundIdentifier` in `registrations`. This allows removing the call to `ctx.ast.atom()` which re-allocates a new `Atom` into the arena - unnecessary as it's already been allocated when the UID was created.

It's unfortunate that `Semantic` stores symbol names as `CompactStr`s instead of `Atom`s, otherwise we could get the name as an `Atom` without re-allocating it. Hopefully we can make that change in future, and then reduce `BoundIdentifier` to just contain the `SymbolId`. But for now, we are kind of stuck with it.
2024-10-23 13:26:23 +00:00
overlookmotel
8316069e7d refactor(transformer/react-refresh): shorten code by using BoundIdentifier (#6815)
Pure refactor. Use `BoundIdentifier` for shorter code.
2024-10-23 13:26:22 +00:00