@rsvelte/compiler 0.2.0 → 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yuichiro Yamashita
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,182 +1,237 @@
1
1
  # rsvelte
2
2
 
3
- A high-performance Rust implementation of the Svelte compiler. Drop-in replacement for `svelte/compiler` with up to 100x performance improvement.
3
+ > **⚠️ Early Stage Project** — This project can compile a wide range of Svelte components and is fully passing the official compiler test suite, but it is still in an early phase of development. APIs, output, and behavior may change without notice. Not yet recommended for production use.
4
4
 
5
- ## Installation
5
+ A Rust port of the official Svelte 5 compiler. Targets **100% test compatibility** with `svelte/compiler` and is designed to slot into the [OXC](https://oxc.rs/) JavaScript/TypeScript toolchain.
6
+
7
+ ## Packages
8
+
9
+ rsvelte ships drop-in replacements for the main pieces of the Svelte toolchain. All packages are published under the `@rsvelte` scope on npm.
10
+
11
+ | Package | Drop-in for | Status |
12
+ |---|---|---|
13
+ | [`@rsvelte/compiler`](npm/compiler) | [`svelte/compiler`](https://svelte.dev/docs/svelte-compiler) | ✅ 100% test compat ([details](#compatibility)) |
14
+ | [`@rsvelte/svelte2tsx`](npm/svelte2tsx) | [`svelte2tsx`](https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx) | ✅ 245 / 245 fixtures |
15
+ | [`@rsvelte/svelte-check`](npm/svelte-check) | [`svelte-check`](https://github.com/sveltejs/language-tools/tree/master/packages/svelte-check) CLI | 🟡 In progress (walker + overlay + tsgo backend) |
16
+ | [`@rsvelte/vite-plugin-svelte`](https://github.com/baseballyama/vite-plugin-svelte/tree/rsvelte) | [`@sveltejs/vite-plugin-svelte`](https://github.com/sveltejs/vite-plugin-svelte) | 🟡 Fork that swaps in the Rust compiler |
17
+ | [`@rsvelte/vite-plugin-svelte-native`](npm/vite-plugin-svelte-native) | — | NAPI bindings consumed by the Vite plugin |
18
+
19
+ See [`docs/ecosystem-implementation-plan.md`](docs/ecosystem-implementation-plan.md) for the full ecosystem port plan.
20
+
21
+ ## Quick Start
22
+
23
+ ### Node.js
6
24
 
7
25
  ```bash
8
26
  npm install @rsvelte/compiler
9
27
  ```
10
28
 
11
- ## Usage
12
-
13
- ### Basic Usage
29
+ Use it as a drop-in replacement for `svelte/compiler`:
14
30
 
15
31
  ```js
16
- import { compile, parse, VERSION } from '@rsvelte/compiler';
32
+ import { compile, compileModule, parse } from '@rsvelte/compiler';
17
33
 
18
- const result = compile('<h1>Hello {name}!</h1>', {
19
- filename: 'App.svelte',
20
- generate: 'client',
34
+ const result = compile('<h1>Hello, {name}!</h1>', {
35
+ generate: 'client', // or 'server'
36
+ filename: 'App.svelte'
21
37
  });
22
38
 
23
39
  console.log(result.js.code);
40
+ console.log(result.css?.code);
41
+
42
+ // Compile a Svelte module (.svelte.js / .svelte.ts)
43
+ const moduleResult = compileModule('export const count = $state(0);', {
44
+ filename: 'counter.svelte.js'
45
+ });
46
+
47
+ // Parse into AST
48
+ const ast = parse('<h1>Hello</h1>', { modern: true });
24
49
  ```
25
50
 
26
- ### With Vite + vite-plugin-svelte
51
+ The API matches the official [`svelte/compiler`](https://svelte.dev/docs/svelte-compiler) — `compile`, `compileModule`, `parse`, and `VERSION` are all available.
52
+
53
+ ### Vite
54
+
55
+ Use [`@rsvelte/vite-plugin-svelte`](https://github.com/baseballyama/vite-plugin-svelte/tree/rsvelte) — a fork of `@sveltejs/vite-plugin-svelte` that swaps in the Rust compiler:
27
56
 
28
- Use `resolve.alias` to replace the Svelte compiler:
57
+ ```bash
58
+ npm install -D @rsvelte/vite-plugin-svelte
59
+ ```
29
60
 
30
61
  ```js
31
62
  // vite.config.js
63
+ import { svelte } from '@rsvelte/vite-plugin-svelte';
32
64
  import { defineConfig } from 'vite';
33
- import { svelte } from '@sveltejs/vite-plugin-svelte';
34
65
 
35
66
  export default defineConfig({
36
- resolve: {
37
- alias: {
38
- 'svelte/compiler': '@rsvelte/compiler',
39
- },
40
- },
41
- plugins: [svelte()],
67
+ plugins: [svelte()]
42
68
  });
43
69
  ```
44
70
 
45
- ## API
46
-
47
- ### `compile(source, options?)`
71
+ ### SvelteKit
48
72
 
49
- Compile a Svelte component to JavaScript.
73
+ SvelteKit imports `@sveltejs/vite-plugin-svelte` internally. Use pnpm `overrides` to redirect it to the rsvelte fork:
50
74
 
51
- ```js
52
- const result = compile(source, {
53
- dev: false,
54
- generate: 'client', // 'client' | 'server'
55
- filename: 'Component.svelte',
56
- css: 'external', // 'injected' | 'external'
57
- // ... see CompileOptions for all options
58
- });
75
+ ```bash
76
+ pnpm add -D @rsvelte/vite-plugin-svelte
77
+ ```
59
78
 
60
- // result.js.code - Generated JavaScript
61
- // result.js.map - Source map
62
- // result.css?.code - Generated CSS (if css: 'external')
63
- // result.css?.map - CSS source map
64
- // result.warnings - Compiler warnings
65
- // result.metadata.runes - Whether component uses runes
79
+ ```json
80
+ // package.json
81
+ {
82
+ "pnpm": {
83
+ "overrides": {
84
+ "@sveltejs/vite-plugin-svelte": "npm:@rsvelte/vite-plugin-svelte@^0.1.0"
85
+ }
86
+ }
87
+ }
66
88
  ```
67
89
 
68
- ### `compileModule(source, options?)`
90
+ Then run `pnpm install`. No changes to `vite.config.js` or `svelte.config.js` are needed.
69
91
 
70
- Compile a Svelte module (`.svelte.js` / `.svelte.ts`).
92
+ ### Rust
71
93
 
72
- ```js
73
- const result = compileModule(source, {
74
- dev: false,
75
- generate: 'client',
76
- filename: 'utils.svelte.js',
77
- });
94
+ ```rust
95
+ use rsvelte::{compile, CompileOptions};
96
+
97
+ let source = r#"<h1>Hello, {name}!</h1>"#;
98
+ let result = compile(source, CompileOptions::default()).unwrap();
99
+ println!("{}", result.js.code);
78
100
  ```
79
101
 
80
- ### `parse(source, options?)`
102
+ ## Highlights
81
103
 
82
- Parse a Svelte component into an AST.
104
+ - **3,341 / 3,341 in-scope tests passing** — every in-scope category of the official Svelte 5 compiler test suite at 100%
105
+ - **2.1x faster single-threaded, 15.8x faster multi-threaded** vs the official JS compiler
106
+ - **Drop-in replacement** — N-API bindings for seamless use with existing tools (Vite, SvelteKit, …)
107
+ - **WASM build** — runs in the browser (used by the docs playground)
108
+ - **Ecosystem port underway** — `svelte2tsx` already at 100%; `svelte-check` and `vite-plugin-svelte` shim in progress
83
109
 
84
- ```js
85
- const ast = parse('<h1>Hello</h1>', {
86
- modern: true, // Use modern AST format
87
- });
88
- ```
110
+ ## Performance
89
111
 
90
- ### `preprocess(source, preprocessors, options?)`
112
+ Compile benchmark across 3,654 real Svelte files (average of 3 runs):
91
113
 
92
- Preprocess a Svelte component (async).
114
+ | Runner | Time | Throughput | Speedup |
115
+ |---|---:|---:|---:|
116
+ | **JavaScript (`svelte/compiler`)** | 689 ms | 5,304 files/sec | 1.0× |
117
+ | **Rust (single-threaded)** | 333 ms | 10,986 files/sec | **2.1×** |
118
+ | **Rust (multi-threaded)** | 44 ms | 83,797 files/sec | **15.8×** |
93
119
 
94
- ```js
95
- const processed = await preprocess(source, [
96
- {
97
- markup({ content, filename }) {
98
- return { code: transformedContent };
99
- },
100
- script({ content, filename }) {
101
- return { code: transformedContent };
102
- },
103
- style({ content, filename }) {
104
- return { code: transformedContent };
105
- },
106
- },
107
- ], { filename: 'App.svelte' });
108
- ```
120
+ > Apple M1 Max · 3,654 files · average of 3 runs. Reproduce locally with `./scripts/bench.sh`.
109
121
 
110
- ### `print(ast, options?)`
122
+ A single-threaded **100× speedup** over the JS compiler is one of this project's explicit goals — current numbers are a snapshot, not a ceiling.
111
123
 
112
- Print an AST back to source code.
124
+ ## Compatibility
113
125
 
114
- ```js
115
- const ast = parse(source, { modern: true });
116
- const { code } = print(ast);
117
- ```
126
+ Current compatibility with the official Svelte compiler test suite:
118
127
 
119
- ### `parseCss(source)`
128
+ | Test Suite | Pass | Total | Status | Notes |
129
+ |---|---:|---:|---|---|
130
+ | Parser Modern | 22 | 22 | 100% | |
131
+ | Parser Legacy | 82 | 83 | 100% | 1 skipped (acorn vs OXC comment attachment) |
132
+ | Compiler Snapshot | 28 | 28 | 100% | |
133
+ | CSS | 179 | 179 | 100% | |
134
+ | Validator | 324 | 325 | 100% | 1 skipped (`error-mode-warn`) |
135
+ | Compiler Errors | 144 | 144 | 100% | |
136
+ | Runtime Runes | 865 | 865 | 100% | |
137
+ | Runtime Legacy | 1,202 | 1,202 | 100% | |
138
+ | Runtime Browser | 31 | 31 | 100% | |
139
+ | Hydration | 78 | 78 | 100% | |
140
+ | SSR | 82 | 82 | 100% | |
141
+ | Preprocess | 19 | 19 | 100% | |
142
+ | Print | 40 | 40 | 100% | |
143
+ | svelte2tsx | 245 | 245 | 100% | 2 skipped (`expected.error.json` error fixtures) |
144
+ | **Total (in-scope)** | **3,341** | **3,341** | **100%** | |
145
+ | Migrate | 0 | 76 | — | **Out of scope** — rsvelte is a Svelte 5 compiler port, not a 4→5 migrator |
146
+ | Sourcemaps | 0 | 0 | — | No fixtures yet |
120
147
 
121
- Parse CSS into an AST.
148
+ Re-run `pnpm run test-and-update` to refresh these numbers.
122
149
 
123
- ### `VERSION`
150
+ ## Goals
124
151
 
125
- The compiler version string.
152
+ 1. **100% test compatibility** with the official `svelte/compiler` test suite
153
+ 2. **100× single-threaded speedup** over the JS compiler via Rust + OXC
154
+ 3. **Drop-in replacement** — identical output, N-API bindings, no toolchain changes required
155
+ 4. **Ecosystem port** — pluggable into `svelte-check`, `vite-plugin-svelte`, and the wider Svelte tooling chain (see [`docs/ecosystem-implementation-plan.md`](docs/ecosystem-implementation-plan.md))
156
+ 5. **OXC integration** — serve as the foundation for Svelte support in OXC's linter, formatter, and bundler ecosystem
126
157
 
127
- ```js
128
- import { VERSION } from '@rsvelte/compiler';
129
- console.log(VERSION); // "0.1.0"
158
+ ## Architecture
159
+
160
+ The directory structure mirrors `submodules/svelte/packages/svelte/src/compiler/`:
161
+
162
+ ```
163
+ src/compiler/phases/
164
+ ├── 1_parse/ # Parsing (Svelte syntax → AST)
165
+ ├── 2_analyze/ # Analysis (scope tree, bindings, rune detection)
166
+ └── 3_transform/ # Code generation (AST → JS/CSS, client + SSR)
130
167
  ```
131
168
 
132
- ## Limitations
169
+ Key design decisions:
133
170
 
134
- ### Callback Options Not Supported
171
+ - Memory-efficient AST (u32 positions, `compact_str`)
172
+ - JavaScript parsing / codegen via OXC
173
+ - Direct AST passing between phases — no re-parsing
174
+ - Parallel processing with `rayon`
175
+ - No backward-compat shims for internal APIs — refactor freely
135
176
 
136
- The following options accept JavaScript callback functions and are **not currently supported** in rsvelte. These options will be silently ignored, and the default behavior will be used instead:
177
+ ## Development
137
178
 
138
- | Option | Description | Default Behavior |
139
- |--------|-------------|-----------------|
140
- | `cssHash` | Custom function to generate CSS hash for scoping | Uses the built-in hash function (same algorithm as the official Svelte compiler default) |
141
- | `warningFilter` | Function to filter compiler warnings | All warnings are included in the result |
179
+ ### Setup
142
180
 
143
- **Why?** rsvelte is implemented in Rust and compiled to a native binary. JavaScript callback functions cannot be directly executed inside the Rust runtime. Supporting these would require crossing the Rust-JavaScript boundary for each invocation, which would negate the performance benefits.
181
+ ```bash
182
+ git submodule update --init --recursive
183
+ git config core.hooksPath .githooks
184
+ pnpm install
185
+ pnpm run generate-fixtures # required before running tests
186
+ ```
144
187
 
145
- **Workaround for `warningFilter`:** Filter warnings from the result after compilation:
188
+ ### Build & test
146
189
 
147
- ```js
148
- const result = compile(source, options);
149
- const filteredWarnings = result.warnings.filter(
150
- (w) => w.code !== 'a11y-missing-attribute'
151
- );
190
+ ```bash
191
+ cargo build
192
+ cargo test # all tests
193
+ cargo test --release # recommended for full runs
194
+ cargo test --test parser_fixtures -- --nocapture # single suite
195
+ pnpm run compatibility-report # generate compatibility JSON
196
+ pnpm run test-and-update # refresh report + docs
197
+ ./scripts/bench.sh # JS vs Rust benchmark
152
198
  ```
153
199
 
154
- **Workaround for `cssHash`:** Currently no workaround. The default hash function is used. If you require a custom hash, please open an issue.
200
+ The pre-commit hook (`.githooks/pre-commit`) runs `cargo fmt` and `cargo clippy` automatically.
201
+
202
+ ### Docker (optional)
203
+
204
+ A `Dockerfile` and `docker-compose.yml` provide a reproducible toolchain (Rust nightly + Node 22 + pnpm):
205
+
206
+ ```bash
207
+ docker compose up -d
208
+ docker compose exec dev bash
209
+ docker compose exec dev cargo test
210
+ ```
211
+
212
+ VS Code Dev Containers ("Reopen in Container") also works.
213
+
214
+ ### Upgrading Svelte
215
+
216
+ ```bash
217
+ ./scripts/upgrade-svelte.sh 5.52.0
218
+ ```
155
219
 
156
- ### Not Yet Implemented
220
+ Updates the Svelte submodule, rebuilds, regenerates fixtures, and refreshes the compatibility report.
157
221
 
158
- | API | Status |
159
- |-----|--------|
160
- | `migrate()` | Not implemented - throws error |
161
- | `walk()` | Deprecated in Svelte 5 - throws error directing to estree-walker |
222
+ ## Known incompatibilities
162
223
 
163
- ## Platform Support
224
+ ### Parser Legacy: `javascript-comments` (1 test skipped)
164
225
 
165
- rsvelte ships native binaries for the following platforms:
226
+ The official compiler uses acorn and attaches comments to AST nodes as `leadingComments` / `trailingComments`. rsvelte uses OXC, where comments are provided as a separate list. This only affects the legacy AST format (Svelte 4 compatibility mode) and does **not** impact compiled output or runtime behavior.
166
227
 
167
- | Platform | Architecture | Package |
168
- |----------|-------------|---------|
169
- | macOS | ARM64 (Apple Silicon) | `@rsvelte/binding-darwin-arm64` |
170
- | macOS | x64 (Intel) | `@rsvelte/binding-darwin-x64` |
171
- | Linux | x64 | `@rsvelte/binding-linux-x64-gnu` |
172
- | Linux | ARM64 | `@rsvelte/binding-linux-arm64-gnu` |
173
- | Windows | x64 | `@rsvelte/binding-win32-x64-msvc` |
228
+ ### Validator: `error-mode-warn` (1 test skipped)
174
229
 
175
- Native binaries are installed automatically via `optionalDependencies`. If no native binary is available for your platform, an error will be thrown at runtime.
230
+ Tests an error-mode option not yet wired through rsvelte's diagnostic pipeline. Compiled output is unaffected.
176
231
 
177
- ## Svelte Compatibility
232
+ ### svelte2tsx: 2 error-fixture skips
178
233
 
179
- rsvelte targets compatibility with **Svelte 5** (`svelte/compiler`). It passes 100% of the official Svelte compiler test suite (3028/3028 tests).
234
+ Two svelte2tsx fixtures shaped around `expected.error.json` (error-path assertions) are skipped pending a structured error-fixture runner.
180
235
 
181
236
  ## License
182
237
 
package/package.json CHANGED
@@ -1,45 +1,31 @@
1
1
  {
2
2
  "name": "@rsvelte/compiler",
3
- "version": "0.2.0",
4
- "description": "A high-performance Rust implementation of the Svelte compiler - drop-in replacement",
5
- "author": "baseballyama",
6
3
  "type": "module",
7
- "main": "index.cjs",
8
- "module": "index.js",
9
- "types": "index.d.ts",
10
- "exports": {
11
- ".": {
12
- "types": "./index.d.ts",
13
- "import": "./index.js",
14
- "require": "./index.cjs"
15
- }
4
+ "description": "A high-performance Rust implementation of the Svelte compiler",
5
+ "version": "0.3.0",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/baseballyama/rsvelte.git"
16
10
  },
17
11
  "files": [
18
- "index.js",
19
- "index.cjs",
20
- "index.d.ts",
21
- "README.md"
12
+ "svelte_compiler_rust_bg.wasm",
13
+ "svelte_compiler_rust.js",
14
+ "svelte_compiler_rust.d.ts"
15
+ ],
16
+ "main": "svelte_compiler_rust.js",
17
+ "homepage": "https://github.com/baseballyama/rsvelte#readme",
18
+ "types": "svelte_compiler_rust.d.ts",
19
+ "sideEffects": [
20
+ "./snippets/*"
22
21
  ],
23
- "optionalDependencies": {
24
- "@rsvelte/binding-darwin-arm64": "0.2.0",
25
- "@rsvelte/binding-darwin-x64": "0.1.0",
26
- "@rsvelte/binding-linux-x64-gnu": "0.1.0",
27
- "@rsvelte/binding-linux-arm64-gnu": "0.1.0",
28
- "@rsvelte/binding-win32-x64-msvc": "0.1.0"
29
- },
30
22
  "keywords": [
31
23
  "svelte",
32
24
  "compiler",
33
25
  "rust",
34
- "napi",
35
- "performance"
26
+ "wasm"
36
27
  ],
37
- "license": "MIT",
38
- "repository": {
39
- "type": "git",
40
- "url": "https://github.com/baseballyama/svelte-compiler-rust"
41
- },
42
- "engines": {
43
- "node": ">= 18"
28
+ "bugs": {
29
+ "url": "https://github.com/baseballyama/rsvelte/issues"
44
30
  }
45
- }
31
+ }
@@ -0,0 +1,108 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Result of compiling a Svelte component.
6
+ */
7
+ export class CompileResultWasm {
8
+ private constructor();
9
+ free(): void;
10
+ [Symbol.dispose](): void;
11
+ readonly css: string;
12
+ readonly error: string | undefined;
13
+ readonly js: string;
14
+ readonly success: boolean;
15
+ }
16
+
17
+ /**
18
+ * Result of parsing a Svelte component.
19
+ */
20
+ export class ParseResultWasm {
21
+ private constructor();
22
+ free(): void;
23
+ [Symbol.dispose](): void;
24
+ readonly ast: string;
25
+ readonly error: string | undefined;
26
+ readonly success: boolean;
27
+ }
28
+
29
+ /**
30
+ * Compile a Svelte component to client-side JavaScript.
31
+ */
32
+ export function compile_client(source: string, name: string): CompileResultWasm;
33
+
34
+ /**
35
+ * Compile a Svelte component to server-side JavaScript.
36
+ */
37
+ export function compile_server(source: string, name: string): CompileResultWasm;
38
+
39
+ /**
40
+ * Initialize panic hook for better error messages in the browser console.
41
+ */
42
+ export function init(): void;
43
+
44
+ /**
45
+ * Parse a Svelte component and return the AST as JSON.
46
+ */
47
+ export function parse_svelte(source: string): ParseResultWasm;
48
+
49
+ /**
50
+ * Convert a Svelte component to TypeScript/TSX. Mirrors the napi `svelte2tsx`
51
+ * shape — `options_json` and the return value are JSON strings so the wasm
52
+ * boundary stays at primitive types and no bespoke `wasm_bindgen` struct is
53
+ * needed for every field of `Svelte2TsxResult`.
54
+ */
55
+ export function svelte2tsx(source: string, options_json: string): string;
56
+
57
+ /**
58
+ * Get the version of the compiler.
59
+ */
60
+ export function version(): string;
61
+
62
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
63
+
64
+ export interface InitOutput {
65
+ readonly memory: WebAssembly.Memory;
66
+ readonly __wbg_compileresultwasm_free: (a: number, b: number) => void;
67
+ readonly __wbg_parseresultwasm_free: (a: number, b: number) => void;
68
+ readonly compile_client: (a: number, b: number, c: number, d: number) => number;
69
+ readonly compile_server: (a: number, b: number, c: number, d: number) => number;
70
+ readonly compileresultwasm_css: (a: number) => [number, number];
71
+ readonly compileresultwasm_error: (a: number) => [number, number];
72
+ readonly compileresultwasm_js: (a: number) => [number, number];
73
+ readonly compileresultwasm_success: (a: number) => number;
74
+ readonly parse_svelte: (a: number, b: number) => number;
75
+ readonly parseresultwasm_ast: (a: number) => [number, number];
76
+ readonly parseresultwasm_error: (a: number) => [number, number];
77
+ readonly parseresultwasm_success: (a: number) => number;
78
+ readonly svelte2tsx: (a: number, b: number, c: number, d: number) => [number, number];
79
+ readonly version: () => [number, number];
80
+ readonly init: () => void;
81
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
82
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
83
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
84
+ readonly __wbindgen_externrefs: WebAssembly.Table;
85
+ readonly __wbindgen_start: () => void;
86
+ }
87
+
88
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
89
+
90
+ /**
91
+ * Instantiates the given `module`, which can either be bytes or
92
+ * a precompiled `WebAssembly.Module`.
93
+ *
94
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
95
+ *
96
+ * @returns {InitOutput}
97
+ */
98
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
99
+
100
+ /**
101
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
102
+ * for everything else, calls `WebAssembly.instantiate` directly.
103
+ *
104
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
105
+ *
106
+ * @returns {Promise<InitOutput>}
107
+ */
108
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,455 @@
1
+ /* @ts-self-types="./svelte_compiler_rust.d.ts" */
2
+
3
+ /**
4
+ * Result of compiling a Svelte component.
5
+ */
6
+ export class CompileResultWasm {
7
+ static __wrap(ptr) {
8
+ ptr = ptr >>> 0;
9
+ const obj = Object.create(CompileResultWasm.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ CompileResultWasmFinalization.register(obj, obj.__wbg_ptr, obj);
12
+ return obj;
13
+ }
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ CompileResultWasmFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_compileresultwasm_free(ptr, 0);
23
+ }
24
+ /**
25
+ * @returns {string}
26
+ */
27
+ get css() {
28
+ let deferred1_0;
29
+ let deferred1_1;
30
+ try {
31
+ const ret = wasm.compileresultwasm_css(this.__wbg_ptr);
32
+ deferred1_0 = ret[0];
33
+ deferred1_1 = ret[1];
34
+ return getStringFromWasm0(ret[0], ret[1]);
35
+ } finally {
36
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
37
+ }
38
+ }
39
+ /**
40
+ * @returns {string | undefined}
41
+ */
42
+ get error() {
43
+ const ret = wasm.compileresultwasm_error(this.__wbg_ptr);
44
+ let v1;
45
+ if (ret[0] !== 0) {
46
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
47
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
48
+ }
49
+ return v1;
50
+ }
51
+ /**
52
+ * @returns {string}
53
+ */
54
+ get js() {
55
+ let deferred1_0;
56
+ let deferred1_1;
57
+ try {
58
+ const ret = wasm.compileresultwasm_js(this.__wbg_ptr);
59
+ deferred1_0 = ret[0];
60
+ deferred1_1 = ret[1];
61
+ return getStringFromWasm0(ret[0], ret[1]);
62
+ } finally {
63
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
64
+ }
65
+ }
66
+ /**
67
+ * @returns {boolean}
68
+ */
69
+ get success() {
70
+ const ret = wasm.compileresultwasm_success(this.__wbg_ptr);
71
+ return ret !== 0;
72
+ }
73
+ }
74
+ if (Symbol.dispose) CompileResultWasm.prototype[Symbol.dispose] = CompileResultWasm.prototype.free;
75
+
76
+ /**
77
+ * Result of parsing a Svelte component.
78
+ */
79
+ export class ParseResultWasm {
80
+ static __wrap(ptr) {
81
+ ptr = ptr >>> 0;
82
+ const obj = Object.create(ParseResultWasm.prototype);
83
+ obj.__wbg_ptr = ptr;
84
+ ParseResultWasmFinalization.register(obj, obj.__wbg_ptr, obj);
85
+ return obj;
86
+ }
87
+ __destroy_into_raw() {
88
+ const ptr = this.__wbg_ptr;
89
+ this.__wbg_ptr = 0;
90
+ ParseResultWasmFinalization.unregister(this);
91
+ return ptr;
92
+ }
93
+ free() {
94
+ const ptr = this.__destroy_into_raw();
95
+ wasm.__wbg_parseresultwasm_free(ptr, 0);
96
+ }
97
+ /**
98
+ * @returns {string}
99
+ */
100
+ get ast() {
101
+ let deferred1_0;
102
+ let deferred1_1;
103
+ try {
104
+ const ret = wasm.parseresultwasm_ast(this.__wbg_ptr);
105
+ deferred1_0 = ret[0];
106
+ deferred1_1 = ret[1];
107
+ return getStringFromWasm0(ret[0], ret[1]);
108
+ } finally {
109
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
110
+ }
111
+ }
112
+ /**
113
+ * @returns {string | undefined}
114
+ */
115
+ get error() {
116
+ const ret = wasm.parseresultwasm_error(this.__wbg_ptr);
117
+ let v1;
118
+ if (ret[0] !== 0) {
119
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
120
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
121
+ }
122
+ return v1;
123
+ }
124
+ /**
125
+ * @returns {boolean}
126
+ */
127
+ get success() {
128
+ const ret = wasm.parseresultwasm_success(this.__wbg_ptr);
129
+ return ret !== 0;
130
+ }
131
+ }
132
+ if (Symbol.dispose) ParseResultWasm.prototype[Symbol.dispose] = ParseResultWasm.prototype.free;
133
+
134
+ /**
135
+ * Compile a Svelte component to client-side JavaScript.
136
+ * @param {string} source
137
+ * @param {string} name
138
+ * @returns {CompileResultWasm}
139
+ */
140
+ export function compile_client(source, name) {
141
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
142
+ const len0 = WASM_VECTOR_LEN;
143
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
144
+ const len1 = WASM_VECTOR_LEN;
145
+ const ret = wasm.compile_client(ptr0, len0, ptr1, len1);
146
+ return CompileResultWasm.__wrap(ret);
147
+ }
148
+
149
+ /**
150
+ * Compile a Svelte component to server-side JavaScript.
151
+ * @param {string} source
152
+ * @param {string} name
153
+ * @returns {CompileResultWasm}
154
+ */
155
+ export function compile_server(source, name) {
156
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
157
+ const len0 = WASM_VECTOR_LEN;
158
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
159
+ const len1 = WASM_VECTOR_LEN;
160
+ const ret = wasm.compile_server(ptr0, len0, ptr1, len1);
161
+ return CompileResultWasm.__wrap(ret);
162
+ }
163
+
164
+ /**
165
+ * Initialize panic hook for better error messages in the browser console.
166
+ */
167
+ export function init() {
168
+ wasm.init();
169
+ }
170
+
171
+ /**
172
+ * Parse a Svelte component and return the AST as JSON.
173
+ * @param {string} source
174
+ * @returns {ParseResultWasm}
175
+ */
176
+ export function parse_svelte(source) {
177
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
178
+ const len0 = WASM_VECTOR_LEN;
179
+ const ret = wasm.parse_svelte(ptr0, len0);
180
+ return ParseResultWasm.__wrap(ret);
181
+ }
182
+
183
+ /**
184
+ * Convert a Svelte component to TypeScript/TSX. Mirrors the napi `svelte2tsx`
185
+ * shape — `options_json` and the return value are JSON strings so the wasm
186
+ * boundary stays at primitive types and no bespoke `wasm_bindgen` struct is
187
+ * needed for every field of `Svelte2TsxResult`.
188
+ * @param {string} source
189
+ * @param {string} options_json
190
+ * @returns {string}
191
+ */
192
+ export function svelte2tsx(source, options_json) {
193
+ let deferred3_0;
194
+ let deferred3_1;
195
+ try {
196
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
197
+ const len0 = WASM_VECTOR_LEN;
198
+ const ptr1 = passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
199
+ const len1 = WASM_VECTOR_LEN;
200
+ const ret = wasm.svelte2tsx(ptr0, len0, ptr1, len1);
201
+ deferred3_0 = ret[0];
202
+ deferred3_1 = ret[1];
203
+ return getStringFromWasm0(ret[0], ret[1]);
204
+ } finally {
205
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Get the version of the compiler.
211
+ * @returns {string}
212
+ */
213
+ export function version() {
214
+ let deferred1_0;
215
+ let deferred1_1;
216
+ try {
217
+ const ret = wasm.version();
218
+ deferred1_0 = ret[0];
219
+ deferred1_1 = ret[1];
220
+ return getStringFromWasm0(ret[0], ret[1]);
221
+ } finally {
222
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
223
+ }
224
+ }
225
+
226
+ function __wbg_get_imports() {
227
+ const import0 = {
228
+ __proto__: null,
229
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
230
+ throw new Error(getStringFromWasm0(arg0, arg1));
231
+ },
232
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
233
+ let deferred0_0;
234
+ let deferred0_1;
235
+ try {
236
+ deferred0_0 = arg0;
237
+ deferred0_1 = arg1;
238
+ console.error(getStringFromWasm0(arg0, arg1));
239
+ } finally {
240
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
241
+ }
242
+ },
243
+ __wbg_new_8a6f238a6ece86ea: function() {
244
+ const ret = new Error();
245
+ return ret;
246
+ },
247
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
248
+ const ret = arg1.stack;
249
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
250
+ const len1 = WASM_VECTOR_LEN;
251
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
252
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
253
+ },
254
+ __wbindgen_init_externref_table: function() {
255
+ const table = wasm.__wbindgen_externrefs;
256
+ const offset = table.grow(4);
257
+ table.set(0, undefined);
258
+ table.set(offset + 0, undefined);
259
+ table.set(offset + 1, null);
260
+ table.set(offset + 2, true);
261
+ table.set(offset + 3, false);
262
+ },
263
+ };
264
+ return {
265
+ __proto__: null,
266
+ "./svelte_compiler_rust_bg.js": import0,
267
+ };
268
+ }
269
+
270
+ const CompileResultWasmFinalization = (typeof FinalizationRegistry === 'undefined')
271
+ ? { register: () => {}, unregister: () => {} }
272
+ : new FinalizationRegistry(ptr => wasm.__wbg_compileresultwasm_free(ptr >>> 0, 1));
273
+ const ParseResultWasmFinalization = (typeof FinalizationRegistry === 'undefined')
274
+ ? { register: () => {}, unregister: () => {} }
275
+ : new FinalizationRegistry(ptr => wasm.__wbg_parseresultwasm_free(ptr >>> 0, 1));
276
+
277
+ let cachedDataViewMemory0 = null;
278
+ function getDataViewMemory0() {
279
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
280
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
281
+ }
282
+ return cachedDataViewMemory0;
283
+ }
284
+
285
+ function getStringFromWasm0(ptr, len) {
286
+ ptr = ptr >>> 0;
287
+ return decodeText(ptr, len);
288
+ }
289
+
290
+ let cachedUint8ArrayMemory0 = null;
291
+ function getUint8ArrayMemory0() {
292
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
293
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
294
+ }
295
+ return cachedUint8ArrayMemory0;
296
+ }
297
+
298
+ function passStringToWasm0(arg, malloc, realloc) {
299
+ if (realloc === undefined) {
300
+ const buf = cachedTextEncoder.encode(arg);
301
+ const ptr = malloc(buf.length, 1) >>> 0;
302
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
303
+ WASM_VECTOR_LEN = buf.length;
304
+ return ptr;
305
+ }
306
+
307
+ let len = arg.length;
308
+ let ptr = malloc(len, 1) >>> 0;
309
+
310
+ const mem = getUint8ArrayMemory0();
311
+
312
+ let offset = 0;
313
+
314
+ for (; offset < len; offset++) {
315
+ const code = arg.charCodeAt(offset);
316
+ if (code > 0x7F) break;
317
+ mem[ptr + offset] = code;
318
+ }
319
+ if (offset !== len) {
320
+ if (offset !== 0) {
321
+ arg = arg.slice(offset);
322
+ }
323
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
324
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
325
+ const ret = cachedTextEncoder.encodeInto(arg, view);
326
+
327
+ offset += ret.written;
328
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
329
+ }
330
+
331
+ WASM_VECTOR_LEN = offset;
332
+ return ptr;
333
+ }
334
+
335
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
336
+ cachedTextDecoder.decode();
337
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
338
+ let numBytesDecoded = 0;
339
+ function decodeText(ptr, len) {
340
+ numBytesDecoded += len;
341
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
342
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
343
+ cachedTextDecoder.decode();
344
+ numBytesDecoded = len;
345
+ }
346
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
347
+ }
348
+
349
+ const cachedTextEncoder = new TextEncoder();
350
+
351
+ if (!('encodeInto' in cachedTextEncoder)) {
352
+ cachedTextEncoder.encodeInto = function (arg, view) {
353
+ const buf = cachedTextEncoder.encode(arg);
354
+ view.set(buf);
355
+ return {
356
+ read: arg.length,
357
+ written: buf.length
358
+ };
359
+ };
360
+ }
361
+
362
+ let WASM_VECTOR_LEN = 0;
363
+
364
+ let wasmModule, wasm;
365
+ function __wbg_finalize_init(instance, module) {
366
+ wasm = instance.exports;
367
+ wasmModule = module;
368
+ cachedDataViewMemory0 = null;
369
+ cachedUint8ArrayMemory0 = null;
370
+ wasm.__wbindgen_start();
371
+ return wasm;
372
+ }
373
+
374
+ async function __wbg_load(module, imports) {
375
+ if (typeof Response === 'function' && module instanceof Response) {
376
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
377
+ try {
378
+ return await WebAssembly.instantiateStreaming(module, imports);
379
+ } catch (e) {
380
+ const validResponse = module.ok && expectedResponseType(module.type);
381
+
382
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
383
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
384
+
385
+ } else { throw e; }
386
+ }
387
+ }
388
+
389
+ const bytes = await module.arrayBuffer();
390
+ return await WebAssembly.instantiate(bytes, imports);
391
+ } else {
392
+ const instance = await WebAssembly.instantiate(module, imports);
393
+
394
+ if (instance instanceof WebAssembly.Instance) {
395
+ return { instance, module };
396
+ } else {
397
+ return instance;
398
+ }
399
+ }
400
+
401
+ function expectedResponseType(type) {
402
+ switch (type) {
403
+ case 'basic': case 'cors': case 'default': return true;
404
+ }
405
+ return false;
406
+ }
407
+ }
408
+
409
+ function initSync(module) {
410
+ if (wasm !== undefined) return wasm;
411
+
412
+
413
+ if (module !== undefined) {
414
+ if (Object.getPrototypeOf(module) === Object.prototype) {
415
+ ({module} = module)
416
+ } else {
417
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
418
+ }
419
+ }
420
+
421
+ const imports = __wbg_get_imports();
422
+ if (!(module instanceof WebAssembly.Module)) {
423
+ module = new WebAssembly.Module(module);
424
+ }
425
+ const instance = new WebAssembly.Instance(module, imports);
426
+ return __wbg_finalize_init(instance, module);
427
+ }
428
+
429
+ async function __wbg_init(module_or_path) {
430
+ if (wasm !== undefined) return wasm;
431
+
432
+
433
+ if (module_or_path !== undefined) {
434
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
435
+ ({module_or_path} = module_or_path)
436
+ } else {
437
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
438
+ }
439
+ }
440
+
441
+ if (module_or_path === undefined) {
442
+ module_or_path = new URL('svelte_compiler_rust_bg.wasm', import.meta.url);
443
+ }
444
+ const imports = __wbg_get_imports();
445
+
446
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
447
+ module_or_path = fetch(module_or_path);
448
+ }
449
+
450
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
451
+
452
+ return __wbg_finalize_init(instance, module);
453
+ }
454
+
455
+ export { initSync, __wbg_init as default };
Binary file
package/index.cjs DELETED
@@ -1,79 +0,0 @@
1
- 'use strict';
2
-
3
- const { createRequire } = require('node:module');
4
-
5
- let nativeBinding = null;
6
- let loadError = null;
7
-
8
- const platform = process.platform;
9
- const arch = process.arch;
10
-
11
- const platformPackages = {
12
- 'darwin-arm64': '@rsvelte/binding-darwin-arm64',
13
- 'darwin-x64': '@rsvelte/binding-darwin-x64',
14
- 'linux-x64': '@rsvelte/binding-linux-x64-gnu',
15
- 'linux-arm64': '@rsvelte/binding-linux-arm64-gnu',
16
- 'win32-x64': '@rsvelte/binding-win32-x64-msvc',
17
- };
18
-
19
- const key = `${platform}-${arch}`;
20
- const packageName = platformPackages[key];
21
-
22
- if (packageName) {
23
- try {
24
- nativeBinding = require(packageName);
25
- } catch (e) {
26
- loadError = e;
27
- }
28
- } else {
29
- loadError = new Error(`Unsupported platform: ${key}`);
30
- }
31
-
32
- function getBinding() {
33
- if (nativeBinding) return nativeBinding;
34
- throw new Error(
35
- `rsvelte native binding not available for this platform. ` +
36
- `Ensure the correct @rsvelte/binding-* package is installed. ` +
37
- `Error: ${loadError?.message}`
38
- );
39
- }
40
-
41
- module.exports.compile = function compile(source, options = {}) {
42
- return getBinding().compile(source, options);
43
- };
44
-
45
- module.exports.compileModule = function compileModule(source, options = {}) {
46
- return getBinding().compileModule(source, options);
47
- };
48
-
49
- module.exports.parse = function parse(source, options = {}) {
50
- return getBinding().parse(source, options);
51
- };
52
-
53
- module.exports.preprocess = async function preprocess(source, preprocessor, options = {}) {
54
- return getBinding().preprocess(source, preprocessor, options);
55
- };
56
-
57
- module.exports.print = function print(ast, options = {}) {
58
- return getBinding().print(ast, options);
59
- };
60
-
61
- module.exports.parseCss = function parseCss(source) {
62
- return getBinding().parseCss(source);
63
- };
64
-
65
- module.exports.walk = function walk() {
66
- throw new Error(
67
- 'walk() is deprecated. Use estree-walker instead: https://github.com/Rich-Harris/estree-walker'
68
- );
69
- };
70
-
71
- module.exports.migrate = function migrate() {
72
- throw new Error('migrate() is not yet implemented in rsvelte.');
73
- };
74
-
75
- try {
76
- module.exports.VERSION = nativeBinding?.getVersion?.() ?? '0.2.0';
77
- } catch {
78
- module.exports.VERSION = '0.2.0';
79
- }
package/index.d.ts DELETED
@@ -1,140 +0,0 @@
1
- export interface CompileOptions {
2
- /** Enable dev mode */
3
- dev?: boolean;
4
- /** Generate client or server code */
5
- generate?: 'client' | 'server' | false;
6
- /** Component filename */
7
- filename?: string;
8
- /** Root directory */
9
- rootDir?: string;
10
- /** Component name */
11
- name?: string;
12
- /** Enable custom element mode */
13
- customElement?: boolean;
14
- /** Enable accessors */
15
- accessors?: boolean;
16
- /** HTML namespace */
17
- namespace?: 'html' | 'svg' | 'mathml';
18
- /** Enable immutable mode */
19
- immutable?: boolean;
20
- /** CSS mode */
21
- css?: 'injected' | 'external';
22
- /**
23
- * Custom CSS hash function.
24
- *
25
- * **Note:** Currently not supported in @rsvelte/compiler. The default hash function
26
- * will always be used. See README for details.
27
- */
28
- cssHash?: (args: { hash: (input: string) => string; css: string; name: string; filename: string | undefined }) => string;
29
- /** Preserve HTML comments */
30
- preserveComments?: boolean;
31
- /** Preserve whitespace */
32
- preserveWhitespace?: boolean;
33
- /** Enable runes mode */
34
- runes?: boolean;
35
- /** Disclose compiler version in output */
36
- discloseVersion?: boolean;
37
- /** Source map configuration */
38
- sourcemap?: object | string;
39
- /** Output JS filename */
40
- outputFilename?: string;
41
- /** Output CSS filename */
42
- cssOutputFilename?: string;
43
- /** Enable HMR */
44
- hmr?: boolean;
45
- /** Use modern AST */
46
- modernAst?: boolean;
47
- /**
48
- * Warning filter function.
49
- *
50
- * **Note:** Currently not supported in @rsvelte/compiler. All warnings will be
51
- * included. See README for details.
52
- */
53
- warningFilter?: (warning: Warning) => boolean;
54
- /** Experimental options */
55
- experimental?: {
56
- async?: boolean;
57
- };
58
- /** Compatibility options */
59
- compatibility?: {
60
- componentApi?: 4 | 5;
61
- };
62
- }
63
-
64
- export interface ModuleCompileOptions {
65
- dev?: boolean;
66
- generate?: 'client' | 'server' | false;
67
- filename?: string;
68
- rootDir?: string;
69
- }
70
-
71
- export interface Warning {
72
- code: string;
73
- message: string;
74
- start?: { line: number; column: number; character: number };
75
- end?: { line: number; column: number; character: number };
76
- }
77
-
78
- export interface CompileResult {
79
- js: { code: string; map: any };
80
- css: { code: string; map: any; hasGlobal: boolean } | null;
81
- warnings: Warning[];
82
- metadata: { runes: boolean };
83
- ast?: any;
84
- }
85
-
86
- export interface PrintResult {
87
- code: string;
88
- map?: any;
89
- }
90
-
91
- export interface Processed {
92
- code: string;
93
- map?: any;
94
- dependencies?: string[];
95
- }
96
-
97
- /**
98
- * Compile a Svelte component.
99
- */
100
- export function compile(source: string, options?: CompileOptions): CompileResult;
101
-
102
- /**
103
- * Compile a Svelte module (.svelte.js / .svelte.ts).
104
- */
105
- export function compileModule(source: string, options?: ModuleCompileOptions): CompileResult;
106
-
107
- /**
108
- * Parse a Svelte component into an AST.
109
- */
110
- export function parse(source: string, options?: { modern?: boolean; loose?: boolean }): any;
111
-
112
- /**
113
- * Parse CSS.
114
- */
115
- export function parseCss(source: string): any;
116
-
117
- /**
118
- * Preprocess a Svelte component.
119
- */
120
- export function preprocess(source: string, preprocessor: any | any[], options?: { filename?: string }): Promise<Processed>;
121
-
122
- /**
123
- * Print an AST back to source code.
124
- */
125
- export function print(ast: any, options?: any): PrintResult;
126
-
127
- /**
128
- * Compiler version.
129
- */
130
- export const VERSION: string;
131
-
132
- /**
133
- * @deprecated Use estree-walker instead.
134
- */
135
- export function walk(): never;
136
-
137
- /**
138
- * Not yet implemented in @rsvelte/compiler.
139
- */
140
- export function migrate(): never;
package/index.js DELETED
@@ -1,133 +0,0 @@
1
- // rsvelte - High-performance Svelte compiler
2
- // Native binding with WASM fallback
3
-
4
- import { createRequire } from 'node:module';
5
-
6
- let nativeBinding = null;
7
- let loadError = null;
8
-
9
- function loadNativeBinding() {
10
- const platform = process.platform;
11
- const arch = process.arch;
12
-
13
- const platformPackages = {
14
- 'darwin-arm64': '@rsvelte/binding-darwin-arm64',
15
- 'darwin-x64': '@rsvelte/binding-darwin-x64',
16
- 'linux-x64': '@rsvelte/binding-linux-x64-gnu',
17
- 'linux-arm64': '@rsvelte/binding-linux-arm64-gnu',
18
- 'win32-x64': '@rsvelte/binding-win32-x64-msvc',
19
- };
20
-
21
- const key = `${platform}-${arch}`;
22
- const packageName = platformPackages[key];
23
-
24
- if (!packageName) {
25
- loadError = new Error(`Unsupported platform: ${key}`);
26
- return null;
27
- }
28
-
29
- try {
30
- const require = createRequire(import.meta.url);
31
- return require(packageName);
32
- } catch (e) {
33
- loadError = e;
34
- return null;
35
- }
36
- }
37
-
38
- nativeBinding = loadNativeBinding();
39
-
40
- function getBinding() {
41
- if (nativeBinding) return nativeBinding;
42
- throw new Error(
43
- `rsvelte native binding not available for this platform. ` +
44
- `Ensure the correct @rsvelte/binding-* package is installed. ` +
45
- `Error: ${loadError?.message}`
46
- );
47
- }
48
-
49
- /**
50
- * Compile a Svelte component.
51
- * @param {string} source - Svelte component source code
52
- * @param {object} [options] - Compilation options
53
- * @returns {object} Compilation result with js, css, warnings, and metadata
54
- */
55
- export function compile(source, options = {}) {
56
- return getBinding().compile(source, options);
57
- }
58
-
59
- /**
60
- * Compile a Svelte module (.svelte.js/.svelte.ts).
61
- * @param {string} source - Module source code
62
- * @param {object} [options] - Compilation options
63
- * @returns {object} Compilation result
64
- */
65
- export function compileModule(source, options = {}) {
66
- return getBinding().compileModule(source, options);
67
- }
68
-
69
- /**
70
- * Parse a Svelte component into an AST.
71
- * @param {string} source - Svelte component source code
72
- * @param {object} [options] - Parse options
73
- * @returns {object} AST
74
- */
75
- export function parse(source, options = {}) {
76
- return getBinding().parse(source, options);
77
- }
78
-
79
- /**
80
- * Preprocess a Svelte component.
81
- * NOTE: This is an async function.
82
- * @param {string} source - Svelte component source code
83
- * @param {object|object[]} preprocessor - Preprocessor(s)
84
- * @param {object} [options] - Preprocess options
85
- * @returns {Promise<object>} Preprocessed result
86
- */
87
- export async function preprocess(source, preprocessor, options = {}) {
88
- return getBinding().preprocess(source, preprocessor, options);
89
- }
90
-
91
- /**
92
- * Print an AST back to source code.
93
- * @param {object} ast - Svelte AST
94
- * @param {object} [options] - Print options
95
- * @returns {object} Print result with code and map
96
- */
97
- export function print(ast, options = {}) {
98
- return getBinding().print(ast, options);
99
- }
100
-
101
- /**
102
- * Parse CSS.
103
- * @param {string} source - CSS source code
104
- * @returns {object} Parsed CSS AST
105
- */
106
- export function parseCss(source) {
107
- return getBinding().parseCss(source);
108
- }
109
-
110
- /**
111
- * @deprecated Use estree-walker instead.
112
- */
113
- export function walk() {
114
- throw new Error(
115
- 'walk() is deprecated. Use estree-walker instead: https://github.com/Rich-Harris/estree-walker'
116
- );
117
- }
118
-
119
- /**
120
- * Not yet implemented in rsvelte.
121
- */
122
- export function migrate() {
123
- throw new Error('migrate() is not yet implemented in rsvelte.');
124
- }
125
-
126
- /** Compiler version string. */
127
- let _version;
128
- try {
129
- _version = nativeBinding?.getVersion?.() ?? '0.2.0';
130
- } catch {
131
- _version = '0.2.0';
132
- }
133
- export const VERSION = _version;