@rsvelte/compiler 0.7.13 → 0.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -65
- package/package.json +1 -1
- package/rsvelte_lint_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,86 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rsvelte/compiler
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
|
|
5
|
-
[
|
|
6
|
-
|
|
3
|
+
A high-performance Rust implementation of the [Svelte](https://svelte.dev) 5
|
|
4
|
+
compiler, shipped as WebAssembly. Part of the
|
|
5
|
+
[rsvelte](https://github.com/baseballyama/rsvelte) project — a port of the
|
|
6
|
+
official Svelte compiler to Rust, aiming for byte-identical output and a large
|
|
7
|
+
speedup over the JavaScript compiler.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
The whole compile pipeline — parse, analyze, transform — for client, SSR and
|
|
10
|
+
hydration, with output that matches the official compiler across the in-scope
|
|
11
|
+
test suite.
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
2. **Native rule engine** — a single shared DFS over the template AST that
|
|
14
|
-
dispatches to `Rule` hooks, porting the proven `vize_patina` structure.
|
|
13
|
+
> **⚠️ Early stage.** The API surface is stabilising. Output is verified
|
|
14
|
+
> byte-for-byte against the official compiler across the in-scope Svelte test
|
|
15
|
+
> suite, but treat this as experimental for production use.
|
|
15
16
|
|
|
16
|
-
##
|
|
17
|
+
## Install
|
|
17
18
|
|
|
18
19
|
```bash
|
|
19
|
-
|
|
20
|
+
npm install @rsvelte/compiler
|
|
21
|
+
# pnpm add @rsvelte/compiler
|
|
22
|
+
# yarn add @rsvelte/compiler
|
|
20
23
|
```
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
The package is a `wasm-pack` (`--target web`) module — the WebAssembly binary
|
|
26
|
+
ships with the package, so it runs anywhere WebAssembly does (modern browsers,
|
|
27
|
+
Node.js, Deno, Bun) with no native binaries and no `optionalDependencies`.
|
|
24
28
|
|
|
25
29
|
## Usage
|
|
26
30
|
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
```js
|
|
32
|
+
import init, {
|
|
33
|
+
parse_svelte,
|
|
34
|
+
compile_client,
|
|
35
|
+
compile_server,
|
|
36
|
+
version,
|
|
37
|
+
} from '@rsvelte/compiler';
|
|
38
|
+
|
|
39
|
+
// Initialise the WebAssembly module once before calling any export.
|
|
40
|
+
await init();
|
|
41
|
+
|
|
42
|
+
const source = `<h1>Hello {name}</h1>`;
|
|
43
|
+
|
|
44
|
+
// Compile for the client.
|
|
45
|
+
const client = compile_client(source, 'App');
|
|
46
|
+
console.log(client.js); // generated JavaScript
|
|
47
|
+
console.log(client.css); // scoped styles
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## Config (`rsvelte-lint.json`)
|
|
43
|
-
|
|
44
|
-
```json
|
|
45
|
-
{
|
|
46
|
-
"extends": ["recommended"],
|
|
47
|
-
"rules": {
|
|
48
|
-
"svelte/no-at-html-tags": "error",
|
|
49
|
-
"svelte/button-has-type": ["warn", { "submit": true, "reset": false }],
|
|
50
|
-
"svelte/no-restricted-html-elements": ["error", { "elements": ["marquee"] }]
|
|
51
|
-
},
|
|
52
|
-
"files": ["src/**/*.svelte"],
|
|
53
|
-
"ignores": ["**/generated/**"]
|
|
54
|
-
}
|
|
49
|
+
// Compile for SSR.
|
|
50
|
+
const server = compile_server(source, 'App');
|
|
51
|
+
|
|
52
|
+
// Parse to the Svelte AST (JSON string, same shape the official parser produces).
|
|
53
|
+
const ast = JSON.parse(parse_svelte(source).ast);
|
|
54
|
+
|
|
55
|
+
console.log(version()); // the rsvelte compiler version
|
|
55
56
|
```
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
a `[severity, ...options]` pair. `extends: ["none"]` starts from an empty
|
|
59
|
-
baseline.
|
|
58
|
+
## Why it is fast
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
- Written in Rust with a memory-efficient AST (`u32` spans, compact strings) and
|
|
61
|
+
direct phase-to-phase AST passing — no re-parsing between phases.
|
|
62
|
+
- Thread-safe, parallel parsing via [rayon](https://github.com/rayon-rs/rayon).
|
|
63
|
+
- Designed for integration into the [oxc](https://oxc.rs/) ecosystem.
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
`--print-eslint-config` to generate a flat-config snippet that turns the
|
|
65
|
-
native-owned `svelte/*` rules off in ESLint so each finding fires exactly once.
|
|
65
|
+
## Related packages
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
- [`@rsvelte/svelte2tsx`](https://www.npmjs.com/package/@rsvelte/svelte2tsx) — `.svelte` → TSX for type-checking.
|
|
68
|
+
- [`@rsvelte/svelte-check`](https://www.npmjs.com/package/@rsvelte/svelte-check) — a drop-in `svelte-check`.
|
|
69
|
+
- [`@rsvelte/vite-plugin-svelte`](https://www.npmjs.com/package/@rsvelte/vite-plugin-svelte) — the Vite plugin, backed by the Rust compiler.
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
`require-each-key`, `no-dupe-else-if-blocks`, `no-dupe-style-properties`,
|
|
71
|
-
`no-object-in-text-mustaches`. Opt-in (off by default, matching
|
|
72
|
-
eslint-plugin-svelte's `recommended: false`): `button-has-type`,
|
|
73
|
-
`no-restricted-html-elements`. Each is a 1:1 port of the corresponding
|
|
74
|
-
eslint-plugin-svelte rule and validated against that plugin's own fixtures by the
|
|
75
|
-
compat oracle (`tests/eslint_plugin_oracle.rs`). Run `--list-rules` to see
|
|
76
|
-
defaults.
|
|
71
|
+
## License
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
MIT
|
|
79
74
|
|
|
80
|
-
|
|
81
|
-
cargo test -p rsvelte_lint
|
|
82
|
-
cargo clippy -p rsvelte_lint --all-targets --all-features -- -D warnings
|
|
83
|
-
```
|
|
75
|
+
---
|
|
84
76
|
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
> **Maintainers:** `@rsvelte/compiler` is published from the wasm-pack output in
|
|
78
|
+
> the repo-root `pkg/` directory, not from this directory. See
|
|
79
|
+
> [`PUBLISHING.md`](./PUBLISHING.md) for how the version anchor and README
|
|
80
|
+
> overlay work.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@rsvelte/compiler",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Fast native Svelte linter built on the rsvelte compiler (validator wrap + native rule engine)",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.15",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"files": [
|
|
8
8
|
"rsvelte_lint_bg.wasm",
|
package/rsvelte_lint_bg.wasm
CHANGED
|
Binary file
|