sveld 0.16.1 → 0.17.2
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 +12 -0
- package/README.md +1 -32
- package/lib/ComponentParser.js +7 -6
- package/lib/writer/writer-ts-definitions.js +7 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,18 @@ 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.17.2](https://github.com/carbon-design-system/sveld/releases/tag/v0.17.2) - 2022-06-13
|
|
14
|
+
|
|
15
|
+
- handle `export {}` in script block
|
|
16
|
+
|
|
17
|
+
## [0.17.1](https://github.com/carbon-design-system/sveld/releases/tag/v0.17.1) - 2022-06-02
|
|
18
|
+
|
|
19
|
+
- use correct type for forwarded cut/copy/paste events
|
|
20
|
+
|
|
21
|
+
## [0.17.0](https://github.com/carbon-design-system/sveld/releases/tag/v0.17.0) - 2022-05-21
|
|
22
|
+
|
|
23
|
+
- remove `@required` tag; directly infer if a prop is required
|
|
24
|
+
|
|
13
25
|
## [0.16.1](https://github.com/carbon-design-system/sveld/releases/tag/v0.16.1) - 2022-05-20
|
|
14
26
|
|
|
15
27
|
- `additional_tags` can be `undefined`
|
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ The generated definition extends the official `SvelteComponentTyped` interface e
|
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
41
|
/// <reference types="svelte" />
|
|
42
|
-
import { SvelteComponentTyped } from "svelte";
|
|
42
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
43
43
|
|
|
44
44
|
export interface ButtonProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["button"]> {
|
|
45
45
|
/**
|
|
@@ -115,7 +115,6 @@ export default class Button extends SvelteComponentTyped<
|
|
|
115
115
|
- [API Reference](#api-reference)
|
|
116
116
|
- [@type](#type)
|
|
117
117
|
- [@typedef](#typedef)
|
|
118
|
-
- [@required](#required)
|
|
119
118
|
- [@slot](#slot)
|
|
120
119
|
- [@event](#event)
|
|
121
120
|
- [@restProps](#restprops)
|
|
@@ -351,36 +350,6 @@ export let author = {};
|
|
|
351
350
|
export let authors = [];
|
|
352
351
|
```
|
|
353
352
|
|
|
354
|
-
### `@required`
|
|
355
|
-
|
|
356
|
-
By default, all props are typed as optional.
|
|
357
|
-
|
|
358
|
-
Use the `@required` tag to denote a component prop as required.
|
|
359
|
-
|
|
360
|
-
Example:
|
|
361
|
-
|
|
362
|
-
```js
|
|
363
|
-
/**
|
|
364
|
-
* This prop is required
|
|
365
|
-
* @required
|
|
366
|
-
*/
|
|
367
|
-
export let isRequired = true;
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
TypeScript output:
|
|
371
|
-
|
|
372
|
-
```ts
|
|
373
|
-
export interface ComponentProps {
|
|
374
|
-
/**
|
|
375
|
-
* This prop is required
|
|
376
|
-
* @default true
|
|
377
|
-
*/
|
|
378
|
-
isRequired: boolean;
|
|
379
|
-
}
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
Because `@required` is non-standard JSDoc tag, it is omitted from the prop comment in the TypeScript definitions.
|
|
383
|
-
|
|
384
353
|
### `@slot`
|
|
385
354
|
|
|
386
355
|
Use the `@slot` tag for typing component slots. Note that `@slot` is a non-standard JSDoc tag.
|
package/lib/ComponentParser.js
CHANGED
|
@@ -325,6 +325,10 @@ var ComponentParser = /** @class */ (function () {
|
|
|
325
325
|
_this.vars.add(node);
|
|
326
326
|
}
|
|
327
327
|
if (node.type === "ExportNamedDeclaration") {
|
|
328
|
+
// Handle export {}
|
|
329
|
+
if (node.declaration == null && node.specifiers.length === 0) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
328
332
|
// Handle renamed exports
|
|
329
333
|
var prop_name = void 0;
|
|
330
334
|
if (node.declaration == null && ((_a = node.specifiers[0]) === null || _a === void 0 ? void 0 : _a.type) === "ExportSpecifier") {
|
|
@@ -349,7 +353,7 @@ var ComponentParser = /** @class */ (function () {
|
|
|
349
353
|
var description_1 = undefined;
|
|
350
354
|
var isFunction = false;
|
|
351
355
|
var isFunctionDeclaration = false;
|
|
352
|
-
var
|
|
356
|
+
var isRequired = kind === "let" && init == null;
|
|
353
357
|
if (init != null) {
|
|
354
358
|
if (init.type === "ObjectExpression" ||
|
|
355
359
|
init.type === "BinaryExpression" ||
|
|
@@ -396,10 +400,7 @@ var ComponentParser = /** @class */ (function () {
|
|
|
396
400
|
description_1 = "";
|
|
397
401
|
}
|
|
398
402
|
additional_tags.forEach(function (tag) {
|
|
399
|
-
|
|
400
|
-
if (!isRequired_1) {
|
|
401
|
-
description_1 += "".concat(description_1 ? "\n" : "", "@").concat(tag.tag, " ").concat(tag.name).concat(tag.description ? " ".concat(tag.description) : "");
|
|
402
|
-
}
|
|
403
|
+
description_1 += "".concat(description_1 ? "\n" : "", "@").concat(tag.tag, " ").concat(tag.name).concat(tag.description ? " ".concat(tag.description) : "");
|
|
403
404
|
});
|
|
404
405
|
}
|
|
405
406
|
if (!description_1 && _this.typedefs.has(type)) {
|
|
@@ -413,7 +414,7 @@ var ComponentParser = /** @class */ (function () {
|
|
|
413
414
|
value: value,
|
|
414
415
|
isFunction: isFunction,
|
|
415
416
|
isFunctionDeclaration: isFunctionDeclaration,
|
|
416
|
-
isRequired:
|
|
417
|
+
isRequired: isRequired,
|
|
417
418
|
constant: kind === "const",
|
|
418
419
|
reactive: _this.reactive_vars.has(prop_name)
|
|
419
420
|
});
|
|
@@ -178,6 +178,12 @@ function genSlotDef(def) {
|
|
|
178
178
|
})
|
|
179
179
|
.join("\n");
|
|
180
180
|
}
|
|
181
|
+
var mapEvent = function (name) {
|
|
182
|
+
if (["cut", "copy", "paste"].includes(name)) {
|
|
183
|
+
return "DocumentAndElementEventHandlersEventMap";
|
|
184
|
+
}
|
|
185
|
+
return "WindowEventMap";
|
|
186
|
+
};
|
|
181
187
|
function genEventDef(def) {
|
|
182
188
|
var createDispatchedEvent = function (detail) {
|
|
183
189
|
if (detail === void 0) { detail = ANY_TYPE; }
|
|
@@ -187,7 +193,7 @@ function genEventDef(def) {
|
|
|
187
193
|
};
|
|
188
194
|
return def.events
|
|
189
195
|
.map(function (event) {
|
|
190
|
-
return "".concat(clampKey(event.name), ": ").concat(event.type === "dispatched" ? createDispatchedEvent(event.detail) : "
|
|
196
|
+
return "".concat(clampKey(event.name), ": ").concat(event.type === "dispatched" ? createDispatchedEvent(event.detail) : "".concat(mapEvent(event.name), "[\"").concat(event.name, "\"]"), ";");
|
|
191
197
|
})
|
|
192
198
|
.join("\n");
|
|
193
199
|
}
|