sveld 0.19.2 → 0.20.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 CHANGED
@@ -122,6 +122,7 @@ export default class Button extends SvelteComponentTyped<
122
122
  - [@event](#event)
123
123
  - [@restProps](#restprops)
124
124
  - [@extends](#extends)
125
+ - [@generics](#generics)
125
126
  - [@component comments](#component-comments)
126
127
  - [Contributing](#contributing)
127
128
  - [License](#license)
@@ -147,11 +148,17 @@ This library adopts a progressively enhanced approach. Any property type that ca
147
148
  Install `sveld` as a development dependency.
148
149
 
149
150
  ```sh
150
- yarn add -D sveld
151
- # OR
151
+ # npm
152
152
  npm i -D sveld
153
- # OR
153
+
154
+ # pnpm
154
155
  pnpm i -D sveld
156
+
157
+ # Bun
158
+ bun i -D sveld
159
+
160
+ # Yarn
161
+ yarn add -D sveld
155
162
  ```
156
163
 
157
164
  ### Rollup
@@ -188,15 +195,15 @@ sveld({
188
195
  })
189
196
  ```
190
197
 
191
- The [integration](integration) folder contains example set-ups:
198
+ The [tests/e2e](tests/e2e) folder contains example set-ups:
192
199
 
193
- - [single-export](integration/single-export): library that exports one component
194
- - [single-export-default-only](integration/single-export-default-only): library that exports one component using the concise `export { default } ...` syntax
195
- - [multi-export](integration/multi-export): multi-component library without JSDoc annotations (types are inferred)
196
- - [multi-export-typed](integration/multi-export-typed): multi-component library with JSDoc annotations
197
- - [multi-export-typed-ts-only](integration/multi-export-typed-ts-only): multi-component library that only generates TS definitions
198
- - [glob](integration/glob): library that uses the glob strategy to collect/analyze \*.svelte files
199
- - [carbon](integration/carbon): full `carbon-components-svelte` example
200
+ - [single-export](tests/e2e/single-export): library that exports one component
201
+ - [single-export-default-only](tests/e2e/single-export-default-only): library that exports one component using the concise `export { default } ...` syntax
202
+ - [multi-export](tests/e2e/multi-export): multi-component library without JSDoc annotations (types are inferred)
203
+ - [multi-export-typed](tests/e2e/multi-export-typed): multi-component library with JSDoc annotations
204
+ - [multi-export-typed-ts-only](tests/e2e/multi-export-typed-ts-only): multi-component library that only generates TS definitions
205
+ - [glob](tests/e2e/glob): library that uses the glob strategy to collect/analyze \*.svelte files
206
+ - [carbon](tests/e2e/carbon): full `carbon-components-svelte` example
200
207
 
201
208
  ### CLI
202
209
 
@@ -496,6 +503,45 @@ export const secondary = true;
496
503
  import Button from "./Button.svelte";
497
504
  ```
498
505
 
506
+ ### `@generics`
507
+
508
+ Currently, to define generics for a Svelte component, you must use [`generics` attribute](https://github.com/dummdidumm/rfcs/blob/bfb14dc56a70ec6ddafebf2242b8e1500e06a032/text/ts-typing-props-slots-events.md#generics) on the script tag. Note that this feature is [experimental](https://svelte.dev/docs/typescript#experimental-advanced-typings) and may change in the future.
509
+
510
+ However, the `generics` attribute only works if using `lang="ts"`; the language server will produce an error if `generics` is used without specifying `lang="ts"`.
511
+
512
+ ```svelte
513
+ <!-- This causes an error because `lang="ts"` must be used. -->
514
+ <script generics="Row extends DataTableRow = any"></script>
515
+ ```
516
+
517
+ Because `sveld` is designed to support JavaScript-only usage as a baseline, the API design to specify generics uses a custom JSDoc tag `@generics`.
518
+
519
+ Signature:
520
+
521
+ ```js
522
+ /**
523
+ * @generics {GenericParameter} GenericName
524
+ */
525
+ ```
526
+
527
+ Example
528
+
529
+ ```js
530
+ /**
531
+ * @generics {Row extends DataTableRow = any} Row
532
+ */
533
+ ```
534
+
535
+ The generated TypeScript definition will resemble the following:
536
+
537
+ ```ts
538
+ export default class Component<Row extends DataTableRow = any> extends SvelteComponentTyped<
539
+ ComponentProps<Row>,
540
+ Record<string, any>,
541
+ Record<string, any>
542
+ > {}
543
+ ```
544
+
499
545
  ### `@component` comments
500
546
 
501
547
  The Svelte Language Server supports component-level comments through the following syntax: `<!-- @component [comment] -->`.
@@ -42,6 +42,7 @@ interface TypeDef {
42
42
  description?: string;
43
43
  ts: string;
44
44
  }
45
+ type ComponentGenerics = [name: string, type: string];
45
46
  interface ComponentInlineElement {
46
47
  type: "InlineComponent";
47
48
  name: string;
@@ -61,6 +62,7 @@ export interface ParsedComponent {
61
62
  slots: ComponentSlot[];
62
63
  events: ComponentEvent[];
63
64
  typedefs: TypeDef[];
65
+ generics: null | ComponentGenerics;
64
66
  rest_props: RestProps;
65
67
  extends?: Extends;
66
68
  componentComment?: string;
@@ -80,6 +82,7 @@ export default class ComponentParser {
80
82
  private readonly slots;
81
83
  private readonly events;
82
84
  private readonly typedefs;
85
+ private readonly generics;
83
86
  private readonly bindings;
84
87
  constructor(options?: ComponentParserOptions);
85
88
  private static mapToArray;