Comparing version 0.18.1 to 0.19.0
@@ -13,2 +13,12 @@ # Changelog | ||
## [0.19.0](https://github.com/carbon-design-system/sveld/releases/tag/v0.19.0) - 2023-07-19 | ||
**Breaking Changes** | ||
- if using Svelte 3, the generated TypeScript definitions now require version 3.55 or higher | ||
**Features** | ||
- support Svelte 4 in the generated TypeScript definitions | ||
## [0.18.1](https://github.com/carbon-design-system/sveld/releases/tag/v0.18.1) - 2023-06-04 | ||
@@ -15,0 +25,0 @@ |
@@ -51,3 +51,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -54,0 +54,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
@@ -38,3 +38,3 @@ interface ComponentParserDiagnostics { | ||
} | ||
declare type ComponentEvent = ForwardedEvent | DispatchedEvent; | ||
type ComponentEvent = ForwardedEvent | DispatchedEvent; | ||
interface TypeDef { | ||
@@ -54,3 +54,3 @@ type: string; | ||
} | ||
declare type RestProps = undefined | ComponentInlineElement | ComponentElement; | ||
type RestProps = undefined | ComponentInlineElement | ComponentElement; | ||
interface Extends { | ||
@@ -57,0 +57,0 @@ interface: string; |
@@ -46,2 +46,4 @@ "use strict"; | ||
exports.__esModule = true; | ||
// TODO: upgrading to Svelte 4 shows a lot of TS errors. Ignore for now but resolve. | ||
// @ts-nocheck | ||
var compiler_1 = require("svelte/compiler"); | ||
@@ -48,0 +50,0 @@ var commentParser = __importStar(require("comment-parser")); |
@@ -84,4 +84,4 @@ declare const tag_map: { | ||
}; | ||
declare type ElementTag = keyof typeof tag_map; | ||
type ElementTag = keyof typeof tag_map; | ||
export declare function getElementByTag(element: ElementTag | string): string; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
export declare type SvelteEntryPoint = string; | ||
export type SvelteEntryPoint = string; | ||
/** | ||
@@ -3,0 +3,0 @@ * Get the file path entry point for uncompiled Svelte source code |
@@ -1,2 +0,2 @@ | ||
export declare type ParsedExports = Record<string, { | ||
export type ParsedExports = Record<string, { | ||
source: string; | ||
@@ -3,0 +3,0 @@ default: boolean; |
@@ -15,3 +15,3 @@ import { WriteTsDefinitionsOptions } from "./writer/writer-ts-definitions"; | ||
} | ||
declare type ComponentModuleName = string; | ||
type ComponentModuleName = string; | ||
export interface ComponentDocApi extends ParsedComponent { | ||
@@ -21,3 +21,3 @@ filePath: string; | ||
} | ||
export declare type ComponentDocs = Map<ComponentModuleName, ComponentDocApi>; | ||
export type ComponentDocs = Map<ComponentModuleName, ComponentDocApi>; | ||
export default function pluginSveld(opts?: PluginSveldOptions): { | ||
@@ -24,0 +24,0 @@ name: string; |
@@ -51,3 +51,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -54,0 +54,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -20,0 +20,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
@@ -28,3 +28,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -31,0 +31,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
@@ -17,3 +17,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -20,0 +20,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
@@ -40,3 +40,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -90,2 +90,4 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
var EMPTY_STR = ""; | ||
// Svelte 4 is not compatible with `{}` | ||
var EMPTY_EVENTS = "Record<string, any>"; | ||
function formatTsProps(props) { | ||
@@ -145,14 +147,13 @@ if (props === undefined) | ||
var element = name.trim(); | ||
if (element === "svg") { | ||
return "svelte.JSX.SVGAttributes<SVGSVGElement>"; | ||
} | ||
return "svelte.JSX.HTMLAttributes<HTMLElementTagNameMap[\"".concat(element, "\"]>"); | ||
return "SvelteHTMLElements[\"".concat(element, "\"]"); | ||
}) | ||
.join(","); | ||
.join("&"); | ||
/** | ||
* Components that extend HTML elements should allow for `data-*` attributes. | ||
* @see https://github.com/sveltejs/language-tools/issues/1825 | ||
* | ||
* Even though Svelte 4 does this automatically, we need to preserve this for Svelte 3. | ||
*/ | ||
var dataAttributes = "[key: `data-${string}`]: any;"; | ||
prop_def = "\n export interface ".concat(props_name, " extends ").concat(def["extends"] !== undefined ? "".concat(def["extends"].interface, ", ") : "").concat(extend_tag_map, " {\n ").concat(props, "\n \n ").concat(dataAttributes, "\n }\n "); | ||
prop_def = "\n ".concat(extend_tag_map ? "type RestProps = ".concat(extend_tag_map, ";\n") : "", "\n export interface ").concat(props_name, " extends ").concat(def["extends"] !== undefined ? "".concat(def["extends"].interface, ", ") : "", "RestProps {\n ").concat(props, "\n \n ").concat(dataAttributes, "\n }\n "); | ||
} | ||
@@ -190,3 +191,5 @@ else { | ||
}; | ||
return def.events | ||
if (def.events.length === 0) | ||
return EMPTY_EVENTS; | ||
var events_map = def.events | ||
.map(function (event) { | ||
@@ -200,2 +203,3 @@ var description = ""; | ||
.join(""); | ||
return "{".concat(events_map, "}"); | ||
} | ||
@@ -251,12 +255,12 @@ function genAccessors(def) { | ||
}), props_name = _a.props_name, prop_def = _a.prop_def; | ||
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 }"); | ||
return "\n import type { SvelteComponentTyped } from \"svelte\";".concat((rest_props === null || rest_props === void 0 ? void 0 : rest_props.type) === "Element" ? "import type { SvelteHTMLElements } from \"svelte/elements\";\n" : "", "\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 }"); | ||
} | ||
exports.writeTsDefinition = writeTsDefinition; | ||
function writeTsDefinitions(components, options) { | ||
var components_1, components_1_1; | ||
var e_1, _a; | ||
var _a, components_1, components_1_1; | ||
var _b, e_1, _c, _d; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var ts_base_path, writer, indexDTs, _b, moduleName, component, ts_filepath, e_1_1; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
var ts_base_path, writer, indexDTs, moduleName, component, ts_filepath, e_1_1; | ||
return __generator(this, function (_e) { | ||
switch (_e.label) { | ||
case 0: | ||
@@ -266,37 +270,45 @@ ts_base_path = path.join(process.cwd(), options.outDir, "index.d.ts"); | ||
indexDTs = options.preamble + (0, create_exports_1.createExports)(options.exports, components); | ||
_c.label = 1; | ||
_e.label = 1; | ||
case 1: | ||
_c.trys.push([1, 7, 8, 13]); | ||
components_1 = __asyncValues(components); | ||
_c.label = 2; | ||
_e.trys.push([1, 9, 10, 15]); | ||
_a = true, components_1 = __asyncValues(components); | ||
_e.label = 2; | ||
case 2: return [4 /*yield*/, components_1.next()]; | ||
case 3: | ||
if (!(components_1_1 = _c.sent(), !components_1_1.done)) return [3 /*break*/, 6]; | ||
_b = components_1_1.value, moduleName = _b[0], component = _b[1]; | ||
if (!(components_1_1 = _e.sent(), _b = components_1_1.done, !_b)) return [3 /*break*/, 8]; | ||
_d = components_1_1.value; | ||
_a = false; | ||
_e.label = 4; | ||
case 4: | ||
_e.trys.push([4, , 6, 7]); | ||
moduleName = _d[0], component = _d[1]; | ||
ts_filepath = (0, create_exports_1.convertSvelteExt)(path.join(options.outDir, component.filePath)); | ||
return [4 /*yield*/, writer.write(ts_filepath, writeTsDefinition(component))]; | ||
case 4: | ||
_c.sent(); | ||
_c.label = 5; | ||
case 5: return [3 /*break*/, 2]; | ||
case 6: return [3 /*break*/, 13]; | ||
case 7: | ||
e_1_1 = _c.sent(); | ||
case 5: | ||
_e.sent(); | ||
return [3 /*break*/, 7]; | ||
case 6: | ||
_a = true; | ||
return [7 /*endfinally*/]; | ||
case 7: return [3 /*break*/, 2]; | ||
case 8: return [3 /*break*/, 15]; | ||
case 9: | ||
e_1_1 = _e.sent(); | ||
e_1 = { error: e_1_1 }; | ||
return [3 /*break*/, 13]; | ||
case 8: | ||
_c.trys.push([8, , 11, 12]); | ||
if (!(components_1_1 && !components_1_1.done && (_a = components_1["return"]))) return [3 /*break*/, 10]; | ||
return [4 /*yield*/, _a.call(components_1)]; | ||
case 9: | ||
_c.sent(); | ||
_c.label = 10; | ||
case 10: return [3 /*break*/, 12]; | ||
return [3 /*break*/, 15]; | ||
case 10: | ||
_e.trys.push([10, , 13, 14]); | ||
if (!(!_a && !_b && (_c = components_1["return"]))) return [3 /*break*/, 12]; | ||
return [4 /*yield*/, _c.call(components_1)]; | ||
case 11: | ||
_e.sent(); | ||
_e.label = 12; | ||
case 12: return [3 /*break*/, 14]; | ||
case 13: | ||
if (e_1) throw e_1.error; | ||
return [7 /*endfinally*/]; | ||
case 12: return [7 /*endfinally*/]; | ||
case 13: return [4 /*yield*/, writer.write(ts_base_path, indexDTs)]; | ||
case 14: | ||
_c.sent(); | ||
case 14: return [7 /*endfinally*/]; | ||
case 15: return [4 /*yield*/, writer.write(ts_base_path, indexDTs)]; | ||
case 16: | ||
_e.sent(); | ||
console.log("created TypeScript definitions."); | ||
@@ -303,0 +315,0 @@ return [2 /*return*/]; |
@@ -40,3 +40,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -43,0 +43,0 @@ if (y = 0, t) op = [op[0] & 2, t.value]; |
import Writer from "./Writer"; | ||
declare type OnAppend = (type: AppendType, document: WriterMarkdown) => void; | ||
type OnAppend = (type: AppendType, document: WriterMarkdown) => void; | ||
interface MarkdownOptions { | ||
onAppend?: OnAppend; | ||
} | ||
export declare type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw"; | ||
export type AppendType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "quote" | "p" | "divider" | "raw"; | ||
interface TocLine { | ||
@@ -8,0 +8,0 @@ array: number[]; |
{ | ||
"name": "sveld", | ||
"version": "0.18.1", | ||
"version": "0.19.0", | ||
"license": "Apache-2.0", | ||
@@ -26,3 +26,3 @@ "description": "Generate TypeScript definitions for your Svelte components.", | ||
"rollup-plugin-svelte": "^7.1.0", | ||
"svelte": "^3.52.0", | ||
"svelte": "^4.0.5", | ||
"svelte-preprocess": "^4.10.6", | ||
@@ -29,0 +29,0 @@ "typescript": "^4.8.4" |
@@ -17,3 +17,3 @@ # sveld | ||
**Please note** that the generated TypeScript definitions require [Svelte version 3.31](https://github.com/sveltejs/svelte/blob/master/CHANGELOG.md#3310) or greater. | ||
**Please note** that the generated TypeScript definitions require Svelte version 3.55 or greater. | ||
@@ -42,6 +42,8 @@ --- | ||
```ts | ||
/// <reference types="svelte" /> | ||
import type { SvelteComponentTyped } from "svelte"; | ||
import type { SvelteHTMLElements } from "svelte/elements"; | ||
export interface ButtonProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["button"]> { | ||
type RestProps = SvelteHTMLElements["button"]; | ||
export interface ButtonProps extends RestProps { | ||
/** | ||
@@ -82,6 +84,7 @@ * @default "button" | ||
```ts | ||
/// <reference types="svelte" /> | ||
import { SvelteComponentTyped } from "svelte"; | ||
import type { SvelteHTMLElements } from "svelte/elements"; | ||
export interface ButtonProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["button"]> { | ||
type RestProps = SvelteHTMLElements["button"]; | ||
export interface ButtonProps extends RestProps { | ||
/** | ||
@@ -143,4 +146,2 @@ * @default "button" | ||
The generated TypeScript definitions for a component extends the `SvelteComponentTyped` interface available in svelte version 3.31. | ||
## Usage | ||
@@ -147,0 +148,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149328
2423
541
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Addedaria-query@5.3.2(transitive)
+ Addedaxobject-query@4.1.0(transitive)
+ Addedcode-red@1.0.4(transitive)
+ Addedcss-tree@2.3.1(transitive)
+ Addedestree-walker@3.0.3(transitive)
+ Addedis-reference@3.0.3(transitive)
+ Addedlocate-character@3.0.0(transitive)
+ Addedmagic-string@0.30.13(transitive)
+ Addedmdn-data@2.0.30(transitive)
+ Addedperiscopic@3.1.0(transitive)
+ Addedsvelte@4.2.19(transitive)
Updatedsvelte@^4.0.5