sveld 0.18.1 → 0.19.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/CHANGELOG.md CHANGED
@@ -10,6 +10,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  - add isAccessor field to API
11
11
  - update Markdown writer to generate a separate table for accessors -->
12
12
 
13
+ ## [0.19.1](https://github.com/carbon-design-system/sveld/releases/tag/v0.19.1) - 2023-10-17
14
+
15
+ **Fixes**
16
+
17
+ - only print `outFile` when writing Markdown file
18
+ - upgrade `svelte-preprocess` and `typescript` to ameliorate peer dependency warning
19
+
20
+ ## [0.19.0](https://github.com/carbon-design-system/sveld/releases/tag/v0.19.0) - 2023-07-19
21
+
22
+ **Breaking Changes**
23
+
24
+ - if using Svelte 3, the generated TypeScript definitions now require version 3.55 or higher
25
+
26
+ **Features**
27
+
28
+ - support Svelte 4 in the generated TypeScript definitions
29
+
13
30
  ## [0.18.1](https://github.com/carbon-design-system/sveld/releases/tag/v0.18.1) - 2023-06-04
14
31
 
15
32
  - allow `data-*` attributes for props forwarded to HTML elements for `svelte-check@3.x` compatibility
package/README.md CHANGED
@@ -14,7 +14,7 @@ The purpose of this project is to make third party Svelte component libraries co
14
14
  - [Component Index](https://github.com/IBM/carbon-components-svelte/blob/master/COMPONENT_INDEX.md): Markdown file documenting component props, slots, and events
15
15
  - [Component API](https://github.com/IBM/carbon-components-svelte/blob/master/docs/src/COMPONENT_API.json): Component API metadata in JSON format
16
16
 
17
- **Please note** that the generated TypeScript definitions require [Svelte version 3.31](https://github.com/sveltejs/svelte/blob/master/CHANGELOG.md#3310) or greater.
17
+ **Please note** that the generated TypeScript definitions require Svelte version 3.55 or greater.
18
18
 
19
19
  ---
20
20
 
@@ -38,10 +38,12 @@ The generated definition extends the official `SvelteComponentTyped` interface e
38
38
  **Button.svelte.d.ts**
39
39
 
40
40
  ```ts
41
- /// <reference types="svelte" />
42
41
  import type { SvelteComponentTyped } from "svelte";
42
+ import type { SvelteHTMLElements } from "svelte/elements";
43
43
 
44
- export interface ButtonProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["button"]> {
44
+ type RestProps = SvelteHTMLElements["button"];
45
+
46
+ export interface ButtonProps extends RestProps {
45
47
  /**
46
48
  * @default "button"
47
49
  */
@@ -77,10 +79,11 @@ export let primary = false;
77
79
  The accompanying JSDoc annotations would generate the following:
78
80
 
79
81
  ```ts
80
- /// <reference types="svelte" />
81
- import { SvelteComponentTyped } from "svelte";
82
+ import type { SvelteHTMLElements } from "svelte/elements";
83
+
84
+ type RestProps = SvelteHTMLElements["button"];
82
85
 
83
- export interface ButtonProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["button"]> {
86
+ export interface ButtonProps extends RestProps {
84
87
  /**
85
88
  * @default "button"
86
89
  */
@@ -137,8 +140,6 @@ Extracted metadata include:
137
140
 
138
141
  This library adopts a progressively enhanced approach. Any property type that cannot be inferred (e.g., "hello" is a string) falls back to "any" to minimize incorrectly typed properties or signatures. To mitigate this, the library author can add JSDoc annotations to specify types that cannot be reliably inferred. This represents a progressively enhanced approach because JSDocs are comments that can be ignored by the compiler.
139
142
 
140
- The generated TypeScript definitions for a component extends the `SvelteComponentTyped` interface available in svelte version 3.31.
141
-
142
143
  ## Usage
143
144
 
144
145
  ### Installation
@@ -35,7 +35,7 @@ interface DispatchedEvent {
35
35
  detail?: any;
36
36
  description?: string;
37
37
  }
38
- declare type ComponentEvent = ForwardedEvent | DispatchedEvent;
38
+ type ComponentEvent = ForwardedEvent | DispatchedEvent;
39
39
  interface TypeDef {
40
40
  type: string;
41
41
  name: string;
@@ -50,7 +50,7 @@ interface ComponentElement {
50
50
  type: "Element";
51
51
  name: string;
52
52
  }
53
- declare type RestProps = undefined | ComponentInlineElement | ComponentElement;
53
+ type RestProps = undefined | ComponentInlineElement | ComponentElement;
54
54
  interface Extends {
55
55
  interface: string;
56
56
  import: string;
@@ -42,7 +42,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
42
42
  }
43
43
  return to.concat(ar || Array.prototype.slice.call(from));
44
44
  };
45
- exports.__esModule = true;
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ // TODO: upgrading to Svelte 4 shows a lot of TS errors. Ignore for now but resolve.
47
+ // @ts-nocheck
46
48
  var compiler_1 = require("svelte/compiler");
47
49
  var commentParser = __importStar(require("comment-parser"));
48
50
  var element_tag_map_1 = require("./element-tag-map");
@@ -135,10 +137,10 @@ var ComponentParser = /** @class */ (function () {
135
137
  else {
136
138
  this.slots.set(name, {
137
139
  name: name,
138
- "default": default_slot,
140
+ default: default_slot,
139
141
  fallback: fallback,
140
142
  slot_props: slot_props,
141
- description: description
143
+ description: description,
142
144
  });
143
145
  }
144
146
  };
@@ -163,7 +165,7 @@ var ComponentParser = /** @class */ (function () {
163
165
  type: "dispatched",
164
166
  name: name,
165
167
  detail: default_detail,
166
- description: event_description
168
+ description: event_description,
167
169
  });
168
170
  }
169
171
  };
@@ -176,22 +178,22 @@ var ComponentParser = /** @class */ (function () {
176
178
  var type = _this.aliasType(tagType);
177
179
  switch (tag) {
178
180
  case "extends":
179
- _this["extends"] = {
181
+ _this.extends = {
180
182
  interface: name,
181
- "import": type
183
+ import: type,
182
184
  };
183
185
  break;
184
186
  case "restProps":
185
187
  _this.rest_props = {
186
188
  type: "Element",
187
- name: type
189
+ name: type,
188
190
  };
189
191
  break;
190
192
  case "slot":
191
193
  _this.addSlot({
192
194
  slot_name: name,
193
195
  slot_props: type,
194
- slot_description: !!description ? description : undefined
196
+ slot_description: !!description ? description : undefined,
195
197
  });
196
198
  break;
197
199
  case "event":
@@ -199,7 +201,7 @@ var ComponentParser = /** @class */ (function () {
199
201
  name: name,
200
202
  detail: type,
201
203
  has_argument: false,
202
- description: !!description ? description : undefined
204
+ description: !!description ? description : undefined,
203
205
  });
204
206
  break;
205
207
  case "typedef":
@@ -207,7 +209,7 @@ var ComponentParser = /** @class */ (function () {
207
209
  type: type,
208
210
  name: name,
209
211
  description: ComponentParser.assignValue(description),
210
- ts: /(\}|\};)$/.test(type) ? "interface ".concat(name, " ").concat(type) : "type ".concat(name, " = ").concat(type)
212
+ ts: /(\}|\};)$/.test(type) ? "interface ".concat(name, " ").concat(type) : "type ".concat(name, " = ").concat(type),
211
213
  });
212
214
  break;
213
215
  }
@@ -219,7 +221,7 @@ var ComponentParser = /** @class */ (function () {
219
221
  this.compiled = undefined;
220
222
  this.parsed = undefined;
221
223
  this.rest_props = undefined;
222
- this["extends"] = undefined;
224
+ this.extends = undefined;
223
225
  this.componentComment = undefined;
224
226
  this.reactive_vars.clear();
225
227
  this.props.clear();
@@ -289,7 +291,7 @@ var ComponentParser = /** @class */ (function () {
289
291
  if (node.leadingComments) {
290
292
  var last_comment = node.leadingComments[node.leadingComments.length - 1];
291
293
  var comment = commentParser.parse(ComponentParser.formatComment(last_comment.value), {
292
- spacing: "preserve"
294
+ spacing: "preserve",
293
295
  });
294
296
  var tag = (_e = comment[0]) === null || _e === void 0 ? void 0 : _e.tags[((_f = comment[0]) === null || _f === void 0 ? void 0 : _f.tags.length) - 1];
295
297
  if ((tag === null || tag === void 0 ? void 0 : tag.tag) === "type")
@@ -309,10 +311,10 @@ var ComponentParser = /** @class */ (function () {
309
311
  isFunctionDeclaration: isFunctionDeclaration,
310
312
  isRequired: false,
311
313
  constant: kind === "const",
312
- reactive: false
314
+ reactive: false,
313
315
  });
314
316
  }
315
- }
317
+ },
316
318
  });
317
319
  }
318
320
  var dispatcher_name = undefined;
@@ -326,14 +328,14 @@ var ComponentParser = /** @class */ (function () {
326
328
  }
327
329
  callees.push({
328
330
  name: node.callee.name,
329
- arguments: node.arguments
331
+ arguments: node.arguments,
330
332
  });
331
333
  }
332
334
  if (node.type === "Spread" && (node === null || node === void 0 ? void 0 : node.expression.name) === "$$restProps") {
333
335
  if (_this.rest_props === undefined && ((parent === null || parent === void 0 ? void 0 : parent.type) === "InlineComponent" || (parent === null || parent === void 0 ? void 0 : parent.type) === "Element")) {
334
336
  _this.rest_props = {
335
337
  type: parent.type,
336
- name: parent.name
338
+ name: parent.name,
337
339
  };
338
340
  }
339
341
  }
@@ -405,7 +407,7 @@ var ComponentParser = /** @class */ (function () {
405
407
  if (node.leadingComments) {
406
408
  var last_comment = node.leadingComments[node.leadingComments.length - 1];
407
409
  var comment = commentParser.parse(ComponentParser.formatComment(last_comment.value), {
408
- spacing: "preserve"
410
+ spacing: "preserve",
409
411
  });
410
412
  var tag = (_e = comment[0]) === null || _e === void 0 ? void 0 : _e.tags[((_f = comment[0]) === null || _f === void 0 ? void 0 : _f.tags.length) - 1];
411
413
  if ((tag === null || tag === void 0 ? void 0 : tag.tag) === "type")
@@ -432,7 +434,7 @@ var ComponentParser = /** @class */ (function () {
432
434
  isFunctionDeclaration: isFunctionDeclaration,
433
435
  isRequired: isRequired,
434
436
  constant: kind === "const",
435
- reactive: _this.reactive_vars.has(prop_name)
437
+ reactive: _this.reactive_vars.has(prop_name),
436
438
  });
437
439
  }
438
440
  if (node.type === "Comment") {
@@ -450,7 +452,7 @@ var ComponentParser = /** @class */ (function () {
450
452
  var name = _a.name, value = _a.value;
451
453
  var slot_prop_value = {
452
454
  value: undefined,
453
- replace: false
455
+ replace: false,
454
456
  };
455
457
  if (value === undefined)
456
458
  return {};
@@ -486,7 +488,7 @@ var ComponentParser = /** @class */ (function () {
486
488
  _this.addSlot({
487
489
  slot_name: slot_name,
488
490
  slot_props: JSON.stringify(slot_props, null, 2),
489
- slot_fallback: fallback
491
+ slot_fallback: fallback,
490
492
  });
491
493
  }
492
494
  if (node.type === "EventHandler" && node.expression == null) {
@@ -494,7 +496,7 @@ var ComponentParser = /** @class */ (function () {
494
496
  _this.events.set(node.name, {
495
497
  type: "forwarded",
496
498
  name: node.name,
497
- element: parent.name
499
+ element: parent.name,
498
500
  });
499
501
  }
500
502
  }
@@ -509,11 +511,11 @@ var ComponentParser = /** @class */ (function () {
509
511
  }
510
512
  else {
511
513
  _this.bindings.set(prop_name, {
512
- elements: [element_name]
514
+ elements: [element_name],
513
515
  });
514
516
  }
515
517
  }
516
- }
518
+ },
517
519
  });
518
520
  if (dispatcher_name !== undefined) {
519
521
  callees.forEach(function (callee) {
@@ -525,7 +527,7 @@ var ComponentParser = /** @class */ (function () {
525
527
  _this.addDispatchedEvent({
526
528
  name: event_name,
527
529
  detail: event_detail,
528
- has_argument: Boolean(event_argument)
530
+ has_argument: Boolean(event_argument),
529
531
  });
530
532
  }
531
533
  });
@@ -574,10 +576,10 @@ var ComponentParser = /** @class */ (function () {
574
576
  events: ComponentParser.mapToArray(this.events),
575
577
  typedefs: ComponentParser.mapToArray(this.typedefs),
576
578
  rest_props: this.rest_props,
577
- "extends": this["extends"],
578
- componentComment: this.componentComment
579
+ extends: this.extends,
580
+ componentComment: this.componentComment,
579
581
  };
580
582
  };
581
583
  return ComponentParser;
582
584
  }());
583
- exports["default"] = ComponentParser;
585
+ exports.default = ComponentParser;
package/lib/cli.js CHANGED
@@ -48,7 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  function verb(n) { return function (v) { return step([n, v]); }; }
49
49
  function step(op) {
50
50
  if (f) throw new TypeError("Generator is already executing.");
51
- while (_) try {
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
52
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
53
  if (y = 0, t) op = [op[0] & 2, t.value];
54
54
  switch (op[0]) {
@@ -72,7 +72,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
72
72
  var __importDefault = (this && this.__importDefault) || function (mod) {
73
73
  return (mod && mod.__esModule) ? mod : { "default": mod };
74
74
  };
75
- exports.__esModule = true;
75
+ Object.defineProperty(exports, "__esModule", { value: true });
76
76
  exports.cli = void 0;
77
77
  var Rollup = __importStar(require("rollup"));
78
78
  var svelte = __importStar(require("rollup-plugin-svelte"));
@@ -100,8 +100,8 @@ function cli(process) {
100
100
  plugins: [
101
101
  // @ts-ignore
102
102
  svelte(),
103
- (0, plugin_node_resolve_1["default"])(),
104
- ]
103
+ (0, plugin_node_resolve_1.default)(),
104
+ ],
105
105
  })];
106
106
  case 1:
107
107
  rollup_bundle = _a.sent();
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertSvelteExt = exports.removeSvelteExt = exports.createExports = void 0;
4
4
  function createExports(parsed_exports, components) {
5
5
  var source = Object.entries(parsed_exports).map(function (_a) {
@@ -13,7 +13,7 @@ function createExports(parsed_exports, components) {
13
13
  var named_exports = "";
14
14
  if (module_exports.length > 0)
15
15
  named_exports = ", " + module_exports.join(", ");
16
- if (id === "default" || exportee["default"]) {
16
+ if (id === "default" || exportee.default) {
17
17
  if (exportee.mixed) {
18
18
  return "export { default as ".concat(id).concat(named_exports, " } from \"").concat(exportee.source, "\";\nexport { default } from \"").concat(exportee.source, "\";");
19
19
  }
@@ -81,6 +81,6 @@ declare const tag_map: {
81
81
  ul: string;
82
82
  video: string;
83
83
  };
84
- declare type ElementTag = keyof typeof tag_map;
84
+ type ElementTag = keyof typeof tag_map;
85
85
  export declare function getElementByTag(element: ElementTag | string): string;
86
86
  export {};
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getElementByTag = void 0;
4
4
  // Element tag map adapted from TypeScript (`lib.dom.d.ts`)
5
5
  // https://github.com/microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L19263
@@ -84,7 +84,7 @@ var tag_map = {
84
84
  tr: "HTMLTableRowElement",
85
85
  track: "HTMLTrackElement",
86
86
  ul: "HTMLUListElement",
87
- video: "HTMLVideoElement"
87
+ video: "HTMLVideoElement",
88
88
  };
89
89
  function getElementByTag(element) {
90
90
  return element in tag_map ? tag_map[element] : "HTMLElement";
@@ -1,4 +1,4 @@
1
- export declare type SvelteEntryPoint = string;
1
+ export type SvelteEntryPoint = string;
2
2
  /**
3
3
  * Get the file path entry point for uncompiled Svelte source code
4
4
  * Expects a "svelte" field in the consumer's `package.json`
@@ -22,7 +22,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- exports.__esModule = true;
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getSvelteEntry = void 0;
27
27
  var fs = __importStar(require("fs"));
28
28
  var path = __importStar(require("path"));
package/lib/index.js CHANGED
@@ -1,22 +1,14 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- exports.__esModule = true;
14
- exports.sveld = exports.cli = exports.ComponentParser = exports["default"] = void 0;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sveld = exports.cli = exports.ComponentParser = exports.default = void 0;
15
7
  var rollup_plugin_1 = require("./rollup-plugin");
16
- __createBinding(exports, rollup_plugin_1, "default");
8
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(rollup_plugin_1).default; } });
17
9
  var ComponentParser_1 = require("./ComponentParser");
18
- __createBinding(exports, ComponentParser_1, "default", "ComponentParser");
10
+ Object.defineProperty(exports, "ComponentParser", { enumerable: true, get: function () { return __importDefault(ComponentParser_1).default; } });
19
11
  var cli_1 = require("./cli");
20
- __createBinding(exports, cli_1, "cli");
12
+ Object.defineProperty(exports, "cli", { enumerable: true, get: function () { return cli_1.cli; } });
21
13
  var sveld_1 = require("./sveld");
22
- __createBinding(exports, sveld_1, "sveld");
14
+ Object.defineProperty(exports, "sveld", { enumerable: true, get: function () { return sveld_1.sveld; } });
@@ -1,4 +1,4 @@
1
- export declare type ParsedExports = Record<string, {
1
+ export type ParsedExports = Record<string, {
2
2
  source: string;
3
3
  default: boolean;
4
4
  mixed?: boolean;
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- exports.__esModule = true;
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.parseExports = void 0;
41
41
  var acorn = __importStar(require("acorn"));
42
42
  var fs = __importStar(require("fs"));
@@ -45,7 +45,7 @@ var path_2 = require("./path");
45
45
  function parseExports(source, dir) {
46
46
  var ast = acorn.parse(source, {
47
47
  ecmaVersion: "latest",
48
- sourceType: "module"
48
+ sourceType: "module",
49
49
  });
50
50
  var exports_by_identifier = {};
51
51
  // @ts-ignore
@@ -54,31 +54,31 @@ function parseExports(source, dir) {
54
54
  if (node.type === "ExportDefaultDeclaration") {
55
55
  var id = node.declaration.name;
56
56
  if (id in exports_by_identifier) {
57
- exports_by_identifier[id]["default"] = true;
57
+ exports_by_identifier[id].default = true;
58
58
  }
59
59
  else {
60
- exports_by_identifier[id] = { source: "", "default": true };
60
+ exports_by_identifier[id] = { source: "", default: true };
61
61
  }
62
62
  }
63
63
  else if (node.type === "ExportAllDeclaration") {
64
64
  if (!node.source)
65
65
  return;
66
- var file_path = path_1["default"].resolve(dir, node.source.value);
66
+ var file_path = path_1.default.resolve(dir, node.source.value);
67
67
  if (!fs.lstatSync(file_path).isFile()) {
68
68
  var files = fs.readdirSync(file_path);
69
69
  for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
70
70
  var file = files_1[_i];
71
71
  if (file.includes("index")) {
72
- file_path = path_1["default"].join(file_path, file);
72
+ file_path = path_1.default.join(file_path, file);
73
73
  break;
74
74
  }
75
75
  }
76
76
  }
77
77
  var export_file = fs.readFileSync(file_path, "utf-8");
78
- var exports_1 = parseExports(export_file, path_1["default"].dirname(file_path));
78
+ var exports_1 = parseExports(export_file, path_1.default.dirname(file_path));
79
79
  for (var _e = 0, _f = Object.entries(exports_1); _e < _f.length; _e++) {
80
80
  var _g = _f[_e], key = _g[0], value = _g[1];
81
- var source_1 = (0, path_2.normalizeSeparators)("./" + path_1["default"].join(node.source.value, value.source));
81
+ var source_1 = (0, path_2.normalizeSeparators)("./" + path_1.default.join(node.source.value, value.source));
82
82
  exports_by_identifier[key] = __assign(__assign({}, value), { source: source_1 });
83
83
  }
84
84
  }
@@ -98,7 +98,7 @@ function parseExports(source, dir) {
98
98
  else {
99
99
  exports_by_identifier[id] = {
100
100
  source: (_d = (_c = node.source) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : "",
101
- "default": id === "default"
101
+ default: id === "default",
102
102
  };
103
103
  }
104
104
  });
@@ -113,7 +113,7 @@ function parseExports(source, dir) {
113
113
  else {
114
114
  exports_by_identifier[id] = {
115
115
  source: (_d = (_c = node.source) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : "",
116
- "default": id === "default"
116
+ default: id === "default",
117
117
  };
118
118
  }
119
119
  }
package/lib/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeSeparators = void 0;
4
4
  var path_1 = require("path");
5
5
  /**
@@ -12,12 +12,12 @@ export interface PluginSveldOptions {
12
12
  markdown?: boolean;
13
13
  markdownOptions?: Partial<WriteMarkdownOptions>;
14
14
  }
15
- declare type ComponentModuleName = string;
15
+ type ComponentModuleName = string;
16
16
  export interface ComponentDocApi extends ParsedComponent {
17
17
  filePath: string;
18
18
  moduleName: string;
19
19
  }
20
- export declare type ComponentDocs = Map<ComponentModuleName, ComponentDocApi>;
20
+ export type ComponentDocs = Map<ComponentModuleName, ComponentDocApi>;
21
21
  export default function pluginSveld(opts?: PluginSveldOptions): {
22
22
  name: string;
23
23
  buildStart(): void;
@@ -48,7 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  function verb(n) { return function (v) { return step([n, v]); }; }
49
49
  function step(op) {
50
50
  if (f) throw new TypeError("Generator is already executing.");
51
- while (_) try {
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
52
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
53
  if (y = 0, t) op = [op[0] & 2, t.value];
54
54
  switch (op[0]) {
@@ -72,7 +72,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
72
72
  var __importDefault = (this && this.__importDefault) || function (mod) {
73
73
  return (mod && mod.__esModule) ? mod : { "default": mod };
74
74
  };
75
- exports.__esModule = true;
75
+ Object.defineProperty(exports, "__esModule", { value: true });
76
76
  exports.writeOutput = exports.generateBundle = void 0;
77
77
  var fs = __importStar(require("fs"));
78
78
  var fsp = __importStar(require("fs/promises"));
@@ -113,10 +113,10 @@ function pluginSveld(opts) {
113
113
  writeBundle: function () {
114
114
  if (input != null)
115
115
  writeOutput(result, opts || {}, input);
116
- }
116
+ },
117
117
  };
118
118
  }
119
- exports["default"] = pluginSveld;
119
+ exports.default = pluginSveld;
120
120
  function generateBundle(input, glob) {
121
121
  return __awaiter(this, void 0, void 0, function () {
122
122
  var dir, entry, exports, components, parser, exportEntries, _i, exportEntries_1, _a, exportName, entry_1, filePath, _b, ext, name_1, moduleName, source, processed;
@@ -136,7 +136,7 @@ function generateBundle(input, glob) {
136
136
  });
137
137
  }
138
138
  components = new Map();
139
- parser = new ComponentParser_1["default"]();
139
+ parser = new ComponentParser_1.default();
140
140
  exportEntries = Object.entries(exports);
141
141
  _i = 0, exportEntries_1 = exportEntries;
142
142
  _c.label = 1;
@@ -154,13 +154,13 @@ function generateBundle(input, glob) {
154
154
  case 2:
155
155
  source = _c.sent();
156
156
  return [4 /*yield*/, (0, compiler_1.preprocess)(source, [(0, svelte_preprocess_1.typescript)(), (0, svelte_preprocess_1.replace)([[/<style.+<\/style>/gims, ""]])], {
157
- filename: path.basename(filePath)
157
+ filename: path.basename(filePath),
158
158
  })];
159
159
  case 3:
160
160
  processed = (_c.sent()).code;
161
161
  components.set(moduleName, __assign({ moduleName: moduleName, filePath: filePath }, parser.parseSvelteComponent(processed, {
162
162
  moduleName: moduleName,
163
- filePath: filePath
163
+ filePath: filePath,
164
164
  })));
165
165
  _c.label = 4;
166
166
  case 4:
@@ -168,7 +168,7 @@ function generateBundle(input, glob) {
168
168
  return [3 /*break*/, 1];
169
169
  case 5: return [2 /*return*/, {
170
170
  exports: exports,
171
- components: components
171
+ components: components,
172
172
  }];
173
173
  }
174
174
  });
@@ -178,13 +178,13 @@ exports.generateBundle = generateBundle;
178
178
  function writeOutput(result, opts, input) {
179
179
  var inputDir = path.dirname(input);
180
180
  if ((opts === null || opts === void 0 ? void 0 : opts.types) !== false) {
181
- (0, writer_ts_definitions_1["default"])(result.components, __assign(__assign({ outDir: "types", preamble: "" }, opts === null || opts === void 0 ? void 0 : opts.typesOptions), { exports: result.exports, inputDir: inputDir }));
181
+ (0, writer_ts_definitions_1.default)(result.components, __assign(__assign({ outDir: "types", preamble: "" }, opts === null || opts === void 0 ? void 0 : opts.typesOptions), { exports: result.exports, inputDir: inputDir }));
182
182
  }
183
183
  if (opts === null || opts === void 0 ? void 0 : opts.json) {
184
- (0, writer_json_1["default"])(result.components, __assign(__assign({ outFile: "COMPONENT_API.json" }, opts === null || opts === void 0 ? void 0 : opts.jsonOptions), { input: input, inputDir: inputDir }));
184
+ (0, writer_json_1.default)(result.components, __assign(__assign({ outFile: "COMPONENT_API.json" }, opts === null || opts === void 0 ? void 0 : opts.jsonOptions), { input: input, inputDir: inputDir }));
185
185
  }
186
186
  if (opts === null || opts === void 0 ? void 0 : opts.markdown) {
187
- (0, writer_markdown_1["default"])(result.components, __assign({ outFile: path.join(process.cwd(), "COMPONENT_INDEX.md") }, opts === null || opts === void 0 ? void 0 : opts.markdownOptions));
187
+ (0, writer_markdown_1.default)(result.components, __assign({ outFile: "COMPONENT_INDEX.md" }, opts === null || opts === void 0 ? void 0 : opts.markdownOptions));
188
188
  }
189
189
  }
190
190
  exports.writeOutput = writeOutput;
package/lib/sveld.js CHANGED
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- exports.__esModule = true;
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.sveld = void 0;
40
40
  var get_svelte_entry_1 = require("./get-svelte-entry");
41
41
  var rollup_plugin_1 = require("./rollup-plugin");
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  function verb(n) { return function (v) { return step([n, v]); }; }
38
38
  function step(op) {
39
39
  if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
41
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
42
  if (y = 0, t) op = [op[0] & 2, t.value];
43
43
  switch (op[0]) {
@@ -58,7 +58,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
58
58
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
59
  }
60
60
  };
61
- exports.__esModule = true;
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
62
  var path = __importStar(require("path"));
63
63
  var fsp = __importStar(require("fs/promises"));
64
64
  var prettier = __importStar(require("prettier"));
@@ -92,4 +92,4 @@ var Writer = /** @class */ (function () {
92
92
  };
93
93
  return Writer;
94
94
  }());
95
- exports["default"] = Writer;
95
+ exports.default = Writer;
@@ -1,9 +1,9 @@
1
1
  import Writer from "./Writer";
2
- declare type OnAppend = (type: AppendType, document: WriterMarkdown) => void;
2
+ type OnAppend = (type: AppendType, document: WriterMarkdown) => void;
3
3
  interface MarkdownOptions {
4
4
  onAppend?: OnAppend;
5
5
  }
6
- export declare type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw";
6
+ export type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw";
7
7
  interface TocLine {
8
8
  array: number[];
9
9
  raw: any;
@@ -17,7 +17,7 @@ var __extends = (this && this.__extends) || (function () {
17
17
  var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
- exports.__esModule = true;
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  var Writer_1 = __importDefault(require("./Writer"));
22
22
  var WriterMarkdown = /** @class */ (function (_super) {
23
23
  __extends(WriterMarkdown, _super);
@@ -49,7 +49,7 @@ var WriterMarkdown = /** @class */ (function (_super) {
49
49
  if (this.hasToC && type === "h2") {
50
50
  this.toc.push({
51
51
  array: Array.from({ length: (length_1 - 1) * 2 }),
52
- raw: raw
52
+ raw: raw,
53
53
  });
54
54
  }
55
55
  break;
@@ -87,5 +87,5 @@ var WriterMarkdown = /** @class */ (function (_super) {
87
87
  return this.source;
88
88
  };
89
89
  return WriterMarkdown;
90
- }(Writer_1["default"]));
91
- exports["default"] = WriterMarkdown;
90
+ }(Writer_1.default));
91
+ exports.default = WriterMarkdown;
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
29
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
30
  if (y = 0, t) op = [op[0] & 2, t.value];
31
31
  switch (op[0]) {
@@ -49,7 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
- exports.__esModule = true;
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
53
  var path_1 = __importDefault(require("path"));
54
54
  var path_2 = require("../path");
55
55
  var Writer_1 = __importDefault(require("./Writer"));
@@ -59,7 +59,7 @@ function writeJsonComponents(components, options) {
59
59
  return __generator(this, function (_a) {
60
60
  output = Array.from(components, function (_a) {
61
61
  var moduleName = _a[0], component = _a[1];
62
- return (__assign(__assign({}, component), { filePath: (0, path_2.normalizeSeparators)(path_1["default"].join(options.inputDir, path_1["default"].normalize(component.filePath))) }));
62
+ return (__assign(__assign({}, component), { filePath: (0, path_2.normalizeSeparators)(path_1.default.join(options.inputDir, path_1.default.normalize(component.filePath))) }));
63
63
  }).sort(function (a, b) {
64
64
  if (a.moduleName < b.moduleName)
65
65
  return -1;
@@ -68,8 +68,8 @@ function writeJsonComponents(components, options) {
68
68
  return 0;
69
69
  });
70
70
  output.map(function (c) {
71
- var outFile = path_1["default"].resolve(path_1["default"].join(options.outDir || "", "".concat(c.moduleName, ".api.json")));
72
- var writer = new Writer_1["default"]({ parser: "json", printWidth: 80 });
71
+ var outFile = path_1.default.resolve(path_1.default.join(options.outDir || "", "".concat(c.moduleName, ".api.json")));
72
+ var writer = new Writer_1.default({ parser: "json", printWidth: 80 });
73
73
  console.log("created ".concat(outFile, "\"\n"));
74
74
  return writer.write(outFile, JSON.stringify(c));
75
75
  });
@@ -87,17 +87,17 @@ function writeJsonLocal(components, options) {
87
87
  total: components.size,
88
88
  components: Array.from(components, function (_a) {
89
89
  var moduleName = _a[0], component = _a[1];
90
- return (__assign(__assign({}, component), { filePath: (0, path_2.normalizeSeparators)(path_1["default"].join(options.inputDir, path_1["default"].normalize(component.filePath))) }));
90
+ return (__assign(__assign({}, component), { filePath: (0, path_2.normalizeSeparators)(path_1.default.join(options.inputDir, path_1.default.normalize(component.filePath))) }));
91
91
  }).sort(function (a, b) {
92
92
  if (a.moduleName < b.moduleName)
93
93
  return -1;
94
94
  if (a.moduleName > b.moduleName)
95
95
  return 1;
96
96
  return 0;
97
- })
97
+ }),
98
98
  };
99
- output_path = path_1["default"].join(process.cwd(), options.outFile);
100
- writer = new Writer_1["default"]({ parser: "json", printWidth: 80 });
99
+ output_path = path_1.default.join(process.cwd(), options.outFile);
100
+ writer = new Writer_1.default({ parser: "json", printWidth: 80 });
101
101
  return [4 /*yield*/, writer.write(output_path, JSON.stringify(output))];
102
102
  case 1:
103
103
  _a.sent();
@@ -126,4 +126,4 @@ function writeJson(components, options) {
126
126
  });
127
127
  });
128
128
  }
129
- exports["default"] = writeJson;
129
+ exports.default = writeJson;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -14,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
37
  function verb(n) { return function (v) { return step([n, v]); }; }
15
38
  function step(op) {
16
39
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
41
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
42
  if (y = 0, t) op = [op[0] & 2, t.value];
20
43
  switch (op[0]) {
@@ -47,7 +70,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
47
70
  var __importDefault = (this && this.__importDefault) || function (mod) {
48
71
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
72
  };
50
- exports.__esModule = true;
73
+ Object.defineProperty(exports, "__esModule", { value: true });
74
+ var path = __importStar(require("path"));
51
75
  var WriterMarkdown_1 = __importDefault(require("./WriterMarkdown"));
52
76
  var writer_ts_definitions_1 = require("./writer-ts-definitions");
53
77
  var PROP_TABLE_HEADER = "| Prop name | Required | Kind | Reactive | Type | Default value | Description |\n| :- | :- | :- | :- |\n";
@@ -89,16 +113,16 @@ function formatEventDetail(detail) {
89
113
  }
90
114
  function writeMarkdown(components, options) {
91
115
  return __awaiter(this, void 0, void 0, function () {
92
- var write, document, keys;
116
+ var write, document, keys, outFile;
93
117
  return __generator(this, function (_a) {
94
118
  switch (_a.label) {
95
119
  case 0:
96
120
  write = (options === null || options === void 0 ? void 0 : options.write) !== false;
97
- document = new WriterMarkdown_1["default"]({
121
+ document = new WriterMarkdown_1.default({
98
122
  onAppend: function (type, document) {
99
123
  var _a;
100
124
  (_a = options.onAppend) === null || _a === void 0 ? void 0 : _a.call(null, type, document, components);
101
- }
125
+ },
102
126
  });
103
127
  document.append("h1", "Component Index");
104
128
  document.append("h2", "Components").tableOfContents();
@@ -109,7 +133,7 @@ function writeMarkdown(components, options) {
109
133
  document.append("h2", "`".concat(component.moduleName, "`"));
110
134
  if (component.typedefs.length > 0) {
111
135
  document.append("h3", "Types").append("raw", "```ts\n".concat((0, writer_ts_definitions_1.getTypeDefs)({
112
- typedefs: component.typedefs
136
+ typedefs: component.typedefs,
113
137
  }), "\n```\n\n"));
114
138
  }
115
139
  document.append("h3", "Props");
@@ -123,7 +147,7 @@ function writeMarkdown(components, options) {
123
147
  return 0;
124
148
  })
125
149
  .forEach(function (prop) {
126
- document.append("raw", "| ".concat(prop.name, " | ").concat(prop.isRequired ? 'Yes' : 'No', " | ").concat("<code>".concat(prop.kind, "</code>"), " | ").concat(prop.reactive ? "Yes" : "No", " | ").concat(formatPropType(prop.type), " | ").concat(formatPropValue(prop.value), " | ").concat(formatPropDescription(prop.description), " |\n"));
150
+ document.append("raw", "| ".concat(prop.name, " | ").concat(prop.isRequired ? "Yes" : "No", " | ").concat("<code>".concat(prop.kind, "</code>"), " | ").concat(prop.reactive ? "Yes" : "No", " | ").concat(formatPropType(prop.type), " | ").concat(formatPropValue(prop.value), " | ").concat(formatPropDescription(prop.description), " |\n"));
127
151
  });
128
152
  }
129
153
  else {
@@ -133,7 +157,7 @@ function writeMarkdown(components, options) {
133
157
  if (component.slots.length > 0) {
134
158
  document.append("raw", SLOT_TABLE_HEADER);
135
159
  component.slots.forEach(function (slot) {
136
- document.append("raw", "| ".concat(slot["default"] ? MD_TYPE_UNDEFINED : slot.name, " | ").concat(slot["default"] ? "Yes" : "No", " | ").concat(formatSlotProps(slot.slot_props), " | ").concat(formatSlotFallback(slot.fallback), " |\n"));
160
+ document.append("raw", "| ".concat(slot.default ? MD_TYPE_UNDEFINED : slot.name, " | ").concat(slot.default ? "Yes" : "No", " | ").concat(formatSlotProps(slot.slot_props), " | ").concat(formatSlotFallback(slot.fallback), " |\n"));
137
161
  });
138
162
  }
139
163
  else {
@@ -151,7 +175,8 @@ function writeMarkdown(components, options) {
151
175
  }
152
176
  });
153
177
  if (!write) return [3 /*break*/, 2];
154
- return [4 /*yield*/, document.write(options.outFile, document.end())];
178
+ outFile = path.join(process.cwd(), options.outFile);
179
+ return [4 /*yield*/, document.write(outFile, document.end())];
155
180
  case 1:
156
181
  _a.sent();
157
182
  console.log("created \"".concat(options.outFile, "\"."));
@@ -161,4 +186,4 @@ function writeMarkdown(components, options) {
161
186
  });
162
187
  });
163
188
  }
164
- exports["default"] = writeMarkdown;
189
+ exports.default = writeMarkdown;
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  function verb(n) { return function (v) { return step([n, v]); }; }
38
38
  function step(op) {
39
39
  if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
41
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
42
  if (y = 0, t) op = [op[0] & 2, t.value];
43
43
  switch (op[0]) {
@@ -79,13 +79,15 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
79
79
  var __importDefault = (this && this.__importDefault) || function (mod) {
80
80
  return (mod && mod.__esModule) ? mod : { "default": mod };
81
81
  };
82
- exports.__esModule = true;
82
+ Object.defineProperty(exports, "__esModule", { value: true });
83
83
  exports.writeTsDefinition = exports.getTypeDefs = exports.formatTsProps = void 0;
84
84
  var path = __importStar(require("path"));
85
85
  var create_exports_1 = require("../create-exports");
86
86
  var Writer_1 = __importDefault(require("./Writer"));
87
87
  var ANY_TYPE = "any";
88
88
  var EMPTY_STR = "";
89
+ // Svelte 4 is not compatible with `{}`
90
+ var EMPTY_EVENTS = "Record<string, any>";
89
91
  function formatTsProps(props) {
90
92
  if (props === undefined)
91
93
  return ANY_TYPE;
@@ -140,32 +142,31 @@ function genPropDef(def) {
140
142
  .split("|")
141
143
  .map(function (name) {
142
144
  var element = name.trim();
143
- if (element === "svg") {
144
- return "svelte.JSX.SVGAttributes<SVGSVGElement>";
145
- }
146
- return "svelte.JSX.HTMLAttributes<HTMLElementTagNameMap[\"".concat(element, "\"]>");
145
+ return "SvelteHTMLElements[\"".concat(element, "\"]");
147
146
  })
148
- .join(",");
147
+ .join("&");
149
148
  /**
150
149
  * Components that extend HTML elements should allow for `data-*` attributes.
151
150
  * @see https://github.com/sveltejs/language-tools/issues/1825
151
+ *
152
+ * Even though Svelte 4 does this automatically, we need to preserve this for Svelte 3.
152
153
  */
153
154
  var dataAttributes = "[key: `data-${string}`]: any;";
154
- prop_def = "\n export interface ".concat(props_name, " extends ").concat(def["extends"] !== undefined ? "".concat(def["extends"].interface, ", ") : "").concat(extend_tag_map, " {\n ").concat(props, "\n \n ").concat(dataAttributes, "\n }\n ");
155
+ prop_def = "\n ".concat(extend_tag_map ? "type RestProps = ".concat(extend_tag_map, ";\n") : "", "\n export interface ").concat(props_name, " extends ").concat(def.extends !== undefined ? "".concat(def.extends.interface, ", ") : "", "RestProps {\n ").concat(props, "\n \n ").concat(dataAttributes, "\n }\n ");
155
156
  }
156
157
  else {
157
- prop_def = "\n export interface ".concat(props_name, " ").concat(def["extends"] !== undefined ? "extends ".concat(def["extends"].interface) : "", " {\n ").concat(props, "\n }\n ");
158
+ prop_def = "\n export interface ".concat(props_name, " ").concat(def.extends !== undefined ? "extends ".concat(def.extends.interface) : "", " {\n ").concat(props, "\n }\n ");
158
159
  }
159
160
  return {
160
161
  props_name: props_name,
161
- prop_def: prop_def
162
+ prop_def: prop_def,
162
163
  };
163
164
  }
164
165
  function genSlotDef(def) {
165
166
  return def.slots
166
167
  .map(function (_a) {
167
168
  var name = _a.name, slot_props = _a.slot_props, rest = __rest(_a, ["name", "slot_props"]);
168
- var key = rest["default"] ? "default" : clampKey(name);
169
+ var key = rest.default ? "default" : clampKey(name);
169
170
  var description = rest.description ? "/** " + rest.description + " */\n" : "";
170
171
  return "".concat(description).concat(clampKey(key), ": ").concat(formatTsProps(slot_props), ";");
171
172
  })
@@ -184,7 +185,9 @@ function genEventDef(def) {
184
185
  return detail;
185
186
  return "CustomEvent<".concat(detail, ">");
186
187
  };
187
- return def.events
188
+ if (def.events.length === 0)
189
+ return EMPTY_EVENTS;
190
+ var events_map = def.events
188
191
  .map(function (event) {
189
192
  var description = "";
190
193
  if (event.type === "dispatched" && event.description) {
@@ -193,6 +196,7 @@ function genEventDef(def) {
193
196
  return "".concat(description).concat(clampKey(event.name), ": ").concat(event.type === "dispatched" ? createDispatchedEvent(event.detail) : "".concat(mapEvent(event.name), "[\"").concat(event.name, "\"]"), ";\n");
194
197
  })
195
198
  .join("");
199
+ return "{".concat(events_map, "}");
196
200
  }
197
201
  function genAccessors(def) {
198
202
  return def.props
@@ -205,9 +209,9 @@ function genAccessors(def) {
205
209
  .join("\n");
206
210
  }
207
211
  function genImports(def) {
208
- if (def["extends"] === undefined)
212
+ if (def.extends === undefined)
209
213
  return "";
210
- return "import type { ".concat(def["extends"].interface, " } from ").concat(def["extends"]["import"], ";");
214
+ return "import type { ".concat(def.extends.interface, " } from ").concat(def.extends.import, ";");
211
215
  }
212
216
  function genComponentComment(def) {
213
217
  if (!def.componentComment)
@@ -236,54 +240,58 @@ function genModuleExports(def) {
236
240
  .join("\n");
237
241
  }
238
242
  function writeTsDefinition(component) {
239
- var moduleName = component.moduleName, typedefs = component.typedefs, props = component.props, moduleExports = component.moduleExports, slots = component.slots, events = component.events, rest_props = component.rest_props, _extends = component["extends"], componentComment = component.componentComment;
243
+ var moduleName = component.moduleName, typedefs = component.typedefs, props = component.props, moduleExports = component.moduleExports, slots = component.slots, events = component.events, rest_props = component.rest_props, _extends = component.extends, componentComment = component.componentComment;
240
244
  var _a = genPropDef({
241
245
  moduleName: moduleName,
242
246
  props: props,
243
247
  rest_props: rest_props,
244
- "extends": _extends
248
+ extends: _extends,
245
249
  }), props_name = _a.props_name, prop_def = _a.prop_def;
246
- return "\n /// <reference types=\"svelte\" />\n import type { SvelteComponentTyped } from \"svelte\";\n ".concat(genImports({ "extends": _extends }), "\n ").concat(genModuleExports({ moduleExports: moduleExports }), "\n ").concat(getTypeDefs({ typedefs: typedefs }), "\n ").concat(prop_def, "\n ").concat(genComponentComment({ componentComment: componentComment }), "\n export default class ").concat(moduleName === "default" ? "" : moduleName, " extends SvelteComponentTyped<\n ").concat(props_name, ",\n {").concat(genEventDef({ events: events }), "},\n {").concat(genSlotDef({ slots: slots }), "}\n > {\n ").concat(genAccessors({ props: props }), "\n }");
250
+ return "\n import type { SvelteComponentTyped } from \"svelte\";".concat((rest_props === null || rest_props === void 0 ? void 0 : rest_props.type) === "Element" ? "import type { SvelteHTMLElements } from \"svelte/elements\";\n" : "", "\n ").concat(genImports({ extends: _extends }), "\n ").concat(genModuleExports({ moduleExports: moduleExports }), "\n ").concat(getTypeDefs({ typedefs: typedefs }), "\n ").concat(prop_def, "\n ").concat(genComponentComment({ componentComment: componentComment }), "\n export default class ").concat(moduleName === "default" ? "" : moduleName, " extends SvelteComponentTyped<\n ").concat(props_name, ",\n ").concat(genEventDef({ events: events }), ",\n {").concat(genSlotDef({ slots: slots }), "}\n > {\n ").concat(genAccessors({ props: props }), "\n }");
247
251
  }
248
252
  exports.writeTsDefinition = writeTsDefinition;
249
253
  function writeTsDefinitions(components, options) {
250
- var components_1, components_1_1;
251
- var e_1, _a;
254
+ var _a, components_1, components_1_1;
255
+ var _b, e_1, _c, _d;
252
256
  return __awaiter(this, void 0, void 0, function () {
253
- var ts_base_path, writer, indexDTs, _b, moduleName, component, ts_filepath, e_1_1;
254
- return __generator(this, function (_c) {
255
- switch (_c.label) {
257
+ var ts_base_path, writer, indexDTs, moduleName, component, ts_filepath, e_1_1;
258
+ return __generator(this, function (_e) {
259
+ switch (_e.label) {
256
260
  case 0:
257
261
  ts_base_path = path.join(process.cwd(), options.outDir, "index.d.ts");
258
- writer = new Writer_1["default"]({ parser: "typescript", printWidth: 80 });
262
+ writer = new Writer_1.default({ parser: "typescript", printWidth: 80 });
259
263
  indexDTs = options.preamble + (0, create_exports_1.createExports)(options.exports, components);
260
- _c.label = 1;
264
+ _e.label = 1;
261
265
  case 1:
262
- _c.trys.push([1, 7, 8, 13]);
263
- components_1 = __asyncValues(components);
264
- _c.label = 2;
266
+ _e.trys.push([1, 7, 8, 13]);
267
+ _a = true, components_1 = __asyncValues(components);
268
+ _e.label = 2;
265
269
  case 2: return [4 /*yield*/, components_1.next()];
266
270
  case 3:
267
- if (!(components_1_1 = _c.sent(), !components_1_1.done)) return [3 /*break*/, 6];
268
- _b = components_1_1.value, moduleName = _b[0], component = _b[1];
271
+ if (!(components_1_1 = _e.sent(), _b = components_1_1.done, !_b)) return [3 /*break*/, 6];
272
+ _d = components_1_1.value;
273
+ _a = false;
274
+ moduleName = _d[0], component = _d[1];
269
275
  ts_filepath = (0, create_exports_1.convertSvelteExt)(path.join(options.outDir, component.filePath));
270
276
  return [4 /*yield*/, writer.write(ts_filepath, writeTsDefinition(component))];
271
277
  case 4:
272
- _c.sent();
273
- _c.label = 5;
274
- case 5: return [3 /*break*/, 2];
278
+ _e.sent();
279
+ _e.label = 5;
280
+ case 5:
281
+ _a = true;
282
+ return [3 /*break*/, 2];
275
283
  case 6: return [3 /*break*/, 13];
276
284
  case 7:
277
- e_1_1 = _c.sent();
285
+ e_1_1 = _e.sent();
278
286
  e_1 = { error: e_1_1 };
279
287
  return [3 /*break*/, 13];
280
288
  case 8:
281
- _c.trys.push([8, , 11, 12]);
282
- if (!(components_1_1 && !components_1_1.done && (_a = components_1["return"]))) return [3 /*break*/, 10];
283
- return [4 /*yield*/, _a.call(components_1)];
289
+ _e.trys.push([8, , 11, 12]);
290
+ if (!(!_a && !_b && (_c = components_1.return))) return [3 /*break*/, 10];
291
+ return [4 /*yield*/, _c.call(components_1)];
284
292
  case 9:
285
- _c.sent();
286
- _c.label = 10;
293
+ _e.sent();
294
+ _e.label = 10;
287
295
  case 10: return [3 /*break*/, 12];
288
296
  case 11:
289
297
  if (e_1) throw e_1.error;
@@ -291,11 +299,11 @@ function writeTsDefinitions(components, options) {
291
299
  case 12: return [7 /*endfinally*/];
292
300
  case 13: return [4 /*yield*/, writer.write(ts_base_path, indexDTs)];
293
301
  case 14:
294
- _c.sent();
302
+ _e.sent();
295
303
  console.log("created TypeScript definitions.");
296
304
  return [2 /*return*/];
297
305
  }
298
306
  });
299
307
  });
300
308
  }
301
- exports["default"] = writeTsDefinitions;
309
+ exports.default = writeTsDefinitions;
package/package.json CHANGED
@@ -1,43 +1,35 @@
1
1
  {
2
2
  "name": "sveld",
3
- "version": "0.18.1",
3
+ "version": "0.19.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Generate TypeScript definitions for your Svelte components.",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "scripts": {
9
- "dev": "vite",
10
- "build": "vite build",
11
- "preview": "vite preview",
12
9
  "test:unit": "vitest -r tests",
13
10
  "test:snapshot": "node tests/test-snapshot",
14
11
  "test:integration": "node tests/test-integration",
15
- "format": "prettier --write \"{src,tests}/**/*.{js,ts,svelte,md}\"",
12
+ "format": "prettier --write \"{src,tests,playground}/**/*.{js,ts,svelte,md}\" --ignore-path \".gitignore\"",
16
13
  "prepack": "tsc"
17
14
  },
18
15
  "dependencies": {
19
16
  "@rollup/plugin-node-resolve": "^13.2.1",
20
17
  "acorn": "^8.8.0",
21
- "comment-parser": "^1.3.1",
22
- "fast-glob": "^3.2.12",
23
- "prettier": "^2.6.2",
18
+ "comment-parser": "^1.4.0",
19
+ "fast-glob": "^3.3.1",
20
+ "prettier": "^2.8.8",
24
21
  "rollup": "^2.70.2",
25
- "rollup-plugin-svelte": "^7.1.0",
26
- "svelte": "^3.52.0",
27
- "svelte-preprocess": "^4.10.6",
28
- "typescript": "^4.8.4"
22
+ "rollup-plugin-svelte": "^7.1.6",
23
+ "svelte": "^4.1.2",
24
+ "svelte-preprocess": "^5.0.4",
25
+ "typescript": "^5.1.6"
29
26
  },
30
27
  "devDependencies": {
31
- "@sveltejs/vite-plugin-svelte": "1.0.9",
32
- "@types/node": "^18.11.0",
33
- "@types/prettier": "^2.7.1",
34
- "carbon-components-svelte": "^0.70.12",
35
- "carbon-preprocess-svelte": "^0.9.1",
36
- "codemirror": "5.65.5",
28
+ "@types/node": "^20.4.9",
29
+ "@types/prettier": "^2.7.3",
37
30
  "prettier-plugin-svelte": "^2.8.0",
38
- "svelte-highlight": "^6.2.1",
39
- "vite": "^3.1.8",
40
- "vitest": "^0.24.3"
31
+ "vite": "^3.2.3",
32
+ "vitest": "^0.34.1"
41
33
  },
42
34
  "bin": {
43
35
  "sveld": "./cli.js"