sveld 0.13.4 → 0.14.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/CHANGELOG.md +5 -0
- package/LICENSE +1 -1
- package/README.md +4 -3
- package/cli.js +1 -1
- package/lib/ComponentParser.d.ts +3 -2
- package/lib/ComponentParser.js +78 -72
- package/lib/get-svelte-entry.js +4 -4
- package/lib/rollup-plugin.js +4 -3
- package/lib/writer/Writer.js +6 -13
- package/lib/writer/writer-json.js +1 -1
- package/lib/writer/writer-markdown.d.ts +2 -1
- package/lib/writer/writer-markdown.js +7 -6
- package/lib/writer/writer-ts-definitions.js +19 -8
- package/package.json +25 -26
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,11 @@ 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.14.0](https://github.com/carbon-design-system/sveld/releases/tag/v0.14.0) - 2022-04-09
|
|
14
|
+
|
|
15
|
+
- add `sveltekit:prefetch`, `sveltekit:noscroll` attributes to props that extend `a` attributes
|
|
16
|
+
- use type-only imports for `SvelteComponentTyped` and extended props
|
|
17
|
+
|
|
13
18
|
## [0.13.4](https://github.com/carbon-design-system/sveld/releases/tag/v0.13.4) - 2022-02-26
|
|
14
19
|
|
|
15
20
|
- use file name as module name if library only has a single default export
|
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2020 IBM
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -173,11 +173,11 @@ export default {
|
|
|
173
173
|
};
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
When building the library
|
|
176
|
+
When building the library, TypeScript definitions are emitted to the `types` folder by default.
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
Customize the output folder using the `typesOptions.outDir` option.
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
The following example emits the output to the `dist` folder:
|
|
181
181
|
|
|
182
182
|
```diff
|
|
183
183
|
sveld({
|
|
@@ -190,6 +190,7 @@ sveld({
|
|
|
190
190
|
The [integration](integration) folder contains example set-ups:
|
|
191
191
|
|
|
192
192
|
- [single-export](integration/single-export): library that exports one component
|
|
193
|
+
- [single-export-default-only](integration/single-export-default-only): library that exports one component using the concise `export { default } ...` syntax
|
|
193
194
|
- [multi-export](integration/multi-export): multi-component library without JSDoc annotations (types are inferred)
|
|
194
195
|
- [multi-export-typed](integration/multi-export-typed): multi-component library with JSDoc annotations
|
|
195
196
|
- [multi-export-typed-ts-only](integration/multi-export-typed-ts-only): multi-component library that only generates TS definitions
|
package/cli.js
CHANGED
package/lib/ComponentParser.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as commentParser from "comment-parser";
|
|
2
1
|
interface ComponentParserDiagnostics {
|
|
3
2
|
moduleName: string;
|
|
4
3
|
filePath: string;
|
|
@@ -34,7 +33,9 @@ interface DispatchedEvent {
|
|
|
34
33
|
detail?: any;
|
|
35
34
|
}
|
|
36
35
|
declare type ComponentEvent = ForwardedEvent | DispatchedEvent;
|
|
37
|
-
interface TypeDef
|
|
36
|
+
interface TypeDef {
|
|
37
|
+
type: string;
|
|
38
|
+
name: string;
|
|
38
39
|
description?: string;
|
|
39
40
|
ts: string;
|
|
40
41
|
}
|
package/lib/ComponentParser.js
CHANGED
|
@@ -132,7 +132,7 @@ var ComponentParser = /** @class */ (function () {
|
|
|
132
132
|
};
|
|
133
133
|
ComponentParser.prototype.parseCustomTypes = function () {
|
|
134
134
|
var _this = this;
|
|
135
|
-
commentParser(this.source).forEach(function (_a) {
|
|
135
|
+
commentParser.parse(this.source, { spacing: "preserve" }).forEach(function (_a) {
|
|
136
136
|
var tags = _a.tags;
|
|
137
137
|
tags.forEach(function (_a) {
|
|
138
138
|
var tag = _a.tag, tagType = _a.type, name = _a.name, description = _a.description;
|
|
@@ -185,9 +185,9 @@ var ComponentParser = /** @class */ (function () {
|
|
|
185
185
|
};
|
|
186
186
|
ComponentParser.prototype.parseSvelteComponent = function (source, diagnostics) {
|
|
187
187
|
var _this = this;
|
|
188
|
-
var _a, _b;
|
|
188
|
+
var _a, _b, _c;
|
|
189
189
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.verbose) {
|
|
190
|
-
|
|
190
|
+
console.log("[parsing] \"".concat(diagnostics.moduleName, "\" ").concat(diagnostics.filePath));
|
|
191
191
|
}
|
|
192
192
|
this.cleanup();
|
|
193
193
|
this.source = source;
|
|
@@ -195,80 +195,84 @@ var ComponentParser = /** @class */ (function () {
|
|
|
195
195
|
this.parsed = (0, compiler_1.parse)(source);
|
|
196
196
|
this.collectReactiveVars();
|
|
197
197
|
this.parseCustomTypes();
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (init
|
|
212
|
-
init.type === "
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (
|
|
220
|
-
type
|
|
198
|
+
if ((_b = this.parsed) === null || _b === void 0 ? void 0 : _b.module) {
|
|
199
|
+
(0, compiler_1.walk)((_c = this.parsed) === null || _c === void 0 ? void 0 : _c.module, {
|
|
200
|
+
enter: function (node) {
|
|
201
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
202
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
203
|
+
var _j = ((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) ? node.declaration.declarations[0] : node.declaration, declaration_type = _j.type, id = _j.id, init = _j.init, body = _j.body;
|
|
204
|
+
var prop_name = id.name;
|
|
205
|
+
var value = undefined;
|
|
206
|
+
var type = undefined;
|
|
207
|
+
var kind = node.declaration.kind;
|
|
208
|
+
var description = undefined;
|
|
209
|
+
var isFunction = false;
|
|
210
|
+
var isFunctionDeclaration = false;
|
|
211
|
+
if (init != null) {
|
|
212
|
+
if (init.type === "ObjectExpression" ||
|
|
213
|
+
init.type === "BinaryExpression" ||
|
|
214
|
+
init.type === "ArrayExpression" ||
|
|
215
|
+
init.type === "ArrowFunctionExpression") {
|
|
216
|
+
value = (_b = _this.sourceAtPos(init.start, init.end)) === null || _b === void 0 ? void 0 : _b.replace(/\n/g, " ");
|
|
217
|
+
type = value;
|
|
218
|
+
isFunction = init.type === "ArrowFunctionExpression";
|
|
219
|
+
if (init.type === "BinaryExpression") {
|
|
220
|
+
if ((init === null || init === void 0 ? void 0 : init.left.type) === "Literal" && typeof (init === null || init === void 0 ? void 0 : init.left.value) === "string") {
|
|
221
|
+
type = "string";
|
|
222
|
+
}
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
if (init.type === "UnaryExpression") {
|
|
226
|
-
value = _this.sourceAtPos(init.start, init.end);
|
|
227
|
-
type = typeof ((_c = init.argument) === null || _c === void 0 ? void 0 : _c.value);
|
|
228
|
-
}
|
|
229
225
|
else {
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
if (init.type === "UnaryExpression") {
|
|
227
|
+
value = _this.sourceAtPos(init.start, init.end);
|
|
228
|
+
type = typeof ((_c = init.argument) === null || _c === void 0 ? void 0 : _c.value);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
value = init.raw;
|
|
232
|
+
type = init.value == null ? undefined : typeof init.value;
|
|
233
|
+
}
|
|
232
234
|
}
|
|
233
235
|
}
|
|
236
|
+
if (declaration_type === "FunctionDeclaration") {
|
|
237
|
+
value = "() => " + ((_d = _this.sourceAtPos(body.start, body.end)) === null || _d === void 0 ? void 0 : _d.replace(/\n/g, " "));
|
|
238
|
+
type = "() => any";
|
|
239
|
+
kind = "function";
|
|
240
|
+
isFunction = true;
|
|
241
|
+
isFunctionDeclaration = true;
|
|
242
|
+
}
|
|
243
|
+
if (node.leadingComments) {
|
|
244
|
+
var last_comment = node.leadingComments[node.leadingComments.length - 1];
|
|
245
|
+
var comment = commentParser.parse(ComponentParser.formatComment(last_comment.value), {
|
|
246
|
+
spacing: "preserve"
|
|
247
|
+
});
|
|
248
|
+
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];
|
|
249
|
+
if ((tag === null || tag === void 0 ? void 0 : tag.tag) === "type")
|
|
250
|
+
type = _this.aliasType(tag.type);
|
|
251
|
+
description = ComponentParser.assignValue((_h = (_g = comment[0]) === null || _g === void 0 ? void 0 : _g.description) === null || _h === void 0 ? void 0 : _h.trim());
|
|
252
|
+
}
|
|
253
|
+
if (!description && _this.typedefs.has(type)) {
|
|
254
|
+
description = _this.typedefs.get(type).description;
|
|
255
|
+
}
|
|
256
|
+
_this.addModuleExport(prop_name, {
|
|
257
|
+
name: prop_name,
|
|
258
|
+
kind: kind,
|
|
259
|
+
description: description,
|
|
260
|
+
type: type,
|
|
261
|
+
value: value,
|
|
262
|
+
isFunction: isFunction,
|
|
263
|
+
isFunctionDeclaration: isFunctionDeclaration,
|
|
264
|
+
constant: kind === "const",
|
|
265
|
+
reactive: false
|
|
266
|
+
});
|
|
234
267
|
}
|
|
235
|
-
if (declaration_type === "FunctionDeclaration") {
|
|
236
|
-
value = "() => " + ((_d = _this.sourceAtPos(body.start, body.end)) === null || _d === void 0 ? void 0 : _d.replace(/\n/g, " "));
|
|
237
|
-
type = "() => any";
|
|
238
|
-
kind = "function";
|
|
239
|
-
isFunction = true;
|
|
240
|
-
isFunctionDeclaration = true;
|
|
241
|
-
}
|
|
242
|
-
if (node.leadingComments) {
|
|
243
|
-
var last_comment = node.leadingComments[node.leadingComments.length - 1];
|
|
244
|
-
var comment = commentParser(ComponentParser.formatComment(last_comment.value));
|
|
245
|
-
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];
|
|
246
|
-
if ((tag === null || tag === void 0 ? void 0 : tag.tag) === "type")
|
|
247
|
-
type = _this.aliasType(tag.type);
|
|
248
|
-
description = ComponentParser.assignValue((_g = comment[0]) === null || _g === void 0 ? void 0 : _g.description);
|
|
249
|
-
}
|
|
250
|
-
if (!description && _this.typedefs.has(type)) {
|
|
251
|
-
description = _this.typedefs.get(type).description;
|
|
252
|
-
}
|
|
253
|
-
_this.addModuleExport(prop_name, {
|
|
254
|
-
name: prop_name,
|
|
255
|
-
kind: kind,
|
|
256
|
-
description: description,
|
|
257
|
-
type: type,
|
|
258
|
-
value: value,
|
|
259
|
-
isFunction: isFunction,
|
|
260
|
-
isFunctionDeclaration: isFunctionDeclaration,
|
|
261
|
-
constant: kind === "const",
|
|
262
|
-
reactive: false
|
|
263
|
-
});
|
|
264
268
|
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
267
271
|
var dispatcher_name = undefined;
|
|
268
272
|
var callees = [];
|
|
269
273
|
(0, compiler_1.walk)({ html: this.parsed.html, instance: this.parsed.instance }, {
|
|
270
274
|
enter: function (node, parent, prop) {
|
|
271
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
275
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
272
276
|
if (node.type === "CallExpression") {
|
|
273
277
|
if (node.callee.name === "createEventDispatcher") {
|
|
274
278
|
dispatcher_name = parent === null || parent === void 0 ? void 0 : parent.id.name;
|
|
@@ -306,7 +310,7 @@ var ComponentParser = /** @class */ (function () {
|
|
|
306
310
|
node.declaration = declaration_1;
|
|
307
311
|
prop_name = exportedName;
|
|
308
312
|
}
|
|
309
|
-
var
|
|
313
|
+
var _o = node.declaration.declarations ? node.declaration.declarations[0] : node.declaration, declaration_type = _o.type, id = _o.id, init = _o.init, body = _o.body;
|
|
310
314
|
prop_name !== null && prop_name !== void 0 ? prop_name : (prop_name = id.name);
|
|
311
315
|
var value = undefined;
|
|
312
316
|
var type = undefined;
|
|
@@ -348,11 +352,13 @@ var ComponentParser = /** @class */ (function () {
|
|
|
348
352
|
}
|
|
349
353
|
if (node.leadingComments) {
|
|
350
354
|
var last_comment = node.leadingComments[node.leadingComments.length - 1];
|
|
351
|
-
var comment = commentParser(ComponentParser.formatComment(last_comment.value)
|
|
355
|
+
var comment = commentParser.parse(ComponentParser.formatComment(last_comment.value), {
|
|
356
|
+
spacing: "preserve"
|
|
357
|
+
});
|
|
352
358
|
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];
|
|
353
359
|
if ((tag === null || tag === void 0 ? void 0 : tag.tag) === "type")
|
|
354
360
|
type = _this.aliasType(tag.type);
|
|
355
|
-
description = ComponentParser.assignValue((_g = comment[0]) === null || _g === void 0 ? void 0 : _g.description);
|
|
361
|
+
description = ComponentParser.assignValue((_h = (_g = comment[0]) === null || _g === void 0 ? void 0 : _g.description) === null || _h === void 0 ? void 0 : _h.trim());
|
|
356
362
|
}
|
|
357
363
|
if (!description && _this.typedefs.has(type)) {
|
|
358
364
|
description = _this.typedefs.get(type).description;
|
|
@@ -370,13 +376,13 @@ var ComponentParser = /** @class */ (function () {
|
|
|
370
376
|
});
|
|
371
377
|
}
|
|
372
378
|
if (node.type === "Comment") {
|
|
373
|
-
var data = (
|
|
379
|
+
var data = (_k = (_j = node === null || node === void 0 ? void 0 : node.data) === null || _j === void 0 ? void 0 : _j.trim()) !== null && _k !== void 0 ? _k : "";
|
|
374
380
|
if (/^@component/.test(data)) {
|
|
375
381
|
_this.componentComment = data.replace(/^@component/, "");
|
|
376
382
|
}
|
|
377
383
|
}
|
|
378
384
|
if (node.type === "Slot") {
|
|
379
|
-
var slot_name = (
|
|
385
|
+
var slot_name = (_l = node.attributes.find(function (attr) { return attr.name === "name"; })) === null || _l === void 0 ? void 0 : _l.value[0].data;
|
|
380
386
|
var slot_props = node.attributes
|
|
381
387
|
.filter(function (attr) { return attr.name !== "name"; })
|
|
382
388
|
.reduce(function (slot_props, _a) {
|
|
@@ -413,7 +419,7 @@ var ComponentParser = /** @class */ (function () {
|
|
|
413
419
|
}
|
|
414
420
|
return __assign(__assign({}, slot_props), (_b = {}, _b[name] = slot_prop_value, _b));
|
|
415
421
|
}, {});
|
|
416
|
-
var fallback = (
|
|
422
|
+
var fallback = (_m = node.children) === null || _m === void 0 ? void 0 : _m.map(function (_a) {
|
|
417
423
|
var start = _a.start, end = _a.end;
|
|
418
424
|
return _this.sourceAtPos(start, end);
|
|
419
425
|
}).join("").trim();
|
package/lib/get-svelte-entry.js
CHANGED
|
@@ -14,7 +14,7 @@ function getSvelteEntry(entryPoint) {
|
|
|
14
14
|
return entryPoint;
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
|
|
17
|
+
console.log("Invalid entry point: ".concat(entry_path, "."));
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -23,12 +23,12 @@ function getSvelteEntry(entryPoint) {
|
|
|
23
23
|
var pkg = JSON.parse(fs.readFileSync(pkg_path, "utf-8"));
|
|
24
24
|
if (pkg.svelte !== undefined)
|
|
25
25
|
return pkg.svelte;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
console.log("Could not determine an entry point.\n");
|
|
27
|
+
console.log('Specify an entry point to your Svelte code in the "svelte" field of your package.json.\n');
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
|
|
31
|
+
console.log("Could not locate a package.json file.\n");
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
34
|
}
|
package/lib/rollup-plugin.js
CHANGED
|
@@ -48,7 +48,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
};
|
|
49
49
|
exports.__esModule = true;
|
|
50
50
|
exports.writeOutput = exports.generateBundle = void 0;
|
|
51
|
-
var fs = require("fs
|
|
51
|
+
var fs = require("fs");
|
|
52
|
+
var fsp = require("fs/promises");
|
|
52
53
|
var path = require("path");
|
|
53
54
|
var fg = require("fast-glob");
|
|
54
55
|
var writer_ts_definitions_1 = require("./writer/writer-ts-definitions");
|
|
@@ -123,7 +124,7 @@ function generateBundle(input, glob) {
|
|
|
123
124
|
moduleName = name_1;
|
|
124
125
|
}
|
|
125
126
|
if (!(ext === ".svelte")) return [3 /*break*/, 4];
|
|
126
|
-
return [4 /*yield*/,
|
|
127
|
+
return [4 /*yield*/, fsp.readFile(path.resolve(dir, filePath), "utf-8")];
|
|
127
128
|
case 2:
|
|
128
129
|
source = _c.sent();
|
|
129
130
|
return [4 /*yield*/, (0, compiler_1.preprocess)(source, [(0, svelte_preprocess_1.typescript)(), (0, svelte_preprocess_1.replace)([[/<style.+<\/style>/gims, ""]])], {
|
|
@@ -157,7 +158,7 @@ function writeOutput(result, opts, input) {
|
|
|
157
158
|
(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 }));
|
|
158
159
|
}
|
|
159
160
|
if (opts === null || opts === void 0 ? void 0 : opts.markdown) {
|
|
160
|
-
(0, writer_markdown_1["default"])(result.components, __assign({ outFile: "COMPONENT_INDEX.md" }, opts === null || opts === void 0 ? void 0 : opts.markdownOptions));
|
|
161
|
+
(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));
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
exports.writeOutput = writeOutput;
|
package/lib/writer/Writer.js
CHANGED
|
@@ -36,7 +36,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
exports.__esModule = true;
|
|
39
|
-
var
|
|
39
|
+
var path = require("path");
|
|
40
|
+
var fsp = require("fs/promises");
|
|
40
41
|
var prettier = require("prettier");
|
|
41
42
|
var Writer = /** @class */ (function () {
|
|
42
43
|
function Writer(options) {
|
|
@@ -47,29 +48,21 @@ var Writer = /** @class */ (function () {
|
|
|
47
48
|
return prettier.format(raw, this.options);
|
|
48
49
|
}
|
|
49
50
|
catch (error) {
|
|
50
|
-
|
|
51
|
+
console.error(error);
|
|
51
52
|
return raw;
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
Writer.prototype.write = function (filePath, raw) {
|
|
55
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var error_1;
|
|
57
57
|
return __generator(this, function (_a) {
|
|
58
58
|
switch (_a.label) {
|
|
59
|
-
case 0:
|
|
60
|
-
_a.trys.push([0, 3, , 4]);
|
|
61
|
-
return [4 /*yield*/, fs.ensureFile(filePath)];
|
|
59
|
+
case 0: return [4 /*yield*/, fsp.mkdir(path.parse(filePath).dir, { recursive: true })];
|
|
62
60
|
case 1:
|
|
63
61
|
_a.sent();
|
|
64
|
-
return [4 /*yield*/,
|
|
62
|
+
return [4 /*yield*/, fsp.writeFile(filePath, this.format(raw))];
|
|
65
63
|
case 2:
|
|
66
64
|
_a.sent();
|
|
67
|
-
return [
|
|
68
|
-
case 3:
|
|
69
|
-
error_1 = _a.sent();
|
|
70
|
-
process.stderr.write(error_1 + "\n");
|
|
71
|
-
return [3 /*break*/, 4];
|
|
72
|
-
case 4: return [2 /*return*/];
|
|
65
|
+
return [2 /*return*/];
|
|
73
66
|
}
|
|
74
67
|
});
|
|
75
68
|
});
|
|
@@ -74,7 +74,7 @@ function writeJson(components, options) {
|
|
|
74
74
|
return [4 /*yield*/, writer.write(output_path, JSON.stringify(output))];
|
|
75
75
|
case 1:
|
|
76
76
|
_a.sent();
|
|
77
|
-
|
|
77
|
+
console.log("created \"".concat(options.outFile, "\".\n"));
|
|
78
78
|
return [2 /*return*/];
|
|
79
79
|
}
|
|
80
80
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ComponentDocs } from "../rollup-plugin";
|
|
2
2
|
import WriterMarkdown, { AppendType } from "./WriterMarkdown";
|
|
3
3
|
export interface WriteMarkdownOptions {
|
|
4
|
+
write?: boolean;
|
|
4
5
|
outFile: string;
|
|
5
6
|
onAppend?: (type: AppendType, document: WriterMarkdown, components: ComponentDocs) => void;
|
|
6
7
|
}
|
|
7
|
-
export default function writeMarkdown(components: ComponentDocs, options: WriteMarkdownOptions): Promise<
|
|
8
|
+
export default function writeMarkdown(components: ComponentDocs, options: WriteMarkdownOptions): Promise<string>;
|
|
@@ -45,7 +45,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
45
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
46
|
};
|
|
47
47
|
exports.__esModule = true;
|
|
48
|
-
var path = require("path");
|
|
49
48
|
var WriterMarkdown_1 = require("./WriterMarkdown");
|
|
50
49
|
var writer_ts_definitions_1 = require("./writer-ts-definitions");
|
|
51
50
|
var PROP_TABLE_HEADER = "| Prop name | Kind | Reactive | Type | Default value | Description |\n| :- | :- | :- | :- |\n";
|
|
@@ -87,11 +86,11 @@ function formatEventDetail(detail) {
|
|
|
87
86
|
}
|
|
88
87
|
function writeMarkdown(components, options) {
|
|
89
88
|
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
var
|
|
89
|
+
var write, document, keys;
|
|
91
90
|
return __generator(this, function (_a) {
|
|
92
91
|
switch (_a.label) {
|
|
93
92
|
case 0:
|
|
94
|
-
|
|
93
|
+
write = (options === null || options === void 0 ? void 0 : options.write) !== false;
|
|
95
94
|
document = new WriterMarkdown_1["default"]({
|
|
96
95
|
onAppend: function (type, document) {
|
|
97
96
|
var _a;
|
|
@@ -148,11 +147,13 @@ function writeMarkdown(components, options) {
|
|
|
148
147
|
document.append("p", "None.");
|
|
149
148
|
}
|
|
150
149
|
});
|
|
151
|
-
return [
|
|
150
|
+
if (!write) return [3 /*break*/, 2];
|
|
151
|
+
return [4 /*yield*/, document.write(options.outFile, document.end())];
|
|
152
152
|
case 1:
|
|
153
153
|
_a.sent();
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
console.log("created \"".concat(options.outFile, "\"."));
|
|
155
|
+
_a.label = 2;
|
|
156
|
+
case 2: return [2 /*return*/, document.end()];
|
|
156
157
|
}
|
|
157
158
|
});
|
|
158
159
|
});
|
|
@@ -84,8 +84,8 @@ function addCommentLine(value, returnValue) {
|
|
|
84
84
|
return "* ".concat(returnValue || value, "\n");
|
|
85
85
|
}
|
|
86
86
|
function genPropDef(def) {
|
|
87
|
-
var _a;
|
|
88
|
-
var
|
|
87
|
+
var _a, _b, _c;
|
|
88
|
+
var initial_props = def.props
|
|
89
89
|
.filter(function (prop) { return !prop.isFunctionDeclaration && prop.kind !== "const"; })
|
|
90
90
|
.map(function (prop) {
|
|
91
91
|
var _a;
|
|
@@ -105,11 +105,22 @@ function genPropDef(def) {
|
|
|
105
105
|
.join("");
|
|
106
106
|
var prop_value = prop.constant && !prop.isFunction ? prop.value : prop.type;
|
|
107
107
|
return "\n ".concat(prop_comments.length > 0 ? "/**\n".concat(prop_comments, "*/") : EMPTY_STR, "\n ").concat(prop.name, "?: ").concat(prop_value, ";");
|
|
108
|
-
})
|
|
109
|
-
|
|
108
|
+
});
|
|
109
|
+
if (((_a = def.rest_props) === null || _a === void 0 ? void 0 : _a.type) === "Element") {
|
|
110
|
+
var elements = (_b = def.rest_props) === null || _b === void 0 ? void 0 : _b.name.split("|").map(function (element) { return element.replace(/\s+/g, ""); });
|
|
111
|
+
if (elements.includes("a")) {
|
|
112
|
+
initial_props.push([
|
|
113
|
+
"\n",
|
|
114
|
+
"\n /**\n * SvelteKit attribute to enable data prefetching\n * if a link is hovered over or touched on mobile.\n * @see https://kit.svelte.dev/docs/a-options#sveltekit-prefetch\n * @default false\n */\n \"sveltekit:prefetch\"?: boolean;\n ",
|
|
115
|
+
"\n",
|
|
116
|
+
"\n /**\n * SvelteKit attribute to prevent scrolling\n * after the link is clicked.\n * @see https://kit.svelte.dev/docs/a-options#sveltekit-prefetch\n * @default false\n */\n \"sveltekit:noscroll\"?: boolean;\n ",
|
|
117
|
+
].join("\n"));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
var props = initial_props.join("\n");
|
|
110
121
|
var props_name = "".concat(def.moduleName, "Props");
|
|
111
122
|
var prop_def = EMPTY_STR;
|
|
112
|
-
if (((
|
|
123
|
+
if (((_c = def.rest_props) === null || _c === void 0 ? void 0 : _c.type) === "Element") {
|
|
113
124
|
var extend_tag_map = def.rest_props.name
|
|
114
125
|
.split("|")
|
|
115
126
|
.map(function (name) { return "svelte.JSX.HTMLAttributes<HTMLElementTagNameMap[\"".concat(name.trim(), "\"]>"); })
|
|
@@ -159,7 +170,7 @@ function genAccessors(def) {
|
|
|
159
170
|
function genImports(def) {
|
|
160
171
|
if (def["extends"] === undefined)
|
|
161
172
|
return "";
|
|
162
|
-
return "import { ".concat(def["extends"].interface, " } from ").concat(def["extends"]["import"], ";");
|
|
173
|
+
return "import type { ".concat(def["extends"].interface, " } from ").concat(def["extends"]["import"], ";");
|
|
163
174
|
}
|
|
164
175
|
function genComponentComment(def) {
|
|
165
176
|
if (!def.componentComment)
|
|
@@ -188,7 +199,7 @@ function writeTsDefinition(component) {
|
|
|
188
199
|
rest_props: rest_props,
|
|
189
200
|
"extends": _extends
|
|
190
201
|
}), props_name = _a.props_name, prop_def = _a.prop_def;
|
|
191
|
-
return "\n /// <reference types=\"svelte\" />\n import { 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 }");
|
|
202
|
+
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 }");
|
|
192
203
|
}
|
|
193
204
|
exports.writeTsDefinition = writeTsDefinition;
|
|
194
205
|
function writeTsDefinitions(components, options) {
|
|
@@ -237,7 +248,7 @@ function writeTsDefinitions(components, options) {
|
|
|
237
248
|
case 13: return [4 /*yield*/, writer.write(ts_base_path, indexDTs)];
|
|
238
249
|
case 14:
|
|
239
250
|
_c.sent();
|
|
240
|
-
|
|
251
|
+
console.log("created TypeScript definitions.");
|
|
241
252
|
return [2 /*return*/];
|
|
242
253
|
}
|
|
243
254
|
});
|
package/package.json
CHANGED
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sveld",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
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
|
-
"
|
|
10
|
-
"build
|
|
11
|
-
"
|
|
12
|
-
"test:unit": "
|
|
13
|
-
"test:
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"peerDependencies": {
|
|
18
|
-
"svelte": "^3.31.0"
|
|
9
|
+
"dev": "vite",
|
|
10
|
+
"build": "vite build",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"test:unit": "vitest",
|
|
13
|
+
"test:snapshot": "node tests/test-snapshot",
|
|
14
|
+
"test:integration": "node tests/test-integration",
|
|
15
|
+
"format": "prettier --write \"{src,tests}/**/*.{js,ts,svelte,md}\"",
|
|
16
|
+
"prepack": "tsc"
|
|
19
17
|
},
|
|
20
18
|
"dependencies": {
|
|
21
19
|
"@rollup/plugin-node-resolve": "^11.0.1",
|
|
22
|
-
"acorn": "^8.
|
|
23
|
-
"comment-parser": "^
|
|
24
|
-
"fast-glob": "^3.2.
|
|
25
|
-
"fs-extra": "^9.0.1",
|
|
20
|
+
"acorn": "^8.7.0",
|
|
21
|
+
"comment-parser": "^1.3.0",
|
|
22
|
+
"fast-glob": "^3.2.11",
|
|
26
23
|
"prettier": "^2.5.1",
|
|
27
|
-
"rollup": "^2.
|
|
24
|
+
"rollup": "^2.68.0",
|
|
28
25
|
"rollup-plugin-svelte": "^7.1.0",
|
|
29
|
-
"svelte": "^3.46.
|
|
30
|
-
"svelte-preprocess": "^4.10.
|
|
26
|
+
"svelte": "^3.46.4",
|
|
27
|
+
"svelte-preprocess": "^4.10.4",
|
|
31
28
|
"typescript": "^4.5.5"
|
|
32
29
|
},
|
|
33
30
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@types/node": "^
|
|
36
|
-
"@types/prettier": "^2.
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
31
|
+
"@sveltejs/vite-plugin-svelte": "next",
|
|
32
|
+
"@types/node": "^17.0.21",
|
|
33
|
+
"@types/prettier": "^2.4.4",
|
|
34
|
+
"carbon-components-svelte": "^0.61.1",
|
|
35
|
+
"carbon-preprocess-svelte": "^0.6.0",
|
|
36
|
+
"codemirror": "^5.65.2",
|
|
37
|
+
"prettier-plugin-svelte": "^2.6.0",
|
|
38
|
+
"svelte-highlight": "^5.3.0",
|
|
39
|
+
"vite": "^2.8.6",
|
|
40
|
+
"vitest": "^0.6.0"
|
|
42
41
|
},
|
|
43
42
|
"bin": {
|
|
44
43
|
"sveld": "./cli.js"
|