@rsvelte/vite-plugin-svelte-native 0.3.8 → 0.3.10
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/index.cjs +1 -1
- package/index.d.ts +31 -0
- package/package.json +6 -6
- package/parse-envelope.js +58 -9
package/index.cjs
CHANGED
|
@@ -254,4 +254,4 @@ module.exports.decodeParseEnvelope = decodeParseEnvelope;
|
|
|
254
254
|
// with `submodules/svelte/packages/svelte/package.json` by hand; run
|
|
255
255
|
// `node scripts/dev/check-vps-version.mjs` (also wired into CI) to
|
|
256
256
|
// catch drift.
|
|
257
|
-
module.exports.VERSION = '5.56.
|
|
257
|
+
module.exports.VERSION = '5.56.10';
|
package/index.d.ts
CHANGED
|
@@ -193,6 +193,13 @@ export function compileModule(
|
|
|
193
193
|
* {@link decodeEnvelope} to obtain
|
|
194
194
|
* the legacy {@link CompileResult} shape; or pass the buffer through
|
|
195
195
|
* worker `postMessage` (transferable) to avoid a copy.
|
|
196
|
+
*
|
|
197
|
+
* Unlike {@link compile}, this does NOT go through the wrapper that resolves
|
|
198
|
+
* upstream's function-valued options, so a `runes` / `css` / `customElement` /
|
|
199
|
+
* `warningFilter` callback is **rejected** here rather than honoured — evaluate
|
|
200
|
+
* it yourself and pass the plain value. `runes` and `warningFilter` used to be
|
|
201
|
+
* dropped in silence instead, which produced a successful compile with the
|
|
202
|
+
* wrong result; `css` and `customElement` already threw.
|
|
196
203
|
*/
|
|
197
204
|
export function compileEnvelope(source: string, options?: CompileOptions): Buffer;
|
|
198
205
|
export function compileModuleEnvelope(
|
|
@@ -328,6 +335,13 @@ export function compileModuleBuffers(
|
|
|
328
335
|
/**
|
|
329
336
|
* The legacy JSON-on-the-boundary path. Kept exported for parity tests
|
|
330
337
|
* and as an escape hatch — production callers should use {@link compile}.
|
|
338
|
+
*
|
|
339
|
+
* Unlike {@link compile}, this does NOT go through the wrapper that resolves
|
|
340
|
+
* upstream's function-valued options, so a `runes` / `css` / `customElement` /
|
|
341
|
+
* `warningFilter` callback is **rejected** here rather than honoured — evaluate
|
|
342
|
+
* it yourself and pass the plain value. `runes` and `warningFilter` used to be
|
|
343
|
+
* dropped in silence instead, which produced a successful compile with the
|
|
344
|
+
* wrong result; `css` and `customElement` already threw.
|
|
331
345
|
*/
|
|
332
346
|
export function compileLegacy(source: string, options?: CompileOptions): CompileResult;
|
|
333
347
|
export function compileModuleLegacy(
|
|
@@ -359,12 +373,29 @@ export interface ParseOptions {
|
|
|
359
373
|
* JSON-parse step.
|
|
360
374
|
*/
|
|
361
375
|
skipCssAst?: boolean;
|
|
376
|
+
/**
|
|
377
|
+
* `modern` from `svelte/compiler`'s `parse()`. **Defaults to `false`**,
|
|
378
|
+
* which returns the LEGACY AST (`{ html, instance, module, css }`); pass
|
|
379
|
+
* `true` for the modern `Root` shape. The modern AST stays opt-in until
|
|
380
|
+
* Svelte 6, and this binding defaults the same way official does.
|
|
381
|
+
*/
|
|
382
|
+
modern?: boolean;
|
|
383
|
+
/**
|
|
384
|
+
* `loose` from `svelte/compiler`'s `parse()`. Recover from a parse error
|
|
385
|
+
* and return an AST anyway — what an editor integration needs to parse a
|
|
386
|
+
* document mid-keystroke. Not blanket recovery: a source official still
|
|
387
|
+
* rejects under `loose` (e.g. a stray `</div>`) throws here too.
|
|
388
|
+
*/
|
|
389
|
+
loose?: boolean;
|
|
362
390
|
}
|
|
363
391
|
|
|
364
392
|
/**
|
|
365
393
|
* Parse a Svelte component and return the AST as a JSON string. The
|
|
366
394
|
* caller is responsible for `JSON.parse` on the returned value.
|
|
367
395
|
*
|
|
396
|
+
* Without `{ modern: true }` this returns the LEGACY AST, matching
|
|
397
|
+
* `svelte/compiler`'s default.
|
|
398
|
+
*
|
|
368
399
|
* For the fastest path skip JSON entirely: use {@link parseEnvelope}
|
|
369
400
|
* with `decodeParseEnvelope` from
|
|
370
401
|
* `@rsvelte/vite-plugin-svelte-native/parse-envelope.js`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsvelte/vite-plugin-svelte-native",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "NAPI bindings to the rsvelte compiler — used by the @rsvelte vite-plugin-svelte shim",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"index.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"optionalDependencies": {
|
|
33
|
-
"@rsvelte/vite-plugin-svelte-native-darwin-
|
|
34
|
-
"@rsvelte/vite-plugin-svelte-native-darwin-
|
|
35
|
-
"@rsvelte/vite-plugin-svelte-native-linux-
|
|
36
|
-
"@rsvelte/vite-plugin-svelte-native-linux-
|
|
37
|
-
"@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.3.
|
|
33
|
+
"@rsvelte/vite-plugin-svelte-native-darwin-arm64": "^0.3.10",
|
|
34
|
+
"@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.3.10",
|
|
35
|
+
"@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.3.10",
|
|
36
|
+
"@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.3.10",
|
|
37
|
+
"@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.3.10"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
package/parse-envelope.js
CHANGED
|
@@ -19,7 +19,7 @@ const MAGIC = 0x3156_5052; // "RPV1" little-endian
|
|
|
19
19
|
// reorder, `typeParameters` on function-like nodes, Identifier `optional`);
|
|
20
20
|
// v4 adds the object-method `typeParameters`-after-`body` flag byte.
|
|
21
21
|
// Keep in lockstep with `napi_raw_parse.rs`'s `VERSION`.
|
|
22
|
-
const VERSION =
|
|
22
|
+
const VERSION = 8;
|
|
23
23
|
const HEADER_LEN = 24;
|
|
24
24
|
|
|
25
25
|
// Tags — must mirror napi_raw_parse.rs.
|
|
@@ -80,7 +80,7 @@ const TAG_AWAIT_BLOCK = 0x72;
|
|
|
80
80
|
const TAG_KEY_BLOCK = 0x73;
|
|
81
81
|
const TAG_SNIPPET_BLOCK = 0x74;
|
|
82
82
|
|
|
83
|
-
// JsNode (estree) tags — 0x80..
|
|
83
|
+
// JsNode (estree) tags — 0x80..0xD1. Mirrors `napi_raw_parse.rs`.
|
|
84
84
|
const JS_IDENTIFIER = 0x80;
|
|
85
85
|
const JS_PRIVATE_IDENTIFIER = 0x81;
|
|
86
86
|
const JS_LITERAL = 0x82;
|
|
@@ -140,6 +140,8 @@ const JS_CONTINUE_STATEMENT = 0xb7;
|
|
|
140
140
|
const JS_EMPTY_STATEMENT = 0xb8;
|
|
141
141
|
const JS_DEBUGGER_STATEMENT = 0xb9;
|
|
142
142
|
const JS_IMPORT_DECLARATION = 0xba;
|
|
143
|
+
const JS_IMPORT_ATTRIBUTE = 0xd2;
|
|
144
|
+
const JS_EXPORT_ALL_DECLARATION = 0xd3;
|
|
143
145
|
const JS_IMPORT_SPECIFIER = 0xbb;
|
|
144
146
|
const JS_IMPORT_DEFAULT_SPECIFIER = 0xbc;
|
|
145
147
|
const JS_IMPORT_NAMESPACE_SPECIFIER = 0xbd;
|
|
@@ -152,7 +154,6 @@ const JS_PROPERTY_DEFINITION = 0xc3;
|
|
|
152
154
|
const JS_STATIC_BLOCK = 0xc4;
|
|
153
155
|
const JS_DECORATOR = 0xc5;
|
|
154
156
|
const JS_TS_TYPE_ANNOTATION = 0xc6;
|
|
155
|
-
const JS_TS_ENUM_DECLARATION = 0xc7;
|
|
156
157
|
const JS_TS_MODULE_DECLARATION = 0xc8;
|
|
157
158
|
const JS_COMMENT = 0xc9;
|
|
158
159
|
const JS_NULL = 0xca;
|
|
@@ -561,6 +562,8 @@ function readNodeBody(ctx, tag, start, end) {
|
|
|
561
562
|
return readJsBareExpr(ctx, 'DebuggerStatement', start, end);
|
|
562
563
|
case JS_IMPORT_DECLARATION:
|
|
563
564
|
return readJsImportDeclaration(ctx, start, end);
|
|
565
|
+
case JS_IMPORT_ATTRIBUTE:
|
|
566
|
+
return readJsImportAttribute(ctx, start, end);
|
|
564
567
|
case JS_IMPORT_SPECIFIER:
|
|
565
568
|
return readJsImportSpecifier(ctx, start, end);
|
|
566
569
|
case JS_IMPORT_DEFAULT_SPECIFIER:
|
|
@@ -571,6 +574,8 @@ function readNodeBody(ctx, tag, start, end) {
|
|
|
571
574
|
return readJsExportNamedDeclaration(ctx, start, end);
|
|
572
575
|
case JS_EXPORT_DEFAULT_DECLARATION:
|
|
573
576
|
return readJsExportDefaultDeclaration(ctx, start, end);
|
|
577
|
+
case JS_EXPORT_ALL_DECLARATION:
|
|
578
|
+
return readJsExportAllDeclaration(ctx, start, end);
|
|
574
579
|
case JS_EXPORT_SPECIFIER:
|
|
575
580
|
return readJsExportSpecifier(ctx, start, end);
|
|
576
581
|
case JS_CLASS_BODY:
|
|
@@ -585,8 +590,6 @@ function readNodeBody(ctx, tag, start, end) {
|
|
|
585
590
|
return readJsBareExpr(ctx, 'Decorator', start, end);
|
|
586
591
|
case JS_TS_TYPE_ANNOTATION:
|
|
587
592
|
return readJsTSTypeAnnotation(ctx, start, end);
|
|
588
|
-
case JS_TS_ENUM_DECLARATION:
|
|
589
|
-
return readJsBareExpr(ctx, 'TSEnumDeclaration', start, end);
|
|
590
593
|
case JS_TS_PARAMETER_PROPERTY:
|
|
591
594
|
return readJsBareExpr(ctx, 'TSParameterProperty', start, end);
|
|
592
595
|
case JS_TS_MODULE_DECLARATION:
|
|
@@ -978,11 +981,18 @@ function readJsBareExpr(ctx, typeName, start, end) {
|
|
|
978
981
|
function readJsImportExpression(ctx, start, end) {
|
|
979
982
|
const loc = readTypedLoc(ctx);
|
|
980
983
|
const source = readNode(ctx);
|
|
984
|
+
const options = readChildArray(ctx);
|
|
985
|
+
const ts = readBool(ctx);
|
|
981
986
|
const node = { type: 'ImportExpression', start, end };
|
|
982
987
|
if (loc !== null) node.loc = loc;
|
|
983
988
|
node.source = source;
|
|
984
|
-
//
|
|
985
|
-
|
|
989
|
+
// acorn-typescript spells the second argument as an `arguments` list and
|
|
990
|
+
// omits the key when there is none; acorn always writes `options`.
|
|
991
|
+
if (ts) {
|
|
992
|
+
if (options.length > 0) node.arguments = options;
|
|
993
|
+
} else {
|
|
994
|
+
node.options = options.length > 0 ? options[0] : null;
|
|
995
|
+
}
|
|
986
996
|
return node;
|
|
987
997
|
}
|
|
988
998
|
|
|
@@ -1416,7 +1426,19 @@ function readJsImportDeclaration(ctx, start, end) {
|
|
|
1416
1426
|
node.specifiers = specifiers;
|
|
1417
1427
|
node.source = source;
|
|
1418
1428
|
if (importKind !== null) node.importKind = importKind;
|
|
1419
|
-
|
|
1429
|
+
// See `readJsExportNamedDeclaration`.
|
|
1430
|
+
if (importKind === null || attributes.length > 0) node.attributes = attributes;
|
|
1431
|
+
return node;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
function readJsImportAttribute(ctx, start, end) {
|
|
1435
|
+
const loc = readTypedLoc(ctx);
|
|
1436
|
+
const key = readNode(ctx);
|
|
1437
|
+
const value = readNode(ctx);
|
|
1438
|
+
const node = { type: 'ImportAttribute', start, end };
|
|
1439
|
+
if (loc !== null) node.loc = loc;
|
|
1440
|
+
node.key = key;
|
|
1441
|
+
node.value = value;
|
|
1420
1442
|
return node;
|
|
1421
1443
|
}
|
|
1422
1444
|
|
|
@@ -1464,15 +1486,35 @@ function readJsExportNamedDeclaration(ctx, start, end) {
|
|
|
1464
1486
|
node.specifiers = specifiers;
|
|
1465
1487
|
node.source = source;
|
|
1466
1488
|
if (exportKind !== null) node.exportKind = exportKind;
|
|
1467
|
-
|
|
1489
|
+
// acorn always writes `attributes`; acorn-typescript writes it only where the
|
|
1490
|
+
// source had a `with` clause, and `exportKind` is set for TypeScript alone.
|
|
1491
|
+
if (exportKind === null || attributes.length > 0) node.attributes = attributes;
|
|
1492
|
+
return node;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
function readJsExportAllDeclaration(ctx, start, end) {
|
|
1496
|
+
const loc = readTypedLoc(ctx);
|
|
1497
|
+
const exported = readOptNode(ctx);
|
|
1498
|
+
const source = readNode(ctx);
|
|
1499
|
+
const exportKind = readOptStr(ctx);
|
|
1500
|
+
const attributes = readChildArray(ctx);
|
|
1501
|
+
const node = { type: 'ExportAllDeclaration', start, end };
|
|
1502
|
+
if (loc !== null) node.loc = loc;
|
|
1503
|
+
if (exportKind !== null) node.exportKind = exportKind;
|
|
1504
|
+
node.exported = exported;
|
|
1505
|
+
node.source = source;
|
|
1506
|
+
// See `readJsExportNamedDeclaration`.
|
|
1507
|
+
if (exportKind === null || attributes.length > 0) node.attributes = attributes;
|
|
1468
1508
|
return node;
|
|
1469
1509
|
}
|
|
1470
1510
|
|
|
1471
1511
|
function readJsExportDefaultDeclaration(ctx, start, end) {
|
|
1472
1512
|
const loc = readTypedLoc(ctx);
|
|
1473
1513
|
const declaration = readNode(ctx);
|
|
1514
|
+
const exportKind = readOptStr(ctx);
|
|
1474
1515
|
const node = { type: 'ExportDefaultDeclaration', start, end };
|
|
1475
1516
|
if (loc !== null) node.loc = loc;
|
|
1517
|
+
if (exportKind !== null) node.exportKind = exportKind;
|
|
1476
1518
|
node.declaration = declaration;
|
|
1477
1519
|
return node;
|
|
1478
1520
|
}
|
|
@@ -1652,7 +1694,14 @@ function readJsComment(ctx, start, end) {
|
|
|
1652
1694
|
const kindByte = readU8(ctx);
|
|
1653
1695
|
const kind = kindByte === 1 ? 'Block' : 'Line';
|
|
1654
1696
|
const value = readStr(ctx);
|
|
1697
|
+
// Only an in-tag comment's `loc` carries `character`; a script comment's
|
|
1698
|
+
// comes from the JS parser, which does not produce one.
|
|
1699
|
+
const hasCharacter = readU8(ctx) === 1;
|
|
1655
1700
|
const loc = readSourceLocation(ctx);
|
|
1701
|
+
if (!hasCharacter) {
|
|
1702
|
+
delete loc.start.character;
|
|
1703
|
+
delete loc.end.character;
|
|
1704
|
+
}
|
|
1656
1705
|
return { type: kind, start, end, value, loc };
|
|
1657
1706
|
}
|
|
1658
1707
|
|