@rsvelte/compiler 0.8.1 → 0.9.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/README.md +23 -0
- package/package.json +1 -1
- package/rsvelte_lint.d.ts +21 -3
- package/rsvelte_lint.js +162 -1
- package/rsvelte_lint_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -49,6 +49,7 @@ change.
|
|
|
49
49
|
```js
|
|
50
50
|
import init, {
|
|
51
51
|
parse_svelte,
|
|
52
|
+
compile,
|
|
52
53
|
compile_client,
|
|
53
54
|
compile_server,
|
|
54
55
|
version,
|
|
@@ -73,6 +74,28 @@ const ast = JSON.parse(parse_svelte(source).ast);
|
|
|
73
74
|
console.log(version()); // the rsvelte compiler version
|
|
74
75
|
```
|
|
75
76
|
|
|
77
|
+
### Full compile options
|
|
78
|
+
|
|
79
|
+
`compile(source, options)` accepts the full compile-options object, including the
|
|
80
|
+
function forms Svelte's own `compile` supports. It returns the result as a JSON
|
|
81
|
+
string (`{ js, css, warnings, metadata }`); the callbacks are input-only.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const result = JSON.parse(
|
|
85
|
+
compile(source, {
|
|
86
|
+
filename: 'App.svelte',
|
|
87
|
+
generate: 'client',
|
|
88
|
+
// `customElement` / `css` / `runes` also accept `({ filename }) => value`.
|
|
89
|
+
css: 'injected',
|
|
90
|
+
// Filter compiler warnings (applied by the compiler).
|
|
91
|
+
warningFilter: (w) => !w.code.startsWith('a11y'),
|
|
92
|
+
// A constant scope hash, or a dynamic `cssHash({ hash, css, name, filename })`.
|
|
93
|
+
cssHash: ({ hash, css }) => `x-${hash(css)}`,
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
console.log(result.js.code, result.warnings);
|
|
97
|
+
```
|
|
98
|
+
|
|
76
99
|
## Why it is fast
|
|
77
100
|
|
|
78
101
|
- Written in Rust with a memory-efficient AST (`u32` spans, compact strings) and
|
package/package.json
CHANGED
package/rsvelte_lint.d.ts
CHANGED
|
@@ -26,6 +26,18 @@ export class ParseResultWasm {
|
|
|
26
26
|
readonly success: boolean;
|
|
27
27
|
}
|
|
28
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
|
+
|
|
29
41
|
/**
|
|
30
42
|
* Compile a Svelte component to client-side JavaScript.
|
|
31
43
|
*/
|
|
@@ -50,7 +62,7 @@ export function lint(source: string, filename: string): string;
|
|
|
50
62
|
|
|
51
63
|
/**
|
|
52
64
|
* The full catalog of diagnostic ids [`lint`] can emit (see
|
|
53
|
-
*
|
|
65
|
+
* `rsvelte_lint::json_api::lint_rules`).
|
|
54
66
|
*/
|
|
55
67
|
export function lint_rules(): string;
|
|
56
68
|
|
|
@@ -86,23 +98,29 @@ export interface InitOutput {
|
|
|
86
98
|
readonly lint_version: () => [number, number];
|
|
87
99
|
readonly __wbg_compileresultwasm_free: (a: number, b: number) => void;
|
|
88
100
|
readonly __wbg_parseresultwasm_free: (a: number, b: number) => void;
|
|
101
|
+
readonly compile: (a: number, b: number, c: any) => [number, number, number, number];
|
|
89
102
|
readonly compile_client: (a: number, b: number, c: number, d: number) => number;
|
|
90
103
|
readonly compile_server: (a: number, b: number, c: number, d: number) => number;
|
|
91
104
|
readonly compileresultwasm_css: (a: number) => [number, number];
|
|
92
105
|
readonly compileresultwasm_error: (a: number) => [number, number];
|
|
93
106
|
readonly compileresultwasm_js: (a: number) => [number, number];
|
|
94
107
|
readonly compileresultwasm_success: (a: number) => number;
|
|
108
|
+
readonly init: () => void;
|
|
95
109
|
readonly parse_svelte: (a: number, b: number) => number;
|
|
96
110
|
readonly parseresultwasm_ast: (a: number) => [number, number];
|
|
97
111
|
readonly parseresultwasm_error: (a: number) => [number, number];
|
|
98
112
|
readonly parseresultwasm_success: (a: number) => number;
|
|
99
113
|
readonly svelte2tsx: (a: number, b: number, c: number, d: number) => [number, number];
|
|
100
114
|
readonly version: () => [number, number];
|
|
101
|
-
readonly
|
|
102
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
115
|
+
readonly wasm_bindgen_b67232e9c19c9ca6___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_: (a: number, b: number, c: number, d: number) => [number, number];
|
|
103
116
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
104
117
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
118
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
119
|
+
readonly __externref_table_alloc: () => number;
|
|
105
120
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
121
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
122
|
+
readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
|
|
123
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
106
124
|
readonly __wbindgen_start: () => void;
|
|
107
125
|
}
|
|
108
126
|
|
package/rsvelte_lint.js
CHANGED
|
@@ -129,6 +129,40 @@ export class ParseResultWasm {
|
|
|
129
129
|
}
|
|
130
130
|
if (Symbol.dispose) ParseResultWasm.prototype[Symbol.dispose] = ParseResultWasm.prototype.free;
|
|
131
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
|
+
|
|
132
166
|
/**
|
|
133
167
|
* Compile a Svelte component to client-side JavaScript.
|
|
134
168
|
* @param {string} source
|
|
@@ -193,7 +227,7 @@ export function lint(source, filename) {
|
|
|
193
227
|
|
|
194
228
|
/**
|
|
195
229
|
* The full catalog of diagnostic ids [`lint`] can emit (see
|
|
196
|
-
*
|
|
230
|
+
* `rsvelte_lint::json_api::lint_rules`).
|
|
197
231
|
* @returns {string}
|
|
198
232
|
*/
|
|
199
233
|
export function lint_rules() {
|
|
@@ -283,9 +317,41 @@ export function version() {
|
|
|
283
317
|
function __wbg_get_imports() {
|
|
284
318
|
const import0 = {
|
|
285
319
|
__proto__: null,
|
|
320
|
+
__wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
|
|
321
|
+
const v = arg0;
|
|
322
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
323
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
324
|
+
},
|
|
325
|
+
__wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
|
|
326
|
+
const ret = typeof(arg0) === 'function';
|
|
327
|
+
return ret;
|
|
328
|
+
},
|
|
329
|
+
__wbg___wbindgen_is_null_ea9085d691f535d3: function(arg0) {
|
|
330
|
+
const ret = arg0 === null;
|
|
331
|
+
return ret;
|
|
332
|
+
},
|
|
333
|
+
__wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
|
|
334
|
+
const ret = arg0 === undefined;
|
|
335
|
+
return ret;
|
|
336
|
+
},
|
|
337
|
+
__wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
|
|
338
|
+
const obj = arg1;
|
|
339
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
340
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
341
|
+
var len1 = WASM_VECTOR_LEN;
|
|
342
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
343
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
344
|
+
},
|
|
286
345
|
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
287
346
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
288
347
|
},
|
|
348
|
+
__wbg__wbg_cb_unref_fffb441def202758: function(arg0) {
|
|
349
|
+
arg0._wbg_cb_unref();
|
|
350
|
+
},
|
|
351
|
+
__wbg_call_a6e5c5dce5018821: function() { return handleError(function (arg0, arg1, arg2) {
|
|
352
|
+
const ret = arg0.call(arg1, arg2);
|
|
353
|
+
return ret;
|
|
354
|
+
}, arguments); },
|
|
289
355
|
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
290
356
|
let deferred0_0;
|
|
291
357
|
let deferred0_1;
|
|
@@ -297,10 +363,26 @@ function __wbg_get_imports() {
|
|
|
297
363
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
298
364
|
}
|
|
299
365
|
},
|
|
366
|
+
__wbg_get_78f252d074a84d0b: function() { return handleError(function (arg0, arg1) {
|
|
367
|
+
const ret = Reflect.get(arg0, arg1);
|
|
368
|
+
return ret;
|
|
369
|
+
}, arguments); },
|
|
300
370
|
__wbg_new_227d7c05414eb861: function() {
|
|
301
371
|
const ret = new Error();
|
|
302
372
|
return ret;
|
|
303
373
|
},
|
|
374
|
+
__wbg_new_da52cf8fe3429cb2: function() {
|
|
375
|
+
const ret = new Object();
|
|
376
|
+
return ret;
|
|
377
|
+
},
|
|
378
|
+
__wbg_parse_1c0d8a8656d7e016: function() { return handleError(function (arg0, arg1) {
|
|
379
|
+
const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
|
|
380
|
+
return ret;
|
|
381
|
+
}, arguments); },
|
|
382
|
+
__wbg_set_8535240470bf2500: function() { return handleError(function (arg0, arg1, arg2) {
|
|
383
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
384
|
+
return ret;
|
|
385
|
+
}, arguments); },
|
|
304
386
|
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
305
387
|
const ret = arg1.stack;
|
|
306
388
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -308,6 +390,16 @@ function __wbg_get_imports() {
|
|
|
308
390
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
309
391
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
310
392
|
},
|
|
393
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
394
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [String], shim_idx: 164, ret: String, inner_ret: Some(String) }, mutable: false }) -> Externref`.
|
|
395
|
+
const ret = makeClosure(arg0, arg1, wasm_bindgen_b67232e9c19c9ca6___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_);
|
|
396
|
+
return ret;
|
|
397
|
+
},
|
|
398
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
399
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
400
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
401
|
+
return ret;
|
|
402
|
+
},
|
|
311
403
|
__wbindgen_init_externref_table: function() {
|
|
312
404
|
const table = wasm.__wbindgen_externrefs;
|
|
313
405
|
const offset = table.grow(4);
|
|
@@ -324,6 +416,21 @@ function __wbg_get_imports() {
|
|
|
324
416
|
};
|
|
325
417
|
}
|
|
326
418
|
|
|
419
|
+
function wasm_bindgen_b67232e9c19c9ca6___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_(arg0, arg1, arg2) {
|
|
420
|
+
let deferred2_0;
|
|
421
|
+
let deferred2_1;
|
|
422
|
+
try {
|
|
423
|
+
const ptr0 = passStringToWasm0(arg2, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
424
|
+
const len0 = WASM_VECTOR_LEN;
|
|
425
|
+
const ret = wasm.wasm_bindgen_b67232e9c19c9ca6___convert__closures_____invoke___alloc_a941a2cfab7efbc4___string__String__alloc_a941a2cfab7efbc4___string__String__true_(arg0, arg1, ptr0, len0);
|
|
426
|
+
deferred2_0 = ret[0];
|
|
427
|
+
deferred2_1 = ret[1];
|
|
428
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
429
|
+
} finally {
|
|
430
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
327
434
|
const CompileResultWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
328
435
|
? { register: () => {}, unregister: () => {} }
|
|
329
436
|
: new FinalizationRegistry(ptr => wasm.__wbg_compileresultwasm_free(ptr, 1));
|
|
@@ -331,6 +438,16 @@ const ParseResultWasmFinalization = (typeof FinalizationRegistry === 'undefined'
|
|
|
331
438
|
? { register: () => {}, unregister: () => {} }
|
|
332
439
|
: new FinalizationRegistry(ptr => wasm.__wbg_parseresultwasm_free(ptr, 1));
|
|
333
440
|
|
|
441
|
+
function addToExternrefTable0(obj) {
|
|
442
|
+
const idx = wasm.__externref_table_alloc();
|
|
443
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
444
|
+
return idx;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
|
|
448
|
+
? { register: () => {}, unregister: () => {} }
|
|
449
|
+
: new FinalizationRegistry(state => wasm.__wbindgen_destroy_closure(state.a, state.b));
|
|
450
|
+
|
|
334
451
|
let cachedDataViewMemory0 = null;
|
|
335
452
|
function getDataViewMemory0() {
|
|
336
453
|
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
@@ -351,6 +468,44 @@ function getUint8ArrayMemory0() {
|
|
|
351
468
|
return cachedUint8ArrayMemory0;
|
|
352
469
|
}
|
|
353
470
|
|
|
471
|
+
function handleError(f, args) {
|
|
472
|
+
try {
|
|
473
|
+
return f.apply(this, args);
|
|
474
|
+
} catch (e) {
|
|
475
|
+
const idx = addToExternrefTable0(e);
|
|
476
|
+
wasm.__wbindgen_exn_store(idx);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function isLikeNone(x) {
|
|
481
|
+
return x === undefined || x === null;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function makeClosure(arg0, arg1, f) {
|
|
485
|
+
const state = { a: arg0, b: arg1, cnt: 1 };
|
|
486
|
+
const real = (...args) => {
|
|
487
|
+
|
|
488
|
+
// First up with a closure we increment the internal reference
|
|
489
|
+
// count. This ensures that the Rust closure environment won't
|
|
490
|
+
// be deallocated while we're invoking it.
|
|
491
|
+
state.cnt++;
|
|
492
|
+
try {
|
|
493
|
+
return f(state.a, state.b, ...args);
|
|
494
|
+
} finally {
|
|
495
|
+
real._wbg_cb_unref();
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
real._wbg_cb_unref = () => {
|
|
499
|
+
if (--state.cnt === 0) {
|
|
500
|
+
wasm.__wbindgen_destroy_closure(state.a, state.b);
|
|
501
|
+
state.a = 0;
|
|
502
|
+
CLOSURE_DTORS.unregister(state);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
CLOSURE_DTORS.register(real, state, state);
|
|
506
|
+
return real;
|
|
507
|
+
}
|
|
508
|
+
|
|
354
509
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
355
510
|
if (realloc === undefined) {
|
|
356
511
|
const buf = cachedTextEncoder.encode(arg);
|
|
@@ -388,6 +543,12 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
388
543
|
return ptr;
|
|
389
544
|
}
|
|
390
545
|
|
|
546
|
+
function takeFromExternrefTable0(idx) {
|
|
547
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
548
|
+
wasm.__externref_table_dealloc(idx);
|
|
549
|
+
return value;
|
|
550
|
+
}
|
|
551
|
+
|
|
391
552
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
392
553
|
cachedTextDecoder.decode();
|
|
393
554
|
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
package/rsvelte_lint_bg.wasm
CHANGED
|
Binary file
|