oxc/wasm/parser
renovate[bot] 57d821b93c
chore(deps): update npm packages (#4092)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [pnpm](https://pnpm.io) ([source](https://togithub.com/pnpm/pnpm)) |
[`9.4.0` -> `9.5.0`](https://renovatebot.com/diffs/npm/pnpm/9.4.0/9.5.0)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/pnpm/9.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/pnpm/9.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/pnpm/9.4.0/9.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/pnpm/9.4.0/9.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [wasm-pack](https://togithub.com/rustwasm/wasm-pack) | [`^0.12.1` ->
`^0.13.0`](https://renovatebot.com/diffs/npm/wasm-pack/0.12.1/0.13.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/wasm-pack/0.13.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/wasm-pack/0.13.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/wasm-pack/0.12.1/0.13.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/wasm-pack/0.12.1/0.13.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

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

###
[`v9.5.0`](https://togithub.com/pnpm/pnpm/compare/v9.5.0-beta.3...v9.5.0)

[Compare Source](https://togithub.com/pnpm/pnpm/compare/v9.4.0...v9.5.0)

</details>

<details>
<summary>rustwasm/wasm-pack (wasm-pack)</summary>

###
[`v0.13.0`](https://togithub.com/rustwasm/wasm-pack/blob/HEAD/CHANGELOG.md#-0130)

[Compare
Source](https://togithub.com/rustwasm/wasm-pack/compare/v0.12.1...v0.13.0)

-   ###  Features

- **Add option to skip optimization with wasm-opt - [sisou],
[pull/1321]**

This feature introduces the `--no-opt` option to wasm-pack, providing a
significant improvement in build efficiency for projects requiring
multiple wasm-pack executions.

        [pull/1321]: https://togithub.com/rustwasm/wasm-pack/pull/1321

        [sisou]: https://togithub.com/sisou

- **Add support geckodriver for linux-aarch64 - [EstebanBorai],
[pull/1371]**

        Introduces support to download Geckodriver in Linux aarch64.

        [pull/1371]: https://togithub.com/rustwasm/wasm-pack/pull/1371

        [EstebanBorai]: https://togithub.com/EstebanBorai

- **Add wasm-opt linux aarch64 condition - [dkristia], [issue/1392],
[pull/1393]**

A linux aarch64 build for wasm-opt exists in the newest binaryen
versions.

[issue/1392]: https://togithub.com/rustwasm/wasm-pack/issues/1392

        [pull/1393]: https://togithub.com/rustwasm/wasm-pack/pull/1393

        [dkristia]: https://togithub.com/dkristia

-   ### 🤕 Fixes

- **Fix passing relative paths to cargo - [dfaust], [issue/704],
[issue/1156], [issue/1252], [pull/1331]**

When building a crate located in a sub-directory, relative paths, passed
as extra options to cargo (like `--target-dir`), are now handled
correctly.

        [issue/704]: https://togithub.com/rustwasm/wasm-pack/issues/704

[issue/1156]: https://togithub.com/rustwasm/wasm-pack/issues/1156

[issue/1252]: https://togithub.com/rustwasm/wasm-pack/issues/1252

        [pull/1331]: https://togithub.com/rustwasm/wasm-pack/pull/1331

        [dfaust]: https://togithub.com/dfaust

- **Rewrite wasm_target to use target-libdir - [daidoji], [issue/1342],
[pull/1343]**

Rewritten wasm_target to use target libdir from the rustc tool rather
than looking through sysroot. This is to accomodate non-rustup
installations.

[issue/1342]: https://togithub.com/rustwasm/wasm-pack/issues/1342

        [pull/1343]: https://togithub.com/rustwasm/wasm-pack/pull/1343

        [daidoji]: https://togithub.com/daidoji

- **Declare ES module in package.json - [gthb], [issue/1039],
[pull/1061]**

In bundler mode, generate package.json with "type": "module" and use the
"main" attribute instead of the "module" attribute.

This change makes the built ES module palatable to Node.js (when run
with --experimental-vm-modules --experimental-wasm-modules),
while it remains also palatable to webpack as illustrated in
[webpack/webpack#14313](https://togithub.com/webpack/webpack/issues/14313)
(where the pkg subfolder is generated with wasm-pack built with this
change).
This resolves the headache of using a wasm-pack-built package in a
library that one needs to both run directly in Node and include in a
webpack build.

[issue/1039]: https://togithub.com/rustwasm/wasm-pack/issues/1039

        [pull/1061]: https://togithub.com/rustwasm/wasm-pack/pull/1061

        [gthb]: https://togithub.com/gthb

- **Use new chromdriver endpoint and fix CI - [Myriad-Dreamin],
[kade-robertson], [issue/1315], [issue/1390], [pull/1325], [pull/1391]**

[issue/1315]: https://togithub.com/rustwasm/wasm-pack/issues/1315

[issue/1390]: https://togithub.com/rustwasm/wasm-pack/issues/1390

        [pull/1325]: https://togithub.com/rustwasm/wasm-pack/pull/1325

        [pull/1391]: https://togithub.com/rustwasm/wasm-pack/pull/1391

        [Myriad-Dreamin]: https://togithub.com/Myriad-Dreamin

        [kade-robertson]: https://togithub.com/kade-robertson

- **Add mingw support to npm package - [nathaniel-daniel], [issue/1354],
[issue/1359], [pull/1363]**

        Fixes the NPM package's platform detection for mingw.

[issue/1354]: https://togithub.com/rustwasm/wasm-pack/issues/1354

[issue/1359]: https://togithub.com/rustwasm/wasm-pack/issues/1359

        [pull/1363]: https://togithub.com/rustwasm/wasm-pack/pull/1363

        [nathaniel-daniel]: https://togithub.com/nathaniel-daniel

- **pkg-dir option for pack and publish commands - [danielronnkvist],
[issue/1369], [pull/1370]**

To be able to use these commands when the output directory option to the
build command isn't the default pkg.

[issue/1369]: https://togithub.com/rustwasm/wasm-pack/issues/1369

        [pull/1370]: https://togithub.com/rustwasm/wasm-pack/pull/1370

        [danielronnkvist]: https://togithub.com/danielronnkvist

- **Optimize out-dir display - [ahaoboy], [issue/1395], [pull/1396]**

        Optimize out-dir display.

        from:

`[INFO]: 📦 Your wasm pkg is ready to publish at
/root/code/fib-wasm/fib-rs/../fib-wasm/wasm.`

        to:

`[INFO]: 📦 Your wasm pkg is ready to publish at
/root/code/fib-wasm/fib-wasm/wasm.`

[issue/1395]: https://togithub.com/rustwasm/wasm-pack/issues/1395

        [pull/1396]: https://togithub.com/rustwasm/wasm-pack/pull/1396

        [ahaoboy]: https://togithub.com/ahaoboy

-   ### 🛠️ Maintenance
- **Fix error and warnings in install script - [lucashorward],
[issue/1159], [issue/1217], [issue/1283], [pull/1320]**

[issue/1159]: https://togithub.com/rustwasm/wasm-pack/issues/1159

[issue/1217]: https://togithub.com/rustwasm/wasm-pack/issues/1217

[issue/1283]: https://togithub.com/rustwasm/wasm-pack/issues/1283

        [pull/1320]: https://togithub.com/rustwasm/wasm-pack/pull/1320

        [lucashorward]: https://togithub.com/lucashorward

- **Bump follow-redirects from 1.14.9 to 1.15.6 in /npm - [dependabot],
[pull/1375]**

        [pull/1375]: https://togithub.com/rustwasm/wasm-pack/pull/1375

- **Bump rustls-webpki from 0.100.1 to 0.100.2 - [dependabot],
[pull/1323]**

        [pull/1341]: https://togithub.com/rustwasm/wasm-pack/pull/1341

- **Bump rustix from 0.37.20 to 0.37.25 - [dependabot], [pull/1341]**

        [pull/1323]: https://togithub.com/rustwasm/wasm-pack/pull/1323

        [dependabot]: https://togithub.com/apps/dependabot

- **Bump rustls from 0.21.9 to 0.21.11 - [dependabot], [pull/1385]**

        [pull/1385]: https://togithub.com/rustwasm/wasm-pack/pull/1385

        [dependabot]: https://togithub.com/apps/dependabot

- **Bump tar from 6.1.11 to 6.2.1 in /npm - [dependabot], [pull/1379]**

        [pull/1379]: https://togithub.com/rustwasm/wasm-pack/pull/1379

        [dependabot]: https://togithub.com/apps/dependabot

-   ### 📖 Documentation

    -   **Fix typo in README - [Lionelf329], \[pull/1368]**

        [pull/1268]: https://togithub.com/rustwasm/wasm-pack/pull/1368

        [Lionelf329]: https://togithub.com/Lionelf329

- **Add a description of build --target deno - [puxiao], [pull/1344]**

        [pull/1344]: https://togithub.com/rustwasm/wasm-pack/pull/1344

        [puxiao]: https://togithub.com/puxiao

    -   **Document deno in build target - [sigmaSd], [pull/1348]**

        [pull/1348]: https://togithub.com/rustwasm/wasm-pack/pull/1348

        [sigmaSd]: https://togithub.com/sigmaSd

- **Fix local navigation backing one step too far in docs - [SamuSoft],
[pull/1387]**

        [pull/1387]: https://togithub.com/rustwasm/wasm-pack/pull/1387

        [SamuSoft]: https://togithub.com/SamuSoft

- **Add --target web to quick start build command - [josephrocca],
[pull/1367]**

        [pull/1367]: https://togithub.com/rustwasm/wasm-pack/pull/1367

        [josephrocca]: https://togithub.com/josephrocca

</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 becomes conflicted, or you tick the
rebase/retry checkbox.

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

---

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

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/oxc-project/oxc).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjEuOSIsInVwZGF0ZWRJblZlciI6IjM3LjQyMS45IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-07-07 18:33:47 +00:00
..
src chore: improve some format by running cargo +nightly fmt 2024-06-19 00:48:30 +08:00
.gitignore feat: setup wasm parser for npm (#2221) 2024-01-30 21:40:10 +08:00
Cargo.toml chore: format wasm/parser/Cargo.toml 2024-03-14 17:25:53 +08:00
CHANGELOG.md chore: regenerate changelogs with commit id and author 2024-06-07 01:22:28 +08:00
package.json chore(deps): update npm packages (#4092) 2024-07-07 18:33:47 +00:00
pnpm-lock.yaml chore(deps): update npm packages (#4092) 2024-07-07 18:33:47 +00:00
README.md Publish @oxc-parser/wasm with web and node builds (#2916) 2024-04-08 15:47:02 +08:00
test-node.mjs Publish @oxc-parser/wasm with web and node builds (#2916) 2024-04-08 15:47:02 +08:00

About

Experimental wasm package for the oxc parser, with full TypeScript typings support.

This package is built with different wasm-pack's target builds:

  • wasm-pack build --target web for bundler (webpack / vite) consumption.
  • wasm-pack build --target nodejs for node.js

And exports the files as

"main": "./node/oxc_parser_wasm.js",
"browser": "./web/oxc_parser_wasm.js",
"types": "./node/oxc_parser_wasm.d.ts",

Checkout oxc-parser for usage in node.js via napi bindings.

Source code: https://github.com/oxc-project/oxc/tree/main/wasm/parser

Usage

import initWasm, { parseSync } from "@oxc-parser/wasm";

async function main() {
  await initWasm();

  const code = "let foo";
  const result = parseSync(code, { sourceFilename: "test.ts" });
  console.log(result);
}

main();

Notes

UTF8 vs UTF16 byte offsets

The span value returned from the ASTs and diagnostics is in UTF8 byte offsets. Converting to UTF16 byte offsets:

let sourceTextUtf8 = new TextEncoder().encode(sourceText);

const convertToUtf8 = (sourceTextUtf8, d) => {
  return new TextDecoder().decode(sourceTextUtf8.slice(0, d)).length;
}

const diagnostics = result.errors.map((d) => ({
    from: convertToUtf8(sourceTextUtf8, d.start),
    to: convertToUtf8(sourceTextUtf8, d.end),
    severity: d.severity.toLowerCase(),
    message: d.message,
}));

Vite

wasm-pack build --target web is used for the wasm build.

You may need something like https://github.com/nshen/vite-plugin-wasm-pack to get it working with vite, otherwise vite will load the wasm file as a HTML file causing a CompileError: WebAssembly.instantiate(): expected magic word error.