Commit graph

5880 commits

Author SHA1 Message Date
Cam McHenry
f28006668b
chore(oxc): add release-with-debug cargo profile (#6166)
Simplifies creating a release build with debug information for
profiling/debugging purposes. Instead of needing to manually edit
`Cargo.toml` and add `strip = false` and `debug = true`, now you can
simply build with this profile:

```bash
cargo build --profile release-with-debug --bin oxlint
```
2024-10-01 11:14:30 +08:00
dalaoshu
705051560e
feat(rulegen): add diagnostic for rule template (#6187)
When writing new rules, it is always inevitable to add `diagnostic`.
Perhaps we can preset it in the `template`.

In addition, guide users to view relevant documents.
2024-10-01 11:04:50 +08:00
DonIsaac
5db9b3002c perf(allocator): use lower bound of size hint when creating Vecs from an iterator (#6194) 2024-10-01 00:07:29 +00:00
overlookmotel
70d4c569d8 refactor(transformer): rename VarDeclarationsStore methods (#6184)
Pure refactor. Shorten the names of `VarDeclarationsStore`'s public methods and add new `insert_declarator` method.
2024-09-30 19:15:27 +00:00
overlookmotel
81be5455d0 refactor(transformer): export var_declarations module from common module (#6183)
Tiny refactor. Export `var_declarations` module from `common`, rather than `var_declarations::VarDeclarationsStore`. Once we have more common transforms, the namespace of `common` module will become crowded.
2024-09-30 19:09:49 +00:00
overlookmotel
02fedf5123 refactor(transformer): shorten import (#6180)
Tiny change. Import with `use crate::TransformCtx` not `use crate::context::TransformCtx`.
2024-09-30 14:08:52 +00:00
Boshen
3b79e1bc9d feat(minifier): evaluate bigint in fold constant (#6178)
relates #6161
2024-09-30 12:53:42 +00:00
Dunqing
f2ac584bb8 refactor(transformer): use TraverseCtx's ast in ModuleImports (#6175)
close: #6173
2024-09-30 05:54:06 +00:00
overlookmotel
21b08ba141 refactor(transformer): shared VarDeclarations (#6170)
First step towards #5049.

Various transforms need to add a `var` statement at top of enclosing statement block.

e.g.:

```js
// Input
a ??= b;
```

```js
// Output
var _a;
(_a = a) !== null && _a !== void 0 ? _a : (a = b);
```

Each of these transforms previously maintained it's own stack and added `var` statements individually.

Share this functionality in a "common" utility transform which maintains a single stack to serve them all.
2024-09-30 03:53:00 +00:00
overlookmotel
b92fe8401a fix(transformer): NonEmptyStack::push write value before updating cursor (#6169)
`NonEmptyStack::push` was previously updating `cursor` before writing the value to stack. This could be UB if the type `T` is `Drop`, and writing the value panicked - as then `drop` would attempt to drop an uninitialized `T`.

I think `ptr::write` is infallible (can't panic), so it shouldn't matter. But *maybe* in debug mode it can panic if some invariant is broken (e.g. pointer not aligned). So play it safe and write the value first and update the cursor after.
2024-09-30 02:00:30 +00:00
Brandon Largeau
006f2cdbf9
fix(just): use powershell compatible env variable for doc command (#6168)
Hello,

I was following the guide
https://oxc.rs/docs/contribute/development.html and executed `just
ready` as said.
I got an error on Windows on the `doc` command because it sets the env
variable in a way that is not compatible with `powershell`.

I've used
[attributes](https://just.systems/man/en/attributes.html#attributes) to
fix the issue.
I never used `just` so I don't know if there's a better way to fix the
issue.
2024-09-30 09:59:27 +08:00
Boshen
1cee207050 refactor(minifier): some boilerplate work for PeepholeFoldConstants (#6054) 2024-09-29 15:22:12 +00:00
DonIsaac
82b8f217ab refactor(linter): add schemars and serde traits to AllowWarnDeny and RuleCategories (#6119) 2024-09-29 15:03:43 +00:00
overlookmotel
40bd919849 perf(transformer): faster parsing JSX pragmas from comments (#6151)
Parse JSX pragmas faster by:

1. Finding patterns with byte-by-byte iteration, with fast path for ASCII.
2. Checking for the `@jsx` prefix first before parsing the rest of the pragma.

These routines could be speeded up further by using unchecked slicing (unsafe code). But I've avoided that as the routines at present are quite complex, so hard to verify. The exception is `trim_end`, which is trivial to verify, so I have used unchecked slicing there.

The perf gain here is only ~0.5%, but we should split these routines out into a separate common crate and further optimize them, so that they can be used elsewhere in the codebase where we do string operations, which are often quite expensive.
2024-09-29 12:37:09 +00:00
renovate[bot]
646cd1d1ab
chore(deps): update npm packages (#6164)
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [express](http://expressjs.com/)
([source](https://redirect.github.com/expressjs/express)) | [`4.19.2` ->
`4.21.0`](https://renovatebot.com/diffs/npm/express/4.19.2/4.21.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/express/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/express/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/express/4.19.2/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/express/4.19.2/4.21.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [pnpm](https://pnpm.io)
([source](https://redirect.github.com/pnpm/pnpm)) | [`9.9.0` ->
`9.11.0`](https://renovatebot.com/diffs/npm/pnpm/9.9.0/9.11.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/pnpm/9.11.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/pnpm/9.11.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/pnpm/9.9.0/9.11.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/pnpm/9.9.0/9.11.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>expressjs/express (express)</summary>

###
[`v4.21.0`](https://redirect.github.com/expressjs/express/releases/tag/4.21.0)

[Compare
Source](https://redirect.github.com/expressjs/express/compare/4.20.0...4.21.0)

#### What's Changed

- Deprecate `"back"` magic string in redirects by
[@&#8203;blakeembrey](https://redirect.github.com/blakeembrey) in
[https://github.com/expressjs/express/pull/5935](https://redirect.github.com/expressjs/express/pull/5935)
- finalhandler@1.3.1 by
[@&#8203;wesleytodd](https://redirect.github.com/wesleytodd) in
[https://github.com/expressjs/express/pull/5954](https://redirect.github.com/expressjs/express/pull/5954)
- fix(deps): serve-static@1.16.2 by
[@&#8203;wesleytodd](https://redirect.github.com/wesleytodd) in
[https://github.com/expressjs/express/pull/5951](https://redirect.github.com/expressjs/express/pull/5951)
- Upgraded dependency qs to 6.13.0 to match qs in body-parser by
[@&#8203;agadzinski93](https://redirect.github.com/agadzinski93) in
[https://github.com/expressjs/express/pull/5946](https://redirect.github.com/expressjs/express/pull/5946)

#### New Contributors

- [@&#8203;agadzinski93](https://redirect.github.com/agadzinski93) made
their first contribution in
[https://github.com/expressjs/express/pull/5946](https://redirect.github.com/expressjs/express/pull/5946)

**Full Changelog**:
https://github.com/expressjs/express/compare/4.20.0...4.21.0

###
[`v4.20.0`](https://redirect.github.com/expressjs/express/blob/HEAD/History.md#4200--2024-09-10)

[Compare
Source](https://redirect.github.com/expressjs/express/compare/4.19.2...4.20.0)

\==========

-   deps: serve-static@0.16.0
    -   Remove link renderization in html while redirecting
-   deps: send@0.19.0
    -   Remove link renderization in html while redirecting
-   deps: body-parser@0.6.0
    -   add `depth` option to customize the depth level in the parser
- IMPORTANT: The default `depth` level for parsing URL-encoded data is
now `32` (previously was `Infinity`)
-   Remove link renderization in html while using `res.redirect`
-   deps: path-to-regexp@0.1.10
- Adds support for named matching groups in the routes using a regex
- Adds backtracking protection to parameters without regexes defined
-   deps: encodeurl@~2.0.0
- Removes encoding of `\`, `|`, and `^` to align better with URL spec
- Deprecate passing `options.maxAge` and `options.expires` to
`res.clearCookie`
- Will be ignored in v5, clearCookie will set a cookie with an expires
in the past to instruct clients to delete the cookie

</details>

<details>
<summary>pnpm/pnpm (pnpm)</summary>

###
[`v9.11.0`](https://redirect.github.com/pnpm/pnpm/compare/v9.10.0...v9.11.0)

[Compare
Source](https://redirect.github.com/pnpm/pnpm/compare/v9.10.0...v9.11.0)

###
[`v9.10.0`](https://redirect.github.com/pnpm/pnpm/releases/tag/v9.10.0):
pnpm 9.10

[Compare
Source](https://redirect.github.com/pnpm/pnpm/compare/v9.9.0...v9.10.0)

#### Minor Changes

- Support for a new CLI flag, `--exclude-peers`, added to the `list` and
`why` commands. When `--exclude-peers` is used, peer dependencies are
not printed in the results, but dependencies of peer dependencies are
still scanned
[#&#8203;8506](https://redirect.github.com/pnpm/pnpm/pull/8506).
- Added a new setting to `package.json` at
`pnpm.auditConfig.ignoreGhsas` for ignoring vulnerabilities by their
GHSA code
[#&#8203;6838](https://redirect.github.com/pnpm/pnpm/issues/6838).

    For instance:

    ```json
    {
      "pnpm": {
        "auditConfig": {
          "ignoreGhsas": [
            "GHSA-42xw-2xvc-qx8m",
            "GHSA-4w2v-q235-vp99",
            "GHSA-cph5-m8f7-6c5x",
            "GHSA-vh95-rmgr-6w4m"
          ]
        }
      }
    }
    ```

#### Patch Changes

-   Throw an exception if pnpm switches to the same version of itself.
-   Reduce memory usage during peer dependencies resolution.

#### Platinum Sponsors

<table>
  <tbody>
    <tr>
      <td align="center" valign="middle">
<a href="https://bit.dev/?utm_source=pnpm&utm_medium=release_notes"
target="_blank"><img src="https://pnpm.io/img/users/bit.svg"
width="80"></a>
      </td>
      <td align="center" valign="middle">
<a href="https://figma.com/?utm_source=pnpm&utm_medium=release_notes"
target="_blank"><img src="https://pnpm.io/img/users/figma.svg"
width="80"></a>
      </td>
    </tr>
  </tbody>
</table>

#### Gold Sponsors

<table>
  <tbody>
    <tr>
      <td align="center" valign="middle">
<a href="https://discord.com/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/discord.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/discord_light.svg" />
<img src="https://pnpm.io/img/users/discord.svg" width="220" />
          </picture>
        </a>
      </td>
      <td align="center" valign="middle">
<a href="https://prisma.io/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/prisma.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/prisma_light.svg" />
<img src="https://pnpm.io/img/users/prisma.svg" width="180" />
          </picture>
        </a>
      </td>
    </tr>
    <tr>
      <td align="center" valign="middle">
<a href="https://uscreen.de/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/uscreen.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/uscreen_light.svg" />
<img src="https://pnpm.io/img/users/uscreen.svg" width="180" />
          </picture>
        </a>
      </td>
      <td align="center" valign="middle">
<a
href="https://www.jetbrains.com/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/jetbrains.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/jetbrains.svg" />
<img src="https://pnpm.io/img/users/jetbrains.svg" width="180" />
          </picture>
        </a>
      </td>
    </tr>
    <tr>
      <td align="center" valign="middle">
<a href="https://nx.dev/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/nx.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/nx_light.svg" />
            <img src="https://pnpm.io/img/users/nx.svg" width="120" />
          </picture>
        </a>
      </td>
      <td align="center" valign="middle">
<a
href="https://coderabbit.ai/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/coderabbit.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/coderabbit_light.svg" />
<img src="https://pnpm.io/img/users/coderabbit.svg" width="220" />
          </picture>
        </a>
      </td>
    </tr>
  </tbody>
</table>

#### Our Silver Sponsors

<table>
  <tbody>
    <tr>
      <td align="center" valign="middle">
<a
href="https://leniolabs.com/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <img src="https://pnpm.io/img/users/leniolabs.jpg" width="80">
        </a>
      </td>
      <td align="center" valign="middle">
<a href="https://vercel.com/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/vercel.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/vercel_light.svg" />
<img src="https://pnpm.io/img/users/vercel.svg" width="180" />
          </picture>
        </a>
      </td>
    </tr>
    <tr>
      <td align="center" valign="middle">
<a href="https://depot.dev/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/depot.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/depot_light.svg" />
<img src="https://pnpm.io/img/users/depot.svg" width="200" />
          </picture>
        </a>
      </td>
      <td align="center" valign="middle">
<a href="https://moonrepo.dev/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/moonrepo.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/moonrepo_light.svg" />
<img src="https://pnpm.io/img/users/moonrepo.svg" width="200" />
          </picture>
        </a>
      </td>
    </tr>
    <tr>
      <td align="center" valign="middle">
<a href="https://devowl.io/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/devowlio.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/devowlio.svg" />
<img src="https://pnpm.io/img/users/devowlio.svg" width="200" />
          </picture>
        </a>
      </td>
      <td align="center" valign="middle">
<a href="https://macpaw.com/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/macpaw.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/macpaw_light.svg" />
<img src="https://pnpm.io/img/users/macpaw.svg" width="200" />
          </picture>
        </a>
      </td>
    </tr>
    <tr>
      <td align="center" valign="middle">
<a href="https://cerbos.dev/?utm_source=pnpm&utm_medium=release_notes"
target="_blank">
          <picture>
<source media="(prefers-color-scheme: light)"
srcset="https://pnpm.io/img/users/cerbos.svg" />
<source media="(prefers-color-scheme: dark)"
srcset="https://pnpm.io/img/users/cerbos_light.svg" />
<img src="https://pnpm.io/img/users/cerbos.svg" width="180" />
          </picture>
        </a>
      </td>
    </tr>
  </tbody>
</table>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 10am on monday" in timezone
Asia/Shanghai, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config
help](https://redirect.github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/oxc-project/oxc).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC45Ny4wIiwidXBkYXRlZEluVmVyIjoiMzguOTcuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-29 09:48:23 +00:00
oxc-bot
6c01fd7480
release(crates): v0.30.5 (#6163)
## [0.30.5] - 2024-09-29

### Features

- 15552ac napi/transform: Display semantic error (#6160) (Boshen)
- f50fdcd napi/transform: Make react refresh option take a boolean
(#6146) (Boshen)

### Bug Fixes

- f27d59f napi/transform: Remove confusing `jsx` option (#6159) (Boshen)
- bfd1988 transformer/react: Should not collect use-hooks if it's a
nested member expression (#6143) (Dunqing)

### Refactor

- ab187d1 codegen: Restrict visibility of internal methods (#6145)
(DonIsaac)
- 375bebe transformer: Improve parsing React pragmas (#6138)
(overlookmotel)
- 0836f6b transformer: Move parsing pragmas into TS transform (#6137)
(overlookmotel)
- 30424fa transformer: TS transforms only store options they need
(#6135) (overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-09-29 15:20:19 +08:00
Boshen
15552ac499 feat(napi/transform): display semantic error (#6160) 2024-09-29 04:17:26 +00:00
Boshen
f27d59f748 fix(napi/transform): remove confusing jsx option (#6159) 2024-09-29 04:09:53 +00:00
DonIsaac
ea908f742d refactor(linter): consolidate file loading logic (#6130)
# Human Description
Low on time, so this one is short.
- consolidate source file and partial loader logic into `loader` module. I have more plans for this.
- ~LSP no longer uses `VALID_EXTENSIONS`, so now `.d.ts` files (and the like) will be linted as well~ LSP does not respect `.gitignore` files, so this change was reverted.

# AI Description
## Refactor Loader and Partial Loader

This PR refactors the loader and partial loader functionality in the oxc_linter crate:

* Introduce a new `Loader` struct with methods for checking if a file can be loaded and loading file contents
* Move `partial_loader` module to `loader/partial_loader`
* Rename `JavaScriptSource` to `source.rs` and move it to the `loader` module
* Update `JavaScriptSource` to use `u32` for `start` offset instead of `usize`
* Refactor `IsolatedLintHandler` to use the new `Loader`
* Update imports and module references throughout the codebase

This change improves the organization of the loader-related code and provides a more unified interface for loading different file types.
2024-09-29 02:48:01 +00:00
dalaoshu
183739ff47
feat(linter): implement prefer-await-to-callbacks (#6153) 2024-09-28 22:30:30 -04:00
Boshen
f50fdcd0f9 feat(napi/transform): make react refresh option take a boolean (#6146) 2024-09-28 14:52:46 +00:00
Dunqing
bfd19882b0 fix(transformer/react): should not collect use-hooks if it's a nested member expression (#6143)
close: #6139

I still remember this logic and I call `get_first_object` for it intentionally 🥲
2024-09-28 14:38:14 +00:00
DonIsaac
ab187d1e22 refactor(codegen): restrict visibility of internal methods (#6145)
add `pub(crate)` to `Codegen` methods that should only be used within `oxc_codegen`
2024-09-28 14:33:42 +00:00
camchenry
be0030cdb8 fix(linter): allow whitespace control characters in no-control-regex (#6140)
- fixes https://github.com/oxc-project/oxc/issues/6136

The original eslint rule checks if chars start with `\u` or `\x`, but our character spans are currently busted and only report 1 char for chars like `\u{0a}`. I've made whitespace an exception to the rule, so we don't report `\x0a` currently, which is fine for now I think
2024-09-28 12:45:27 +00:00
dalaoshu
14ba263506
docs(linter): improve docs for eslint-plugin-import rules (#6131)
Related to #6050
2024-09-28 20:45:02 +08:00
overlookmotel
375bebea06 refactor(transformer): improve parsing React pragmas (#6138)
If comment starts with `@jsxRuntime`, it can't also start with `@jsxImportSource` etc. So bail out earlier.
2024-09-28 10:29:12 +00:00
overlookmotel
0836f6b57b refactor(transformer): move parsing pragmas into TS transform (#6137)
It's more natural for this code to live in TS transform.
2024-09-28 10:29:11 +00:00
overlookmotel
30424fab58 refactor(transformer): TS transforms only store options they need (#6135)
All TS transforms only need a subset of the options in `TypeScriptOptions` - mostly just a single `bool`. Store these specific options in the transforms, not the whole `TypeScriptOptions` object.

This makes the transformer types smaller, and also checking the option is cheaper as it doesn't involve going through a double-reference.

e.g. Accessing `only_remove_type_imports` option with Rust's deref sugar made explicit:

Before: `*(&*self.options).only_remove_type_imports`
After: `*self.only_remove_type_imports`
2024-09-28 09:40:09 +00:00
oxc-bot
73098a43ff
release(crates): v0.30.4 (#6134)
## [0.30.4] - 2024-09-28

### Bug Fixes

- 8582ae3 codegen: Missing parentheses if there is a pure comment before
a NewExpression as a ComputedMemberExpression's callee (#6105) (Dunqing)
- fd6798f parser: Remove unintended `pub Kind` (#6109) (Boshen)
- 6f98aad sourcemap: Align sourcemap type with Rollup (#6133) (Boshen)
- 64d4756 transformer: Fix debug assertion in `Stack` (#6106)
(overlookmotel)

### Performance

- 05852a0 codegen: Do not check whether there are annotation comments or
not if we don't preserve annotation comments (#6107) (Dunqing)

### Documentation

- 26a273a oxc-transform: Update README (Boshen)
- e2c5baf transformer: Fix formatting of README (#6111) (overlookmotel)

### Refactor

- 2090fce semantic: Fix lint warning in nightly (#6110) (overlookmotel)
- 7bc3988 transformer: Remove dead code (#6124) (overlookmotel)
- 07fe45b transformer: Exponentiation operator: convert to match (#6123)
(overlookmotel)
- 4387845 transformer: Share `TypeScriptOptions` with ref not `Rc`
(#6121) (overlookmotel)
- 09e41c2 transformer: Share `TransformCtx` with ref not `Rc` (#6118)
(overlookmotel)
- 58fd6eb transformer: Pre-allocate more stack space (#6095)
(overlookmotel)
- 9ac80bd transformer: Add wrapper around `NonNull` (#6115)
(overlookmotel)
- c50500e transformer: Move common stack functionality into
`StackCommon` trait (#6114) (overlookmotel)
- 9839059 transformer: Simplify `StackCapacity` trait (#6113)
(overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-09-28 13:08:44 +08:00
Boshen
a5037719ab
chore(napi/minify): no publish 2024-09-28 12:52:46 +08:00
Boshen
6f98aadc7f fix(sourcemap): align sourcemap type with Rollup (#6133)
closes #5578
2024-09-28 04:24:05 +00:00
camchenry
db751f0f8f refactor(linter): use regexp AST visitor in no-control-regex (#6129)
- closes https://github.com/oxc-project/oxc/issues/5416

Rewrites the `no-control-regex` rule to use a regular expression AST visitor instead of the `regex` crate and parsing by hand. This change simplifies the code and makes it easier to maintain.

One notable change in the snapshots is the printing of the control characters. Previously, we always printed from the source text. Now, we print a representation of the control character itself based on its numeric value. This resulted in the nonprintable chars being printed, which are invisible. The other reason for this change is that the spans output by the regex parser for unicode escapes do not match 1:1 when raw strings and escapes are involved. This resulted in goofy looking spans in the output:

```
  ⚠ eslint(no-control-regex): Unexpected control character: '*\\x'
   ╭─[no_control_regex.tsx:1:22]
 1 │ new RegExp('\\u{1111}*\\x1F', 'u')
   ·                      ────
   ╰────
```

Not sure where the bug lies there yet.
2024-09-28 04:18:09 +00:00
camchenry
3aa7e42826 refactor(linter): use RegExp AST visitor for no-hex-escape (#6117)
Updates the `no-hex-escape` to use the new standard `Visit` trait for visiting the RegExp AST, replacing the handwritten implementation in this rule. This makes it much simpler to maintain.
2024-09-27 23:24:59 +00:00
DonIsaac
e7e8eada69 fix(linter): false positive in no-return-assign (#6128) 2024-09-27 21:16:50 +00:00
Radu Baston
ae539af675
feat(linter): implement no-return-assign (#6108)
This PR implements the not-recomennded eslint rule `no-return-assign`
https://github.com/oxc-project/oxc/issues/479

---------

Co-authored-by: Cameron <cameron.clark@hey.com>
2024-09-27 16:52:18 -04:00
overlookmotel
7bc39884ca refactor(transformer): remove dead code (#6124)
This line calls a method which is a no-op. Remove it.
2024-09-27 19:21:56 +00:00
overlookmotel
07fe45b416 refactor(transformer): exponentiation operator: convert to match (#6123)
In exponentiation operator transform, the first branch handling `**` was "falling through" to also run the 2nd branch which handles `**=`. The first branch replaces `**` with `Math.pow`, so it can never match on the 2nd branch.

Convert it to a `match` instead, so it only executes one branch or the other.
2024-09-27 19:21:55 +00:00
overlookmotel
43878451da refactor(transformer): share TypeScriptOptions with ref not Rc (#6121)
Similar to #6118.

Share `TypeScriptOptions` between transforms as a plain `&` reference, rather than an `Rc`, to reduce setup/teardown time.

The code to parse pragmas from comments is moved into `Transformer::new`. This isn't the ideal place for it, but it means `TypeScriptOptions` can be shared with the existing `'ctx` lifetime, rather than having to have a 3rd lifetime `TypeScript<'a, 'ctx, 'options>`.
2024-09-27 18:32:33 +00:00
overlookmotel
09e41c2c26 refactor(transformer): share TransformCtx with ref not Rc (#6118)
Many transforms share `TransformCtx`. Currently it's shared with `Rc`, which has a cost as the `Rc` has to be cloned many times, and it also makes dropping `Transformer` more expensive.

The PR changes that to share it as a normal reference `&TransformCtx` instead.

This requires adding an inner `TransformerImpl`. `Transformer` is now just a facade which creates the `TransformCtx` and stores options. `Transformer::build_with_symbols_and_scopes` constructs `TransformerImpl` and runs the visitor on it.

Unlikely to have any perf impact on larger files, but for small files where setup/teardown is a larger % of the overall workload, it may help a little.
2024-09-27 18:07:54 +00:00
overlookmotel
58fd6eb905 refactor(transformer): pre-allocate more stack space (#6095)
Pre-allocate 16 bytes for stacks in transforms that use them. Allocators usually support minimum of 16 bytes for allocations anyway. Now that we're using `SparseStack`, allocating decent capacity is now cheap.
2024-09-27 16:48:38 +00:00
overlookmotel
9ac80bd2d2 refactor(transformer): add wrapper around NonNull (#6115)
Introduce a wrapper around `NonNull` which enables methods which exist on `std::ptr::NonNull` but are not yet stable in our MSRV. These methods remove a lot of boilerplate code from `Stack` and `NonEmptyStack` and make them easier to understand - which is important, since they contain so much unsafe code.
2024-09-27 16:48:37 +00:00
overlookmotel
c50500ec42 refactor(transformer): move common stack functionality into StackCommon trait (#6114)
`Stack` and `NonEmptyStack` contained a lot of the same logic. Move shared logic into a `StackCommon` trait that they both implement.

Also split out core allocation logic into non-generic free functions for faster compile time.
2024-09-27 16:48:36 +00:00
overlookmotel
98390594d2 refactor(transformer): simplify StackCapacity trait (#6113)
Pure refactor. Make it simpler.
2024-09-27 16:48:35 +00:00
Boshen
c519182359
feat(napi): add napi minifier (#6053) 2024-09-28 00:46:52 +08:00
Boshen
2da9a4d298
chore(regular_expression): rename visitor example to regex_visitor
closes #6116

To avoid name collision with parser/visitor.rs.
2024-09-28 00:33:11 +08:00
overlookmotel
509460b923
ci(transformer): run transformer tests under Miri (#6112)
Transformer tests include tests for unsafe code in `Stack` and
`NonEmptyStack`. Run these tests under Miri.
2024-09-27 17:27:28 +01:00
camchenry
9d5b44ad4c refactor(linter): use regex visitor in no-regex-spaces (#6063)
Similar to previous PRs, this refactors the `no-regex-spaces` rule to use the RegExp AST visitor, rather than the handwritten implementation in this rule. This makes the rule much simpler and easier to maintain in the future.
2024-09-27 15:58:54 +00:00
camchenry
0d44cf730a refactor(linter): use regex visitor in no-useless-escape (#6062)
This PR updates this rule to use the new RegExp AST visitor trait, instead of a custom implementation, which makes this rule much simpler and easier to maintain. The core logic is the same though, and the output should be identical.
2024-09-27 15:58:53 +00:00
camchenry
eeb8873982 refactor(linter): use regex visitor in no-empty-character-class (#6058)
Replaces rule-specific regex AST visitor method with the standard `oxc_regular_expression` one. This simplifies the code and also enables more capabilities (visiting more than just terms, but also character class contents, etc.)
2024-09-27 15:58:53 +00:00
overlookmotel
2090fce4bc refactor(semantic): fix lint warning in nightly (#6110)
Fix a lint warning which you only get on nightly (so appears when running Miri).
2024-09-27 13:45:16 +00:00