Commit graph

6446 commits

Author SHA1 Message Date
overlookmotel
5c299bc10c refactor(ast_tools): move JS file header creation (#6897)
Move creation of generated JS/TS file headers out of individual generators.
2024-10-25 18:09:50 +00:00
overlookmotel
3e7507f9d0 refactor(ast_tools): reduce macro usage (#6895)
1. Reduce the amount of code in `define_derive!` and `define_generator!` macros. This makes the code easier to read, and gives type hints in IDE.
2. Remove `generated_header!` macro and insert header as a blanket action, instead of repeated code in every generator.
2024-10-25 17:42:09 +00:00
overlookmotel
5b21eb5455 refactor(ast_tools): remove dead code (#6894) 2024-10-25 17:10:41 +00:00
Boshen
8bcaf59cf9 feat(minifier): late peeophole optimization (#6882) 2024-10-25 16:12:29 +00:00
overlookmotel
adb50398b8 refactor(allocator): add impl GetAddress for Address (#6891)
This allows passing an `Address` to methods like `StatementInjectorStore::insert_before` if you want to.
2024-10-25 15:20:21 +00:00
overlookmotel
262b2ed1ce style(ast): move crate doc comment to top of file (#6890)
Docs are more important than clippy, so docs go first!
2024-10-25 14:31:35 +00:00
Boshen
6eeb0e6385 docs(ast): mention typescript-eslint, field ordering and shape (#6863)
closes #6453
2024-10-25 14:31:34 +00:00
Boshen
4dc5e51cb1 fix(transformer): only run typescript plugin for typescript source (#6889)
closes #6865

TypeScript plugin changes import / export statements so it needs to be turned off for non-typescript files. This should also give a little performance boost for non-typescript files.
2024-10-25 13:59:31 +00:00
overlookmotel
2d95009bca refactor(transformer): implement Debug on StatementInjector internal types (#6886) 2024-10-25 12:58:28 +00:00
overlookmotel
c383c34a61 refactor(transformer): make StatementInjectorStore methods generic over GetAddress (#6885)
`StatementInjectorStore::insert_before` etc take any `GetAddress`. This allows using them with an `Ancestor` as well as a `Statement`.

Split the implementation of each function into 2 parts - generic outer wrapper and non-generic inner function to allow compiler to make better inlining decisions, and reduced compile time.
2024-10-25 12:50:58 +00:00
Boshen
4618aa22d9 refactor(transformer)!: rename TransformerOptions::react to jsx (#6888) 2024-10-25 12:04:33 +00:00
overlookmotel
419343bdd5 feat(traverse): implement GetAddress for Ancestor (#6877)
Closes #6803. Allow getting `Address` of an `Ancestor`.
2024-10-25 10:52:01 +00:00
Boshen
1f29523fed refactor(transformer): rename ReactJsx to Jsx (#6883)
This plugin is no longer about React.

The next PR will move out the React refresh plugin, which can be turned
on in isolation.
2024-10-25 10:37:28 +00:00
camc314
860cbca446 feat(minifier): implement folding simple arrow fns (#6875)
basically
```ts
const foo = () => {
    return baz
}
```
becomes
```ts
const foo = () => baz
```
2024-10-25 10:26:33 +00:00
Tapan Prakash
a73c5af0f5
feat(linter): Add fixer for jsx-a11y/no-access-key rule (#6781) 2024-10-25 02:48:12 -04:00
Boshen
442975408b feat(ecmascript): constant eval null to number (#6879) 2024-10-25 04:23:24 +00:00
Dunqing
0d0bb17ad9 feat(transformer): complete the async-to-generator plugin (#6658)
In this PR, most of the async functions have transformed correctly. But the async arrow functions don't fully transform correctly yet, it is related to we need to transform the arrow function to the generator function. For example:

Input:
```js
function declaration() {
  const asy = async () => {
  console.log(this.name)
 }
}
```

Output:
```js
function declaration() {
  const asy = babelHelpers.asyncToGenerator(function* () {
     console.log(this.name);
  });
}
```

Expected Output:

```js
function declaration() {
  var _this = this;
  const asy = /*#__PURE__*/function () {
    var _ref = babelHelpers.asyncToGenerator(function* () {
      console.log(_this.name);
    });
    return function asy() {
      return _ref.apply(this, arguments);
    };
  }();
}
```

From the expected output, we haven't handled `this` correctly, which means even if the `arrow-function` plugin doesn't enable, we still need to handle this correctly as the `arrow-function` plugin does, and further question if `arrow-function` plugin is enabled, how to avoid these making conflict?

I thought we may move out the implementation of `arrow-function` and as a common helper, this way every plugin can handle this well
2024-10-25 03:23:31 +00:00
Boshen
fcc6221aa9
chore(oxc_release.toml): add npm/oxc-types/package.json 2024-10-25 11:22:29 +08:00
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