sveld 0.20.3 → 0.22.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 +12 -6
- package/lib/writer/Writer.d.ts +1 -1
- package/lib/writer/Writer.js +4 -3
- package/lib/writer/writer-ts-definitions.js +6 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -41,9 +41,9 @@ The generated definition extends the official `SvelteComponentTyped` interface e
|
|
|
41
41
|
import type { SvelteComponentTyped } from "svelte";
|
|
42
42
|
import type { SvelteHTMLElements } from "svelte/elements";
|
|
43
43
|
|
|
44
|
-
type RestProps = SvelteHTMLElements["button"];
|
|
44
|
+
type $RestProps = SvelteHTMLElements["button"];
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
type $Props = {
|
|
47
47
|
/**
|
|
48
48
|
* @default "button"
|
|
49
49
|
*/
|
|
@@ -53,7 +53,11 @@ export interface ButtonProps extends RestProps {
|
|
|
53
53
|
* @default false
|
|
54
54
|
*/
|
|
55
55
|
primary?: boolean;
|
|
56
|
-
|
|
56
|
+
|
|
57
|
+
[key: `data-${string}`]: any;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type ButtonProps = Omit<$RestProps, keyof $Props> & $Props;
|
|
57
61
|
|
|
58
62
|
export default class Button extends SvelteComponentTyped<
|
|
59
63
|
ButtonProps,
|
|
@@ -81,9 +85,9 @@ The accompanying JSDoc annotations would generate the following:
|
|
|
81
85
|
```ts
|
|
82
86
|
import type { SvelteHTMLElements } from "svelte/elements";
|
|
83
87
|
|
|
84
|
-
type RestProps = SvelteHTMLElements["button"];
|
|
88
|
+
type $RestProps = SvelteHTMLElements["button"];
|
|
85
89
|
|
|
86
|
-
|
|
90
|
+
type $Props = {
|
|
87
91
|
/**
|
|
88
92
|
* @default "button"
|
|
89
93
|
*/
|
|
@@ -94,7 +98,9 @@ export interface ButtonProps extends RestProps {
|
|
|
94
98
|
* @default false
|
|
95
99
|
*/
|
|
96
100
|
primary?: boolean;
|
|
97
|
-
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type ButtonProps = Omit<$RestProps, keyof $Props> & $Props;
|
|
98
104
|
|
|
99
105
|
export default class Button extends SvelteComponentTyped<
|
|
100
106
|
ButtonProps,
|
package/lib/writer/Writer.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ interface WriterOptions extends Pick<prettier.ParserOptions, "parser" | "printWi
|
|
|
4
4
|
export default class Writer {
|
|
5
5
|
options: WriterOptions;
|
|
6
6
|
constructor(options: WriterOptions);
|
|
7
|
-
format(raw: any): any
|
|
7
|
+
format(raw: any): Promise<any>;
|
|
8
8
|
write(filePath: string, raw: any): Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
export {};
|
package/lib/writer/Writer.js
CHANGED
|
@@ -31,9 +31,10 @@ class Writer {
|
|
|
31
31
|
constructor(options) {
|
|
32
32
|
this.options = options;
|
|
33
33
|
}
|
|
34
|
-
format(raw) {
|
|
34
|
+
async format(raw) {
|
|
35
35
|
try {
|
|
36
|
-
|
|
36
|
+
const result = await prettier.format(raw, this.options);
|
|
37
|
+
return result;
|
|
37
38
|
}
|
|
38
39
|
catch (error) {
|
|
39
40
|
console.error(error);
|
|
@@ -42,7 +43,7 @@ class Writer {
|
|
|
42
43
|
}
|
|
43
44
|
async write(filePath, raw) {
|
|
44
45
|
await fsp.mkdir(path.parse(filePath).dir, { recursive: true });
|
|
45
|
-
await fsp.writeFile(filePath, this.format(raw));
|
|
46
|
+
await fsp.writeFile(filePath, await this.format(raw));
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
exports.default = Writer;
|
|
@@ -101,17 +101,19 @@ function genPropDef(def) {
|
|
|
101
101
|
*/
|
|
102
102
|
const dataAttributes = "[key: `data-${string}`]: any;";
|
|
103
103
|
prop_def = `
|
|
104
|
-
${extend_tag_map ? `type RestProps = ${extend_tag_map};\n` : ""}
|
|
105
|
-
|
|
104
|
+
${extend_tag_map ? `type $RestProps = ${extend_tag_map};\n` : ""}
|
|
105
|
+
type $Props${genericsName} = {
|
|
106
106
|
${props}
|
|
107
107
|
|
|
108
108
|
${dataAttributes}
|
|
109
|
-
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export type ${props_name}${genericsName} = Omit<$RestProps, keyof $Props${genericsName}> & $Props${genericsName};
|
|
110
112
|
`;
|
|
111
113
|
}
|
|
112
114
|
else {
|
|
113
115
|
prop_def = `
|
|
114
|
-
export
|
|
116
|
+
export type ${props_name}${genericsName} = ${def.extends !== undefined ? `${def.extends.interface} & ` : ""} {
|
|
115
117
|
${props}
|
|
116
118
|
}
|
|
117
119
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sveld",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Generate TypeScript definitions for your Svelte components.",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
17
17
|
"acorn": "^8.12.1",
|
|
18
18
|
"comment-parser": "^1.4.1",
|
|
19
|
-
"prettier": "^
|
|
19
|
+
"prettier": "^3.3.3",
|
|
20
20
|
"rollup": "^2.79.1",
|
|
21
21
|
"rollup-plugin-svelte": "^7.2.2",
|
|
22
22
|
"svelte": "^4.2.19",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/bun": "^1.1.12",
|
|
29
29
|
"@types/jest": "^29.5.13",
|
|
30
|
-
"@types/prettier": "^
|
|
31
|
-
"prettier-plugin-svelte": "^2.
|
|
30
|
+
"@types/prettier": "^3.0.0",
|
|
31
|
+
"prettier-plugin-svelte": "^3.2.7"
|
|
32
32
|
},
|
|
33
33
|
"bin": {
|
|
34
34
|
"sveld": "cli.js"
|