@rsvelte/vite-plugin-svelte-native 0.3.9 → 0.3.11

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.
Files changed (2) hide show
  1. package/package.json +6 -6
  2. package/parse-envelope.js +79 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsvelte/vite-plugin-svelte-native",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
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-arm64": "^0.3.9",
34
- "@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.3.9",
35
- "@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.3.9",
36
- "@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.3.9",
37
- "@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.3.9"
33
+ "@rsvelte/vite-plugin-svelte-native-darwin-arm64": "^0.3.11",
34
+ "@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.3.11",
35
+ "@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.3.11",
36
+ "@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.3.11",
37
+ "@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.3.11"
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 = 5;
22
+ const VERSION = 10;
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..0xCC. Mirrors `napi_raw_parse.rs`.
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,8 +154,8 @@ 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;
158
+ const JS_TS_MODULE_BLOCK = 0xd4;
157
159
  const JS_COMMENT = 0xc9;
158
160
  const JS_NULL = 0xca;
159
161
  // 0xcb was the former whole-node JS_RAW_JSON escape (removed — TS type
@@ -561,6 +563,8 @@ function readNodeBody(ctx, tag, start, end) {
561
563
  return readJsBareExpr(ctx, 'DebuggerStatement', start, end);
562
564
  case JS_IMPORT_DECLARATION:
563
565
  return readJsImportDeclaration(ctx, start, end);
566
+ case JS_IMPORT_ATTRIBUTE:
567
+ return readJsImportAttribute(ctx, start, end);
564
568
  case JS_IMPORT_SPECIFIER:
565
569
  return readJsImportSpecifier(ctx, start, end);
566
570
  case JS_IMPORT_DEFAULT_SPECIFIER:
@@ -571,6 +575,8 @@ function readNodeBody(ctx, tag, start, end) {
571
575
  return readJsExportNamedDeclaration(ctx, start, end);
572
576
  case JS_EXPORT_DEFAULT_DECLARATION:
573
577
  return readJsExportDefaultDeclaration(ctx, start, end);
578
+ case JS_EXPORT_ALL_DECLARATION:
579
+ return readJsExportAllDeclaration(ctx, start, end);
574
580
  case JS_EXPORT_SPECIFIER:
575
581
  return readJsExportSpecifier(ctx, start, end);
576
582
  case JS_CLASS_BODY:
@@ -585,12 +591,12 @@ function readNodeBody(ctx, tag, start, end) {
585
591
  return readJsBareExpr(ctx, 'Decorator', start, end);
586
592
  case JS_TS_TYPE_ANNOTATION:
587
593
  return readJsTSTypeAnnotation(ctx, start, end);
588
- case JS_TS_ENUM_DECLARATION:
589
- return readJsBareExpr(ctx, 'TSEnumDeclaration', start, end);
590
594
  case JS_TS_PARAMETER_PROPERTY:
591
595
  return readJsBareExpr(ctx, 'TSParameterProperty', start, end);
592
596
  case JS_TS_MODULE_DECLARATION:
593
597
  return readJsTSModuleDeclaration(ctx, start, end);
598
+ case JS_TS_MODULE_BLOCK:
599
+ return readJsTSModuleBlock(ctx, start, end);
594
600
  case JS_TS_AS_EXPRESSION:
595
601
  return readJsTSAssertion(ctx, 'TSAsExpression', start, end, true);
596
602
  case JS_TS_SATISFIES_EXPRESSION:
@@ -978,11 +984,18 @@ function readJsBareExpr(ctx, typeName, start, end) {
978
984
  function readJsImportExpression(ctx, start, end) {
979
985
  const loc = readTypedLoc(ctx);
980
986
  const source = readNode(ctx);
987
+ const options = readChildArray(ctx);
988
+ const ts = readBool(ctx);
981
989
  const node = { type: 'ImportExpression', start, end };
982
990
  if (loc !== null) node.loc = loc;
983
991
  node.source = source;
984
- // The upstream serializer also adds `options: null`. Match that.
985
- node.options = null;
992
+ // acorn-typescript spells the second argument as an `arguments` list and
993
+ // omits the key when there is none; acorn always writes `options`.
994
+ if (ts) {
995
+ if (options.length > 0) node.arguments = options;
996
+ } else {
997
+ node.options = options.length > 0 ? options[0] : null;
998
+ }
986
999
  return node;
987
1000
  }
988
1001
 
@@ -1198,18 +1211,24 @@ function readJsFunctionDeclaration(ctx, start, end) {
1198
1211
  const expression = readBool(ctx);
1199
1212
  const generator = readBool(ctx);
1200
1213
  const asyncFlag = readBool(ctx);
1214
+ const declare = readBool(ctx);
1201
1215
  const typeParameters = readOptTypeAnnotation(ctx);
1216
+ const returnType = readOptTypeAnnotation(ctx);
1202
1217
  const params = readChildArray(ctx);
1203
1218
  const body = readOptNode(ctx);
1204
- const node = { type: 'FunctionDeclaration', start, end };
1219
+ // A function with no body is a `declare function` or an overload signature,
1220
+ // which acorn-typescript spells as `TSDeclareFunction` with no `body` key.
1221
+ const node = { type: body === null ? 'TSDeclareFunction' : 'FunctionDeclaration', start, end };
1205
1222
  if (loc !== null) node.loc = loc;
1223
+ if (declare) node.declare = true;
1206
1224
  node.id = id;
1207
1225
  node.expression = expression;
1208
1226
  node.generator = generator;
1209
1227
  node.async = asyncFlag;
1210
1228
  if (typeParameters !== null) node.typeParameters = typeParameters;
1211
1229
  node.params = params;
1212
- node.body = body;
1230
+ if (returnType !== null) node.returnType = returnType;
1231
+ if (body !== null) node.body = body;
1213
1232
  return node;
1214
1233
  }
1215
1234
 
@@ -1416,7 +1435,19 @@ function readJsImportDeclaration(ctx, start, end) {
1416
1435
  node.specifiers = specifiers;
1417
1436
  node.source = source;
1418
1437
  if (importKind !== null) node.importKind = importKind;
1419
- node.attributes = attributes;
1438
+ // See `readJsExportNamedDeclaration`.
1439
+ if (importKind === null || attributes.length > 0) node.attributes = attributes;
1440
+ return node;
1441
+ }
1442
+
1443
+ function readJsImportAttribute(ctx, start, end) {
1444
+ const loc = readTypedLoc(ctx);
1445
+ const key = readNode(ctx);
1446
+ const value = readNode(ctx);
1447
+ const node = { type: 'ImportAttribute', start, end };
1448
+ if (loc !== null) node.loc = loc;
1449
+ node.key = key;
1450
+ node.value = value;
1420
1451
  return node;
1421
1452
  }
1422
1453
 
@@ -1464,15 +1495,35 @@ function readJsExportNamedDeclaration(ctx, start, end) {
1464
1495
  node.specifiers = specifiers;
1465
1496
  node.source = source;
1466
1497
  if (exportKind !== null) node.exportKind = exportKind;
1467
- node.attributes = attributes;
1498
+ // acorn always writes `attributes`; acorn-typescript writes it only where the
1499
+ // source had a `with` clause, and `exportKind` is set for TypeScript alone.
1500
+ if (exportKind === null || attributes.length > 0) node.attributes = attributes;
1501
+ return node;
1502
+ }
1503
+
1504
+ function readJsExportAllDeclaration(ctx, start, end) {
1505
+ const loc = readTypedLoc(ctx);
1506
+ const exported = readOptNode(ctx);
1507
+ const source = readNode(ctx);
1508
+ const exportKind = readOptStr(ctx);
1509
+ const attributes = readChildArray(ctx);
1510
+ const node = { type: 'ExportAllDeclaration', start, end };
1511
+ if (loc !== null) node.loc = loc;
1512
+ if (exportKind !== null) node.exportKind = exportKind;
1513
+ node.exported = exported;
1514
+ node.source = source;
1515
+ // See `readJsExportNamedDeclaration`.
1516
+ if (exportKind === null || attributes.length > 0) node.attributes = attributes;
1468
1517
  return node;
1469
1518
  }
1470
1519
 
1471
1520
  function readJsExportDefaultDeclaration(ctx, start, end) {
1472
1521
  const loc = readTypedLoc(ctx);
1473
1522
  const declaration = readNode(ctx);
1523
+ const exportKind = readOptStr(ctx);
1474
1524
  const node = { type: 'ExportDefaultDeclaration', start, end };
1475
1525
  if (loc !== null) node.loc = loc;
1526
+ if (exportKind !== null) node.exportKind = exportKind;
1476
1527
  node.declaration = declaration;
1477
1528
  return node;
1478
1529
  }
@@ -1551,10 +1602,27 @@ function readJsTSTypeAnnotation(ctx, start, end) {
1551
1602
 
1552
1603
  function readJsTSModuleDeclaration(ctx, start, end) {
1553
1604
  const loc = readTypedLoc(ctx);
1605
+ const id = readOptNode(ctx);
1606
+ const declare = readBool(ctx);
1607
+ const global = readBool(ctx);
1554
1608
  const body = readOptNode(ctx);
1555
1609
  const node = { type: 'TSModuleDeclaration', start, end };
1556
1610
  if (loc !== null) node.loc = loc;
1611
+ // acorn-typescript omits both flags when false, and orders `global` before
1612
+ // `id` and `declare` after `body`.
1613
+ if (global) node.global = true;
1614
+ if (id !== null) node.id = id;
1557
1615
  if (body !== null) node.body = body;
1616
+ if (declare) node.declare = true;
1617
+ return node;
1618
+ }
1619
+
1620
+ function readJsTSModuleBlock(ctx, start, end) {
1621
+ const loc = readTypedLoc(ctx);
1622
+ const body = readChildArray(ctx);
1623
+ const node = { type: 'TSModuleBlock', start, end };
1624
+ if (loc !== null) node.loc = loc;
1625
+ node.body = body;
1558
1626
  return node;
1559
1627
  }
1560
1628