sveld 0.13.1 → 0.13.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 CHANGED
@@ -5,10 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## Unreleased
8
+ <!-- ## Unreleased
9
9
 
10
10
  - add isAccessor field to API
11
- - update Markdown writer to generate a separate table for accessors
11
+ - update Markdown writer to generate a separate table for accessors -->
12
+
13
+ ## [0.13.2](https://github.com/carbon-design-system/sveld/releases/tag/v0.13.2) - 2022-02-10
14
+
15
+ - do not wrap TS `@event` detail in `CustomEvent` if type contains `CustomEvent`
12
16
 
13
17
  ## [0.13.1](https://github.com/carbon-design-system/sveld/releases/tag/v0.13.1) - 2022-01-22
14
18
 
package/README.md CHANGED
@@ -107,7 +107,8 @@ export default class Button extends SvelteComponentTyped<
107
107
  - [Approach](#approach)
108
108
  - [Usage](#usage)
109
109
  - [Installation](#installation)
110
- - [Set-up with Rollup](#set-up-with-rollup)
110
+ - [Rollup](#rollup)
111
+ - [Node.js](#nodejs)
111
112
  - [CLI](#cli)
112
113
  - [Publishing to NPM](#publishing-to-npm)
113
114
  - [Available Options](#available-options)
@@ -118,14 +119,15 @@ export default class Button extends SvelteComponentTyped<
118
119
  - [@event](#event)
119
120
  - [@restProps](#restprops)
120
121
  - [@extends](#extends)
122
+ - [@component comments](#component-comments)
121
123
  - [Contributing](#contributing)
122
124
  - [License](#license)
123
125
 
124
126
  ## Approach
125
127
 
126
- sveld uses the Svelte compiler to statically analyze all Svelte components exported from a library to generate documentation that is useful for the end user.
128
+ `sveld` uses the Svelte compiler to statically analyze Svelte components exported from a library to generate documentation useful to the end user.
127
129
 
128
- Extracted metadata:
130
+ Extracted metadata include:
129
131
 
130
132
  - props
131
133
  - slots
@@ -133,7 +135,7 @@ Extracted metadata:
133
135
  - dispatched events
134
136
  - `$$restProps`
135
137
 
136
- 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.
138
+ 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.
137
139
 
138
140
  The generated TypeScript definitions for a component extends the `SvelteComponentTyped` interface available in svelte version 3.31.
139
141
 
@@ -147,6 +149,8 @@ Install `sveld` as a development dependency.
147
149
  yarn add -D sveld
148
150
  # OR
149
151
  npm i -D sveld
152
+ # OR
153
+ pnpm i -D sveld
150
154
  ```
151
155
 
152
156
  ### Rollup
@@ -169,7 +173,19 @@ export default {
169
173
  };
170
174
  ```
171
175
 
172
- When building the library with Rollup, TypeScript definitions will be written to the `types` folder.
176
+ When building the library with Rollup, TypeScript definitions will be written to the `types` folder by default.
177
+
178
+ Use the `typesOptions.outDir` option to customize the output folder.
179
+
180
+ For example, specify the following for the output to be emitted to the `dist` folder:
181
+
182
+ ```diff
183
+ sveld({
184
+ + typesOptions: {
185
+ + outDir: 'dist'
186
+ + }
187
+ })
188
+ ```
173
189
 
174
190
  The [integration](integration) folder contains example set-ups:
175
191
 
@@ -255,7 +271,7 @@ sveld({
255
271
 
256
272
  ### `@type`
257
273
 
258
- Without a `@type` annotation, sveld will infer the primitive type for a prop:
274
+ Without a `@type` annotation, `sveld` will infer the primitive type for a prop:
259
275
 
260
276
  ```js
261
277
  export let kind = "primary";
@@ -318,7 +334,7 @@ export let authors = [];
318
334
 
319
335
  ### `@slot`
320
336
 
321
- Use the `@slot` tag for typing component slots.
337
+ Use the `@slot` tag for typing component slots. Note that `@slot` is a non-standard JSDoc tag.
322
338
 
323
339
  Signature:
324
340
 
@@ -379,9 +395,9 @@ $: dispatch("button:key", { key });
379
395
 
380
396
  ### `@restProps`
381
397
 
382
- sveld can pick up inline HTML elements that `$$restProps` is forwarded to. However, it cannot infer the underlying element for instantiated components.
398
+ `sveld` can pick up inline HTML elements that `$$restProps` is forwarded to. However, it cannot infer the underlying element for instantiated components.
383
399
 
384
- You can use the `@restProps` tag to explicitly define element tags that `$$restProps` is forwarded to.
400
+ You can use the `@restProps` tag to specify the element tags that `$$restProps` is forwarded to.
385
401
 
386
402
  Signature:
387
403
 
@@ -134,9 +134,15 @@ function genSlotDef(def) {
134
134
  .join("\n");
135
135
  }
136
136
  function genEventDef(def) {
137
+ var createDispatchedEvent = function (detail) {
138
+ if (detail === void 0) { detail = ANY_TYPE; }
139
+ if (/CustomEvent/.test(detail))
140
+ return detail;
141
+ return "CustomEvent<".concat(detail, ">");
142
+ };
137
143
  return def.events
138
144
  .map(function (event) {
139
- return "".concat(clampKey(event.name), ": ").concat(event.type === "dispatched" ? "CustomEvent<".concat(event.detail || ANY_TYPE, ">") : "WindowEventMap[\"".concat(event.name, "\"]"), ";");
145
+ return "".concat(clampKey(event.name), ": ").concat(event.type === "dispatched" ? createDispatchedEvent(event.detail) : "WindowEventMap[\"".concat(event.name, "\"]"), ";");
140
146
  })
141
147
  .join("\n");
142
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveld",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Generate TypeScript definitions for your Svelte components.",
6
6
  "main": "./lib/index.js",