@rsvelte/compiler 0.2.0 → 0.3.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/LICENSE +21 -0
- package/README.md +247 -107
- package/package.json +19 -33
- package/svelte_compiler_rust.d.ts +108 -0
- package/svelte_compiler_rust.js +455 -0
- package/svelte_compiler_rust_bg.wasm +0 -0
- package/index.cjs +0 -79
- package/index.d.ts +0 -140
- package/index.js +0 -133
|
@@ -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;
|