@rsvelte/compiler 0.11.4 → 0.12.1

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 CHANGED
@@ -101,6 +101,46 @@ The exported names and JSON-string return values below are specific to this
101
101
  WASM package. They are deliberately not presented as `svelte/compiler`
102
102
  equivalents.
103
103
 
104
+ ### Rune modules and Web Workers
105
+
106
+ `compileModule(source, options)` compiles JavaScript rune modules such as
107
+ `state.svelte.js`. Like `compile`, it takes an options object and returns a JSON
108
+ string. It supports `generate`, `dev`, `filename`, `rootDir`, `experimental`, and
109
+ `warningFilter`. Preprocess TypeScript into JavaScript before calling it.
110
+
111
+ The same imports work in a browser module worker:
112
+
113
+ ```js
114
+ // compiler-worker.js (bundle as a module worker)
115
+ import init, { compile, compileModule } from '@rsvelte/compiler';
116
+
117
+ const ready = init();
118
+ self.onmessage = async ({ data: { source, filename, module } }) => {
119
+ await ready;
120
+ try {
121
+ const result = (module ? compileModule : compile)(source, {
122
+ filename,
123
+ generate: 'client',
124
+ });
125
+ self.postMessage({ result: JSON.parse(result) });
126
+ } catch (error) {
127
+ self.postMessage({ error: String(error) });
128
+ }
129
+ };
130
+ ```
131
+
132
+ Load this worker with `new Worker(new URL('./compiler-worker.js', import.meta.url),
133
+ { type: 'module' })`. Ensure your bundler serves the generated wasm asset; you can
134
+ also pass its URL to `init({ module_or_path: wasmUrl })` explicitly.
135
+
136
+ ### Playground tools
137
+
138
+ The default import and `@rsvelte/compiler/wasm` contain only compiler bindings.
139
+ They do not include lint or svelte2tsx. Applications needing those tools import
140
+ `@rsvelte/compiler/playground` and initialize that module separately. Its raw
141
+ binary is available at `@rsvelte/compiler/playground/wasm`. Both artifacts ship
142
+ in the npm package, but loading the default entry fetches only the compiler wasm.
143
+
104
144
  ## Compare CLI
105
145
 
106
146
  Projects that already have Svelte installed can compare official and rsvelte
package/package.json CHANGED
@@ -2,17 +2,18 @@
2
2
  "name": "@rsvelte/compiler",
3
3
  "type": "module",
4
4
  "description": "A high-performance Rust implementation of the Svelte compiler",
5
- "version": "0.11.4",
5
+ "version": "0.12.1",
6
6
  "license": "MIT",
7
7
  "files": [
8
- "rsvelte_lint_bg.wasm",
9
- "rsvelte_lint.js",
10
- "rsvelte_lint.d.ts",
8
+ "rsvelte_compiler_bg.wasm",
9
+ "rsvelte_compiler.js",
10
+ "rsvelte_compiler.d.ts",
11
11
  "bin/rsvelte.mjs",
12
- "lib/compare.mjs"
12
+ "lib/compare.mjs",
13
+ "playground"
13
14
  ],
14
- "main": "rsvelte_lint.js",
15
- "types": "rsvelte_lint.d.ts",
15
+ "main": "rsvelte_compiler.js",
16
+ "types": "rsvelte_compiler.d.ts",
16
17
  "sideEffects": [
17
18
  "./snippets/*"
18
19
  ],
@@ -43,10 +44,15 @@
43
44
  },
44
45
  "exports": {
45
46
  ".": {
46
- "types": "./rsvelte_lint.d.ts",
47
- "default": "./rsvelte_lint.js"
47
+ "types": "./rsvelte_compiler.d.ts",
48
+ "default": "./rsvelte_compiler.js"
48
49
  },
49
- "./wasm": "./rsvelte_lint_bg.wasm",
50
+ "./wasm": "./rsvelte_compiler_bg.wasm",
51
+ "./playground": {
52
+ "types": "./playground/rsvelte_lint.d.ts",
53
+ "default": "./playground/rsvelte_lint.js"
54
+ },
55
+ "./playground/wasm": "./playground/rsvelte_lint_bg.wasm",
50
56
  "./package.json": "./package.json",
51
57
  "./*": "./*"
52
58
  }
@@ -38,6 +38,11 @@ export class ParseResultWasm {
38
38
  */
39
39
  export function compile(source: string, options: any): string;
40
40
 
41
+ /**
42
+ * Compile a JavaScript rune module, returning the same JSON envelope as `compile`.
43
+ */
44
+ export function compileModule(source: string, options: any): string;
45
+
41
46
  /**
42
47
  * Compile a Svelte component to client-side JavaScript.
43
48
  */
@@ -100,9 +105,15 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
100
105
 
101
106
  export interface InitOutput {
102
107
  readonly memory: WebAssembly.Memory;
108
+ readonly lint: (a: number, b: number, c: number, d: number) => [number, number];
109
+ readonly lint_rules: () => [number, number];
110
+ readonly lint_version: () => [number, number];
111
+ readonly lint_with_config: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
112
+ readonly svelte2tsx: (a: number, b: number, c: number, d: number) => [number, number];
103
113
  readonly __wbg_compileresultwasm_free: (a: number, b: number) => void;
104
114
  readonly __wbg_parseresultwasm_free: (a: number, b: number) => void;
105
115
  readonly compile: (a: number, b: number, c: any) => [number, number, number, number];
116
+ readonly compileModule: (a: number, b: number, c: any) => [number, number, number, number];
106
117
  readonly compile_client: (a: number, b: number, c: number, d: number) => number;
107
118
  readonly compile_server: (a: number, b: number, c: number, d: number) => number;
108
119
  readonly compileresultwasm_css: (a: number) => [number, number];
@@ -110,15 +121,10 @@ export interface InitOutput {
110
121
  readonly compileresultwasm_js: (a: number) => [number, number];
111
122
  readonly compileresultwasm_success: (a: number) => number;
112
123
  readonly init: () => void;
113
- readonly lint: (a: number, b: number, c: number, d: number) => [number, number];
114
- readonly lint_rules: () => [number, number];
115
- readonly lint_version: () => [number, number];
116
- readonly lint_with_config: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
117
124
  readonly parse_svelte: (a: number, b: number) => number;
118
125
  readonly parseresultwasm_ast: (a: number) => [number, number];
119
126
  readonly parseresultwasm_error: (a: number) => [number, number];
120
127
  readonly parseresultwasm_success: (a: number) => number;
121
- readonly svelte2tsx: (a: number, b: number, c: number, d: number) => [number, number];
122
128
  readonly version: () => [number, number];
123
129
  readonly wasm_bindgen_de7100a3341595c3___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_: (a: number, b: number, c: number, d: number) => [number, number];
124
130
  readonly __wbindgen_malloc: (a: number, b: number) => number;
@@ -163,6 +163,33 @@ export function compile(source, options) {
163
163
  }
164
164
  }
165
165
 
166
+ /**
167
+ * Compile a JavaScript rune module, returning the same JSON envelope as `compile`.
168
+ * @param {string} source
169
+ * @param {any} options
170
+ * @returns {string}
171
+ */
172
+ export function compileModule(source, options) {
173
+ let deferred3_0;
174
+ let deferred3_1;
175
+ try {
176
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
177
+ const len0 = WASM_VECTOR_LEN;
178
+ const ret = wasm.compileModule(ptr0, len0, options);
179
+ var ptr2 = ret[0];
180
+ var len2 = ret[1];
181
+ if (ret[3]) {
182
+ ptr2 = 0; len2 = 0;
183
+ throw takeFromExternrefTable0(ret[2]);
184
+ }
185
+ deferred3_0 = ptr2;
186
+ deferred3_1 = len2;
187
+ return getStringFromWasm0(ptr2, len2);
188
+ } finally {
189
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
190
+ }
191
+ }
192
+
166
193
  /**
167
194
  * Compile a Svelte component to client-side JavaScript.
168
195
  * @param {string} source
@@ -350,6 +377,10 @@ function __wbg_get_imports() {
350
377
  const ret = typeof(v) === 'boolean' ? v : undefined;
351
378
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
352
379
  },
380
+ __wbg___wbindgen_is_falsy_a6dfe792ff282f10: function(arg0) {
381
+ const ret = !arg0;
382
+ return ret;
383
+ },
353
384
  __wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
354
385
  const ret = typeof(arg0) === 'function';
355
386
  return ret;
@@ -457,7 +488,7 @@ function __wbg_get_imports() {
457
488
  return ret;
458
489
  }, arguments); },
459
490
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
460
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [String], shim_idx: 6, ret: String, inner_ret: Some(String) }, mutable: false }) -> Externref`.
491
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [String], shim_idx: 182, ret: String, inner_ret: Some(String) }, mutable: false }) -> Externref`.
461
492
  const ret = makeClosure(arg0, arg1, wasm_bindgen_de7100a3341595c3___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_);
462
493
  return ret;
463
494
  },
@@ -0,0 +1,123 @@
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 with the full compile-options object.
31
+ *
32
+ * Supports the function-form compile options (issue #1680): the `parametric`
33
+ * function forms of `customElement`/`css`/`runes`, a `warningFilter` callback,
34
+ * a constant `cssHashOverride`, and a dynamic `cssHash` callback. Returns the
35
+ * compile result as a JSON string (`{ js, css, warnings, metadata }`);
36
+ * callbacks are input-only. Throws on a parse failure, an invalid option, or a
37
+ * `cssHash` callback that throws.
38
+ */
39
+ export function compile(source: string, options: any): string;
40
+
41
+ /**
42
+ * Compile a JavaScript rune module, returning the same JSON envelope as `compile`.
43
+ */
44
+ export function compileModule(source: string, options: any): string;
45
+
46
+ /**
47
+ * Compile a Svelte component to client-side JavaScript.
48
+ */
49
+ export function compile_client(source: string, name: string): CompileResultWasm;
50
+
51
+ /**
52
+ * Compile a Svelte component to server-side JavaScript.
53
+ */
54
+ export function compile_server(source: string, name: string): CompileResultWasm;
55
+
56
+ /**
57
+ * Initialize panic hook for better error messages in the browser console.
58
+ */
59
+ export function init(): void;
60
+
61
+ /**
62
+ * Parse a Svelte component and return the AST as JSON.
63
+ */
64
+ export function parse_svelte(source: string): ParseResultWasm;
65
+
66
+ /**
67
+ * Get the version of the compiler.
68
+ */
69
+ export function version(): string;
70
+
71
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
72
+
73
+ export interface InitOutput {
74
+ readonly memory: WebAssembly.Memory;
75
+ readonly __wbg_compileresultwasm_free: (a: number, b: number) => void;
76
+ readonly __wbg_parseresultwasm_free: (a: number, b: number) => void;
77
+ readonly compile: (a: number, b: number, c: any) => [number, number, number, number];
78
+ readonly compileModule: (a: number, b: number, c: any) => [number, number, number, number];
79
+ readonly compile_client: (a: number, b: number, c: number, d: number) => number;
80
+ readonly compile_server: (a: number, b: number, c: number, d: number) => number;
81
+ readonly compileresultwasm_css: (a: number) => [number, number];
82
+ readonly compileresultwasm_error: (a: number) => [number, number];
83
+ readonly compileresultwasm_js: (a: number) => [number, number];
84
+ readonly compileresultwasm_success: (a: number) => number;
85
+ readonly init: () => void;
86
+ readonly parse_svelte: (a: number, b: number) => number;
87
+ readonly parseresultwasm_ast: (a: number) => [number, number];
88
+ readonly parseresultwasm_error: (a: number) => [number, number];
89
+ readonly parseresultwasm_success: (a: number) => number;
90
+ readonly version: () => [number, number];
91
+ readonly wasm_bindgen_3be0ddcbc773b10___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_: (a: number, b: number, c: number, d: number) => [number, number];
92
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
93
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
94
+ readonly __wbindgen_exn_store: (a: number) => void;
95
+ readonly __externref_table_alloc: () => number;
96
+ readonly __wbindgen_externrefs: WebAssembly.Table;
97
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
98
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
99
+ readonly __externref_table_dealloc: (a: number) => void;
100
+ readonly __wbindgen_start: () => void;
101
+ }
102
+
103
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
104
+
105
+ /**
106
+ * Instantiates the given `module`, which can either be bytes or
107
+ * a precompiled `WebAssembly.Module`.
108
+ *
109
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
110
+ *
111
+ * @returns {InitOutput}
112
+ */
113
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
114
+
115
+ /**
116
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
117
+ * for everything else, calls `WebAssembly.instantiate` directly.
118
+ *
119
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
120
+ *
121
+ * @returns {Promise<InitOutput>}
122
+ */
123
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,656 @@
1
+ /* @ts-self-types="./rsvelte_compiler.d.ts" */
2
+
3
+ /**
4
+ * Result of compiling a Svelte component.
5
+ */
6
+ export class CompileResultWasm {
7
+ static __wrap(ptr) {
8
+ const obj = Object.create(CompileResultWasm.prototype);
9
+ obj.__wbg_ptr = ptr;
10
+ CompileResultWasmFinalization.register(obj, obj.__wbg_ptr, obj);
11
+ return obj;
12
+ }
13
+ __destroy_into_raw() {
14
+ const ptr = this.__wbg_ptr;
15
+ this.__wbg_ptr = 0;
16
+ CompileResultWasmFinalization.unregister(this);
17
+ return ptr;
18
+ }
19
+ free() {
20
+ const ptr = this.__destroy_into_raw();
21
+ wasm.__wbg_compileresultwasm_free(ptr, 0);
22
+ }
23
+ /**
24
+ * @returns {string}
25
+ */
26
+ get css() {
27
+ let deferred1_0;
28
+ let deferred1_1;
29
+ try {
30
+ const ret = wasm.compileresultwasm_css(this.__wbg_ptr);
31
+ deferred1_0 = ret[0];
32
+ deferred1_1 = ret[1];
33
+ return getStringFromWasm0(ret[0], ret[1]);
34
+ } finally {
35
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
36
+ }
37
+ }
38
+ /**
39
+ * @returns {string | undefined}
40
+ */
41
+ get error() {
42
+ const ret = wasm.compileresultwasm_error(this.__wbg_ptr);
43
+ let v1;
44
+ if (ret[0] !== 0) {
45
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
46
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
47
+ }
48
+ return v1;
49
+ }
50
+ /**
51
+ * @returns {string}
52
+ */
53
+ get js() {
54
+ let deferred1_0;
55
+ let deferred1_1;
56
+ try {
57
+ const ret = wasm.compileresultwasm_js(this.__wbg_ptr);
58
+ deferred1_0 = ret[0];
59
+ deferred1_1 = ret[1];
60
+ return getStringFromWasm0(ret[0], ret[1]);
61
+ } finally {
62
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
63
+ }
64
+ }
65
+ /**
66
+ * @returns {boolean}
67
+ */
68
+ get success() {
69
+ const ret = wasm.compileresultwasm_success(this.__wbg_ptr);
70
+ return ret !== 0;
71
+ }
72
+ }
73
+ if (Symbol.dispose) CompileResultWasm.prototype[Symbol.dispose] = CompileResultWasm.prototype.free;
74
+
75
+ /**
76
+ * Result of parsing a Svelte component.
77
+ */
78
+ export class ParseResultWasm {
79
+ static __wrap(ptr) {
80
+ const obj = Object.create(ParseResultWasm.prototype);
81
+ obj.__wbg_ptr = ptr;
82
+ ParseResultWasmFinalization.register(obj, obj.__wbg_ptr, obj);
83
+ return obj;
84
+ }
85
+ __destroy_into_raw() {
86
+ const ptr = this.__wbg_ptr;
87
+ this.__wbg_ptr = 0;
88
+ ParseResultWasmFinalization.unregister(this);
89
+ return ptr;
90
+ }
91
+ free() {
92
+ const ptr = this.__destroy_into_raw();
93
+ wasm.__wbg_parseresultwasm_free(ptr, 0);
94
+ }
95
+ /**
96
+ * @returns {string}
97
+ */
98
+ get ast() {
99
+ let deferred1_0;
100
+ let deferred1_1;
101
+ try {
102
+ const ret = wasm.parseresultwasm_ast(this.__wbg_ptr);
103
+ deferred1_0 = ret[0];
104
+ deferred1_1 = ret[1];
105
+ return getStringFromWasm0(ret[0], ret[1]);
106
+ } finally {
107
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
108
+ }
109
+ }
110
+ /**
111
+ * @returns {string | undefined}
112
+ */
113
+ get error() {
114
+ const ret = wasm.parseresultwasm_error(this.__wbg_ptr);
115
+ let v1;
116
+ if (ret[0] !== 0) {
117
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
118
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
119
+ }
120
+ return v1;
121
+ }
122
+ /**
123
+ * @returns {boolean}
124
+ */
125
+ get success() {
126
+ const ret = wasm.parseresultwasm_success(this.__wbg_ptr);
127
+ return ret !== 0;
128
+ }
129
+ }
130
+ if (Symbol.dispose) ParseResultWasm.prototype[Symbol.dispose] = ParseResultWasm.prototype.free;
131
+
132
+ /**
133
+ * Compile a Svelte component with the full compile-options object.
134
+ *
135
+ * Supports the function-form compile options (issue #1680): the `parametric`
136
+ * function forms of `customElement`/`css`/`runes`, a `warningFilter` callback,
137
+ * a constant `cssHashOverride`, and a dynamic `cssHash` callback. Returns the
138
+ * compile result as a JSON string (`{ js, css, warnings, metadata }`);
139
+ * callbacks are input-only. Throws on a parse failure, an invalid option, or a
140
+ * `cssHash` callback that throws.
141
+ * @param {string} source
142
+ * @param {any} options
143
+ * @returns {string}
144
+ */
145
+ export function compile(source, options) {
146
+ let deferred3_0;
147
+ let deferred3_1;
148
+ try {
149
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
150
+ const len0 = WASM_VECTOR_LEN;
151
+ const ret = wasm.compile(ptr0, len0, options);
152
+ var ptr2 = ret[0];
153
+ var len2 = ret[1];
154
+ if (ret[3]) {
155
+ ptr2 = 0; len2 = 0;
156
+ throw takeFromExternrefTable0(ret[2]);
157
+ }
158
+ deferred3_0 = ptr2;
159
+ deferred3_1 = len2;
160
+ return getStringFromWasm0(ptr2, len2);
161
+ } finally {
162
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Compile a JavaScript rune module, returning the same JSON envelope as `compile`.
168
+ * @param {string} source
169
+ * @param {any} options
170
+ * @returns {string}
171
+ */
172
+ export function compileModule(source, options) {
173
+ let deferred3_0;
174
+ let deferred3_1;
175
+ try {
176
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
177
+ const len0 = WASM_VECTOR_LEN;
178
+ const ret = wasm.compileModule(ptr0, len0, options);
179
+ var ptr2 = ret[0];
180
+ var len2 = ret[1];
181
+ if (ret[3]) {
182
+ ptr2 = 0; len2 = 0;
183
+ throw takeFromExternrefTable0(ret[2]);
184
+ }
185
+ deferred3_0 = ptr2;
186
+ deferred3_1 = len2;
187
+ return getStringFromWasm0(ptr2, len2);
188
+ } finally {
189
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Compile a Svelte component to client-side JavaScript.
195
+ * @param {string} source
196
+ * @param {string} name
197
+ * @returns {CompileResultWasm}
198
+ */
199
+ export function compile_client(source, name) {
200
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
201
+ const len0 = WASM_VECTOR_LEN;
202
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
203
+ const len1 = WASM_VECTOR_LEN;
204
+ const ret = wasm.compile_client(ptr0, len0, ptr1, len1);
205
+ return CompileResultWasm.__wrap(ret);
206
+ }
207
+
208
+ /**
209
+ * Compile a Svelte component to server-side JavaScript.
210
+ * @param {string} source
211
+ * @param {string} name
212
+ * @returns {CompileResultWasm}
213
+ */
214
+ export function compile_server(source, name) {
215
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
216
+ const len0 = WASM_VECTOR_LEN;
217
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
218
+ const len1 = WASM_VECTOR_LEN;
219
+ const ret = wasm.compile_server(ptr0, len0, ptr1, len1);
220
+ return CompileResultWasm.__wrap(ret);
221
+ }
222
+
223
+ /**
224
+ * Initialize panic hook for better error messages in the browser console.
225
+ */
226
+ export function init() {
227
+ wasm.init();
228
+ }
229
+
230
+ /**
231
+ * Parse a Svelte component and return the AST as JSON.
232
+ * @param {string} source
233
+ * @returns {ParseResultWasm}
234
+ */
235
+ export function parse_svelte(source) {
236
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
237
+ const len0 = WASM_VECTOR_LEN;
238
+ const ret = wasm.parse_svelte(ptr0, len0);
239
+ return ParseResultWasm.__wrap(ret);
240
+ }
241
+
242
+ /**
243
+ * Get the version of the compiler.
244
+ * @returns {string}
245
+ */
246
+ export function version() {
247
+ let deferred1_0;
248
+ let deferred1_1;
249
+ try {
250
+ const ret = wasm.version();
251
+ deferred1_0 = ret[0];
252
+ deferred1_1 = ret[1];
253
+ return getStringFromWasm0(ret[0], ret[1]);
254
+ } finally {
255
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
256
+ }
257
+ }
258
+ function __wbg_get_imports() {
259
+ const import0 = {
260
+ __proto__: null,
261
+ __wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
262
+ const v = arg0;
263
+ const ret = typeof(v) === 'boolean' ? v : undefined;
264
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
265
+ },
266
+ __wbg___wbindgen_is_falsy_a6dfe792ff282f10: function(arg0) {
267
+ const ret = !arg0;
268
+ return ret;
269
+ },
270
+ __wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
271
+ const ret = typeof(arg0) === 'function';
272
+ return ret;
273
+ },
274
+ __wbg___wbindgen_is_null_ea9085d691f535d3: function(arg0) {
275
+ const ret = arg0 === null;
276
+ return ret;
277
+ },
278
+ __wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
279
+ const val = arg0;
280
+ const ret = typeof(val) === 'object' && val !== null;
281
+ return ret;
282
+ },
283
+ __wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
284
+ const ret = arg0 === undefined;
285
+ return ret;
286
+ },
287
+ __wbg___wbindgen_number_get_394265ed1e1b84ee: function(arg0, arg1) {
288
+ const obj = arg1;
289
+ const ret = typeof(obj) === 'number' ? obj : undefined;
290
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
291
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
292
+ },
293
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
294
+ const obj = arg1;
295
+ const ret = typeof(obj) === 'string' ? obj : undefined;
296
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
297
+ var len1 = WASM_VECTOR_LEN;
298
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
299
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
300
+ },
301
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
302
+ throw new Error(getStringFromWasm0(arg0, arg1));
303
+ },
304
+ __wbg__wbg_cb_unref_fffb441def202758: function(arg0) {
305
+ arg0._wbg_cb_unref();
306
+ },
307
+ __wbg_call_a6e5c5dce5018821: function() { return handleError(function (arg0, arg1, arg2) {
308
+ const ret = arg0.call(arg1, arg2);
309
+ return ret;
310
+ }, arguments); },
311
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
312
+ let deferred0_0;
313
+ let deferred0_1;
314
+ try {
315
+ deferred0_0 = arg0;
316
+ deferred0_1 = arg1;
317
+ console.error(getStringFromWasm0(arg0, arg1));
318
+ } finally {
319
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
320
+ }
321
+ },
322
+ __wbg_get_78f252d074a84d0b: function() { return handleError(function (arg0, arg1) {
323
+ const ret = Reflect.get(arg0, arg1);
324
+ return ret;
325
+ }, arguments); },
326
+ __wbg_get_unchecked_6e0ad6d2a41b06f6: function(arg0, arg1) {
327
+ const ret = arg0[arg1 >>> 0];
328
+ return ret;
329
+ },
330
+ __wbg_isArray_0677c962b281d01a: function(arg0) {
331
+ const ret = Array.isArray(arg0);
332
+ return ret;
333
+ },
334
+ __wbg_keys_58421f8f96795607: function(arg0) {
335
+ const ret = Object.keys(arg0);
336
+ return ret;
337
+ },
338
+ __wbg_length_370319915dc99107: function(arg0) {
339
+ const ret = arg0.length;
340
+ return ret;
341
+ },
342
+ __wbg_new_227d7c05414eb861: function() {
343
+ const ret = new Error();
344
+ return ret;
345
+ },
346
+ __wbg_new_b667d279fd5aa943: function(arg0, arg1) {
347
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
348
+ return ret;
349
+ },
350
+ __wbg_new_da52cf8fe3429cb2: function() {
351
+ const ret = new Object();
352
+ return ret;
353
+ },
354
+ __wbg_parse_1c0d8a8656d7e016: function() { return handleError(function (arg0, arg1) {
355
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
356
+ return ret;
357
+ }, arguments); },
358
+ __wbg_set_8535240470bf2500: function() { return handleError(function (arg0, arg1, arg2) {
359
+ const ret = Reflect.set(arg0, arg1, arg2);
360
+ return ret;
361
+ }, arguments); },
362
+ __wbg_set_name_3bbc583faefa4193: function(arg0, arg1, arg2) {
363
+ arg0.name = getStringFromWasm0(arg1, arg2);
364
+ },
365
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
366
+ const ret = arg1.stack;
367
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
368
+ const len1 = WASM_VECTOR_LEN;
369
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
370
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
371
+ },
372
+ __wbg_stringify_b54333f60f1e4dad: function() { return handleError(function (arg0) {
373
+ const ret = JSON.stringify(arg0);
374
+ return ret;
375
+ }, arguments); },
376
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
377
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [String], shim_idx: 264, ret: String, inner_ret: Some(String) }, mutable: false }) -> Externref`.
378
+ const ret = makeClosure(arg0, arg1, wasm_bindgen_3be0ddcbc773b10___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_);
379
+ return ret;
380
+ },
381
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
382
+ // Cast intrinsic for `Ref(String) -> Externref`.
383
+ const ret = getStringFromWasm0(arg0, arg1);
384
+ return ret;
385
+ },
386
+ __wbindgen_init_externref_table: function() {
387
+ const table = wasm.__wbindgen_externrefs;
388
+ const offset = table.grow(4);
389
+ table.set(0, undefined);
390
+ table.set(offset + 0, undefined);
391
+ table.set(offset + 1, null);
392
+ table.set(offset + 2, true);
393
+ table.set(offset + 3, false);
394
+ },
395
+ };
396
+ return {
397
+ __proto__: null,
398
+ "./rsvelte_compiler_bg.js": import0,
399
+ };
400
+ }
401
+
402
+ function wasm_bindgen_3be0ddcbc773b10___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_(arg0, arg1, arg2) {
403
+ let deferred2_0;
404
+ let deferred2_1;
405
+ try {
406
+ const ptr0 = passStringToWasm0(arg2, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
407
+ const len0 = WASM_VECTOR_LEN;
408
+ const ret = wasm.wasm_bindgen_3be0ddcbc773b10___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_(arg0, arg1, ptr0, len0);
409
+ deferred2_0 = ret[0];
410
+ deferred2_1 = ret[1];
411
+ return getStringFromWasm0(ret[0], ret[1]);
412
+ } finally {
413
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
414
+ }
415
+ }
416
+
417
+ const CompileResultWasmFinalization = (typeof FinalizationRegistry === 'undefined')
418
+ ? { register: () => {}, unregister: () => {} }
419
+ : new FinalizationRegistry(ptr => wasm.__wbg_compileresultwasm_free(ptr, 1));
420
+ const ParseResultWasmFinalization = (typeof FinalizationRegistry === 'undefined')
421
+ ? { register: () => {}, unregister: () => {} }
422
+ : new FinalizationRegistry(ptr => wasm.__wbg_parseresultwasm_free(ptr, 1));
423
+
424
+ function addToExternrefTable0(obj) {
425
+ const idx = wasm.__externref_table_alloc();
426
+ wasm.__wbindgen_externrefs.set(idx, obj);
427
+ return idx;
428
+ }
429
+
430
+ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
431
+ ? { register: () => {}, unregister: () => {} }
432
+ : new FinalizationRegistry(state => wasm.__wbindgen_destroy_closure(state.a, state.b));
433
+
434
+ let cachedDataViewMemory0 = null;
435
+ function getDataViewMemory0() {
436
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
437
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
438
+ }
439
+ return cachedDataViewMemory0;
440
+ }
441
+
442
+ function getStringFromWasm0(ptr, len) {
443
+ return decodeText(ptr >>> 0, len);
444
+ }
445
+
446
+ let cachedUint8ArrayMemory0 = null;
447
+ function getUint8ArrayMemory0() {
448
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
449
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
450
+ }
451
+ return cachedUint8ArrayMemory0;
452
+ }
453
+
454
+ function handleError(f, args) {
455
+ try {
456
+ return f.apply(this, args);
457
+ } catch (e) {
458
+ const idx = addToExternrefTable0(e);
459
+ wasm.__wbindgen_exn_store(idx);
460
+ }
461
+ }
462
+
463
+ function isLikeNone(x) {
464
+ return x === undefined || x === null;
465
+ }
466
+
467
+ function makeClosure(arg0, arg1, f) {
468
+ const state = { a: arg0, b: arg1, cnt: 1 };
469
+ const real = (...args) => {
470
+
471
+ // First up with a closure we increment the internal reference
472
+ // count. This ensures that the Rust closure environment won't
473
+ // be deallocated while we're invoking it.
474
+ state.cnt++;
475
+ try {
476
+ return f(state.a, state.b, ...args);
477
+ } finally {
478
+ real._wbg_cb_unref();
479
+ }
480
+ };
481
+ real._wbg_cb_unref = () => {
482
+ if (--state.cnt === 0) {
483
+ wasm.__wbindgen_destroy_closure(state.a, state.b);
484
+ state.a = 0;
485
+ CLOSURE_DTORS.unregister(state);
486
+ }
487
+ };
488
+ CLOSURE_DTORS.register(real, state, state);
489
+ return real;
490
+ }
491
+
492
+ function passStringToWasm0(arg, malloc, realloc) {
493
+ if (realloc === undefined) {
494
+ const buf = cachedTextEncoder.encode(arg);
495
+ const ptr = malloc(buf.length, 1) >>> 0;
496
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
497
+ WASM_VECTOR_LEN = buf.length;
498
+ return ptr;
499
+ }
500
+
501
+ let len = arg.length;
502
+ let ptr = malloc(len, 1) >>> 0;
503
+
504
+ const mem = getUint8ArrayMemory0();
505
+
506
+ let offset = 0;
507
+
508
+ for (; offset < len; offset++) {
509
+ const code = arg.charCodeAt(offset);
510
+ if (code > 0x7F) break;
511
+ mem[ptr + offset] = code;
512
+ }
513
+ if (offset !== len) {
514
+ if (offset !== 0) {
515
+ arg = arg.slice(offset);
516
+ }
517
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
518
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
519
+ const ret = cachedTextEncoder.encodeInto(arg, view);
520
+
521
+ offset += ret.written;
522
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
523
+ }
524
+
525
+ WASM_VECTOR_LEN = offset;
526
+ return ptr;
527
+ }
528
+
529
+ function takeFromExternrefTable0(idx) {
530
+ const value = wasm.__wbindgen_externrefs.get(idx);
531
+ wasm.__externref_table_dealloc(idx);
532
+ return value;
533
+ }
534
+
535
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
536
+ cachedTextDecoder.decode();
537
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
538
+ let numBytesDecoded = 0;
539
+ function decodeText(ptr, len) {
540
+ numBytesDecoded += len;
541
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
542
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
543
+ cachedTextDecoder.decode();
544
+ numBytesDecoded = len;
545
+ }
546
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
547
+ }
548
+
549
+ const cachedTextEncoder = new TextEncoder();
550
+
551
+ if (!('encodeInto' in cachedTextEncoder)) {
552
+ cachedTextEncoder.encodeInto = function (arg, view) {
553
+ const buf = cachedTextEncoder.encode(arg);
554
+ view.set(buf);
555
+ return {
556
+ read: arg.length,
557
+ written: buf.length
558
+ };
559
+ };
560
+ }
561
+
562
+ let WASM_VECTOR_LEN = 0;
563
+
564
+ let wasmModule, wasmInstance, wasm;
565
+ function __wbg_finalize_init(instance, module) {
566
+ wasmInstance = instance;
567
+ wasm = instance.exports;
568
+ wasmModule = module;
569
+ cachedDataViewMemory0 = null;
570
+ cachedUint8ArrayMemory0 = null;
571
+ wasm.__wbindgen_start();
572
+ return wasm;
573
+ }
574
+
575
+ async function __wbg_load(module, imports) {
576
+ if (typeof Response === 'function' && module instanceof Response) {
577
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
578
+ try {
579
+ return await WebAssembly.instantiateStreaming(module, imports);
580
+ } catch (e) {
581
+ const validResponse = module.ok && expectedResponseType(module.type);
582
+
583
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
584
+ 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);
585
+
586
+ } else { throw e; }
587
+ }
588
+ }
589
+
590
+ const bytes = await module.arrayBuffer();
591
+ return await WebAssembly.instantiate(bytes, imports);
592
+ } else {
593
+ const instance = await WebAssembly.instantiate(module, imports);
594
+
595
+ if (instance instanceof WebAssembly.Instance) {
596
+ return { instance, module };
597
+ } else {
598
+ return instance;
599
+ }
600
+ }
601
+
602
+ function expectedResponseType(type) {
603
+ switch (type) {
604
+ case 'basic': case 'cors': case 'default': return true;
605
+ }
606
+ return false;
607
+ }
608
+ }
609
+
610
+ function initSync(module) {
611
+ if (wasm !== undefined) return wasm;
612
+
613
+
614
+ if (module !== undefined) {
615
+ if (Object.getPrototypeOf(module) === Object.prototype) {
616
+ ({module} = module)
617
+ } else {
618
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
619
+ }
620
+ }
621
+
622
+ const imports = __wbg_get_imports();
623
+ if (!(module instanceof WebAssembly.Module)) {
624
+ module = new WebAssembly.Module(module);
625
+ }
626
+ const instance = new WebAssembly.Instance(module, imports);
627
+ return __wbg_finalize_init(instance, module);
628
+ }
629
+
630
+ async function __wbg_init(module_or_path) {
631
+ if (wasm !== undefined) return wasm;
632
+
633
+
634
+ if (module_or_path !== undefined) {
635
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
636
+ ({module_or_path} = module_or_path)
637
+ } else {
638
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
639
+ }
640
+ }
641
+
642
+ if (module_or_path === undefined) {
643
+ module_or_path = new URL('rsvelte_compiler_bg.wasm', import.meta.url);
644
+ }
645
+ const imports = __wbg_get_imports();
646
+
647
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
648
+ module_or_path = fetch(module_or_path);
649
+ }
650
+
651
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
652
+
653
+ return __wbg_finalize_init(instance, module);
654
+ }
655
+
656
+ export { initSync, __wbg_init as default };
Binary file