From 369a4b0fc47de503b926de4a8fed993025e177c0 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 6 Apr 2024 16:49:10 -0700 Subject: [PATCH] test: update fixture snapshots --- tests/__snapshots__/fixtures.test.ts.snap | 1716 +++++++++++---------- tests/fixtures.test.ts | 57 +- 2 files changed, 927 insertions(+), 846 deletions(-) diff --git a/tests/__snapshots__/fixtures.test.ts.snap b/tests/__snapshots__/fixtures.test.ts.snap index d3511eb..2fff572 100644 --- a/tests/__snapshots__/fixtures.test.ts.snap +++ b/tests/__snapshots__/fixtures.test.ts.snap @@ -1,37 +1,32 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +// Bun Snapshot v1, https://goo.gl/fbAQLP -exports[`fixtures (JSON) > 'component-comment-single/input.svelte' 1`] = ` +exports[`fixtures (JSON) "svg-props/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], - "slots": [ - { - "name": "__default__", - "default": true, - "slot_props": "{}" - } - ], + "slots": [], "events": [], "typedefs": [], "rest_props": { "type": "Element", - "name": "a" + "name": "svg" } }" `; -exports[`fixtures (JSON) > 'component-comment-single/input.svelte' 2`] = ` +exports[`fixtures (JSON) "slots-named/input.svelte" 1`] = ` "{ "props": [ { - "name": "ref", + "name": "text", "kind": "let", - "type": "null | HTMLButtonElement", + "type": "string", + "value": "\"\"", "isFunction": false, "isFunctionDeclaration": false, - "isRequired": true, + "isRequired": false, "constant": false, - "reactive": true + "reactive": false } ], "moduleExports": [], @@ -39,7 +34,26 @@ exports[`fixtures (JSON) > 'component-comment-single/input.svelte' 2`] = ` { "name": "__default__", "default": true, + "fallback": "Default text", "slot_props": "{}" + }, + { + "name": "bold heading", + "default": false, + "fallback": "{text}", + "slot_props": "{ text: string }" + }, + { + "name": "subheading", + "default": false, + "fallback": "{text}", + "slot_props": "{ text: string }" + }, + { + "name": "text", + "default": false, + "fallback": "{text}", + "slot_props": "{ text: string }" } ], "events": [], @@ -47,55 +61,79 @@ exports[`fixtures (JSON) > 'component-comment-single/input.svelte' 2`] = ` }" `; -exports[`fixtures (JSON) > 'component-comment-single/input.svelte' 3`] = ` +exports[`fixtures (JSON) "dispatched-events-dynamic/input.svelte" 1`] = ` +"{ + "props": [], + "moduleExports": [], + "slots": [], + "events": [ + { + "type": "dispatched", + "name": "KEY", + "detail": "{key: string;}" + } + ], + "typedefs": [] +}" +`; + +exports[`fixtures (JSON) "function-declaration/input.svelte" 1`] = ` "{ "props": [ { - "name": "ref", + "name": "fnA", "kind": "let", - "type": "null | HTMLButtonElement | HTMLHeadingElement", - "isFunction": false, + "type": "() => {}", + "value": "() => {}", + "isFunction": true, "isFunctionDeclaration": false, - "isRequired": true, + "isRequired": false, "constant": false, - "reactive": true + "reactive": false }, { - "name": "ref2", - "kind": "let", - "type": "null | HTMLDivElement", - "isFunction": false, + "name": "fnB", + "kind": "const", + "type": "() => {}", + "value": "() => {}", + "isFunction": true, "isFunctionDeclaration": false, - "isRequired": true, + "isRequired": false, + "constant": true, + "reactive": false + }, + { + "name": "add", + "kind": "function", + "type": "() => any", + "value": "() => { return a + b; }", + "isFunction": true, + "isFunctionDeclaration": true, + "isRequired": false, "constant": false, - "reactive": true + "reactive": false }, { - "name": "propBool", - "kind": "let", - "type": "boolean", - "value": "false", - "isFunction": false, - "isFunctionDeclaration": false, + "name": "multiply", + "kind": "function", + "description": "Multiplies two numbers", + "type": "(a: number, b: number) => number", + "value": "() => { return a * b; }", + "isFunction": true, + "isFunctionDeclaration": true, "isRequired": false, "constant": false, "reactive": false } ], "moduleExports": [], - "slots": [ - { - "name": "__default__", - "default": true, - "slot_props": "{}" - } - ], + "slots": [], "events": [], "typedefs": [] }" `; -exports[`fixtures (JSON) > 'component-comment-single/input.svelte' 4`] = ` +exports[`fixtures (JSON) "forwarded-events/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], @@ -106,141 +144,199 @@ exports[`fixtures (JSON) > 'component-comment-single/input.svelte' 4`] = ` "slot_props": "{}" } ], - "events": [], - "typedefs": [], - "componentComment": "\\n@example\\n
\\n Component comment\\n
" + "events": [ + { + "type": "forwarded", + "name": "click", + "element": "button" + }, + { + "type": "forwarded", + "name": "focus", + "element": "button" + }, + { + "type": "forwarded", + "name": "blur", + "element": "button" + }, + { + "type": "forwarded", + "name": "mouseover", + "element": "h1" + } + ], + "typedefs": [] }" `; -exports[`fixtures (JSON) > 'component-comment-single/input.svelte' 5`] = ` +exports[`fixtures (JSON) "mixed-events/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], - "slots": [ + "slots": [], + "events": [ { - "name": "__default__", - "default": true, - "slot_props": "{}" + "type": "dispatched", + "name": "custom-focus", + "detail": "FocusEvent | number" + }, + { + "type": "dispatched", + "name": "blur", + "detail": "FocusEvent | CustomEvent" } ], - "events": [], - "typedefs": [], - "componentComment": " Component comment" + "typedefs": [] }" `; -exports[`fixtures (JSON) > 'context-module/input.svelte' 1`] = ` +exports[`fixtures (JSON) "infer-basic/input.svelte" 1`] = ` "{ "props": [ { - "name": "a", - "kind": "const", - "type": "string", - "value": "\\"\\"", + "name": "ref", + "kind": "let", + "value": "null", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": true, + "constant": false, "reactive": false - } - ], - "moduleExports": [ + }, { - "name": "bool", - "kind": "const", - "type": "string", - "value": "\\"\\"", + "name": "propBool", + "kind": "let", + "type": "boolean", + "value": "true", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": true, - "reactive": false + "constant": false, + "reactive": true }, { - "name": "a", - "kind": "const", - "type": "{ b: 4 }", - "value": "{ b: 4 }", + "name": "propString", + "kind": "let", + "type": "string", + "value": "\"\"", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": true, + "constant": false, "reactive": false }, { - "name": "e", - "kind": "const", - "description": "Description for e", - "type": "{ [key: string]: any; }", - "value": "{ b: 4 }", + "name": "name", + "kind": "let", "isFunction": false, "isFunctionDeclaration": false, - "isRequired": false, - "constant": true, - "reactive": false - }, - { - "name": "log", - "kind": "function", - "description": "Log something", - "type": "(message: string) => void", - "value": "() => { console.log(message); }", - "isFunction": true, - "isFunctionDeclaration": true, - "isRequired": false, + "isRequired": true, "constant": false, "reactive": false }, { - "name": "b", - "kind": "const", - "type": "() => {}", - "value": "() => {}", - "isFunction": true, + "name": "id", + "kind": "let", + "type": "string", + "value": "\"\" + Math.random().toString(36)", + "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": true, + "constant": false, "reactive": false }, { - "name": "b2", + "name": "propConst", "kind": "const", - "type": "() => () => {}", - "value": "() => () => {}", - "isFunction": true, + "type": "{ [\"1\"]: true }", + "value": "{ [\"1\"]: true }", + "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, "constant": true, "reactive": false }, { - "name": "b3", - "kind": "const", - "type": "() => () => false", - "value": "() => () => false", + "name": "fn", + "kind": "function", + "type": "() => any", + "value": "() => { localBool = !localBool; }", "isFunction": true, - "isFunctionDeclaration": false, + "isFunctionDeclaration": true, "isRequired": false, - "constant": true, + "constant": false, "reactive": false } ], - "slots": [], + "moduleExports": [], + "slots": [ + { + "name": "__default__", + "default": true, + "fallback": "{name}", + "slot_props": "{}" + } + ], "events": [], "typedefs": [] }" `; -exports[`fixtures (JSON) > 'dispatched-events/input.svelte' 1`] = ` +exports[`fixtures (JSON) "empty-export/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], - "slots": [ + "slots": [], + "events": [], + "typedefs": [] +}" +`; + +exports[`fixtures (JSON) "typed-slots/input.svelte" 1`] = ` +"{ + "props": [ { - "name": "__default__", - "default": true, - "slot_props": "{}" - } + "name": "prop", + "kind": "let", + "type": "number", + "value": "0", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false + } + ], + "moduleExports": [], + "slots": [ + { + "name": "__default__", + "default": true, + "slot_props": "{ prop: number; doubled: number; }" + }, + { + "name": "description", + "default": false, + "slot_props": "{ props: { class?: string; } }", + "description": "description" + } + ], + "events": [], + "typedefs": [] +}" +`; + +exports[`fixtures (JSON) "dispatched-events/input.svelte" 1`] = ` +"{ + "props": [], + "moduleExports": [], + "slots": [ + { + "name": "__default__", + "default": true, + "slot_props": "{}" + } ], "events": [ { @@ -267,23 +363,84 @@ exports[`fixtures (JSON) > 'dispatched-events/input.svelte' 1`] = ` }" `; -exports[`fixtures (JSON) > 'dispatched-events-dynamic/input.svelte' 1`] = ` +exports[`fixtures (JSON) "typedefs/input.svelte" 1`] = ` "{ - "props": [], + "props": [ + { + "name": "prop1", + "kind": "let", + "type": "MyTypedef", + "value": "{ [\"1\"]: true }", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false + }, + { + "name": "prop2", + "kind": "let", + "type": "MyTypedefArray", + "value": "[]", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false + } + ], "moduleExports": [], - "slots": [], - "events": [ + "slots": [ { - "type": "dispatched", - "name": "KEY", - "detail": "{key: string;}" + "name": "__default__", + "default": true, + "slot_props": "{ prop1: MyTypedef, prop2: MyTypedefArray }" + } + ], + "events": [], + "typedefs": [ + { + "type": "{ [key: string]: boolean; }", + "name": "MyTypedef", + "ts": "interface MyTypedef { [key: string]: boolean; }" + }, + { + "type": "MyTypedef[]", + "name": "MyTypedefArray", + "ts": "type MyTypedefArray = MyTypedef[]" + } + ] +}" +`; + +exports[`fixtures (JSON) "bind-this/input.svelte" 1`] = ` +"{ + "props": [ + { + "name": "ref", + "kind": "let", + "type": "null | HTMLButtonElement", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": true, + "constant": false, + "reactive": true + } + ], + "moduleExports": [], + "slots": [ + { + "name": "__default__", + "default": true, + "slot_props": "{}" } ], + "events": [], "typedefs": [] }" `; -exports[`fixtures (JSON) > 'dispatched-events-typed/input.svelte' 1`] = ` +exports[`fixtures (JSON) "dispatched-events-typed/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], @@ -311,116 +468,101 @@ exports[`fixtures (JSON) > 'dispatched-events-typed/input.svelte' 1`] = ` }" `; -exports[`fixtures (JSON) > 'empty-export/input.svelte' 1`] = ` +exports[`fixtures (JSON) "input-events/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], "slots": [], - "events": [], - "typedefs": [] -}" -`; - -exports[`fixtures (JSON) > 'forwarded-events/input.svelte' 1`] = ` -"{ - "props": [], - "moduleExports": [], - "slots": [ - { - "name": "__default__", - "default": true, - "slot_props": "{}" - } - ], "events": [ { "type": "forwarded", - "name": "click", - "element": "button" - }, - { - "type": "forwarded", - "name": "focus", - "element": "button" + "name": "input", + "element": "input" }, { "type": "forwarded", - "name": "blur", - "element": "button" + "name": "change", + "element": "input" }, { "type": "forwarded", - "name": "mouseover", - "element": "h1" + "name": "paste", + "element": "input" } ], "typedefs": [] }" `; -exports[`fixtures (JSON) > 'function-declaration/input.svelte' 1`] = ` +exports[`fixtures (JSON) "required/input.svelte" 1`] = ` "{ "props": [ { - "name": "fnA", + "name": "prop", "kind": "let", - "type": "() => {}", - "value": "() => {}", - "isFunction": true, + "description": "@required ", + "type": "boolean", + "value": "true", + "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, "constant": false, "reactive": false }, { - "name": "fnB", - "kind": "const", - "type": "() => {}", - "value": "() => {}", - "isFunction": true, + "name": "prop1", + "kind": "let", + "description": "This is a comment.\n@required ", + "type": "boolean | string", + "value": "true", + "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": true, + "constant": false, "reactive": false }, { - "name": "add", - "kind": "function", - "type": "() => any", - "value": "() => { return a + b; }", - "isFunction": true, - "isFunctionDeclaration": true, - "isRequired": false, + "name": "prop2", + "kind": "let", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": true, "constant": false, "reactive": false }, { - "name": "multiply", - "kind": "function", - "description": "Multiplies two numbers", - "type": "(a: number, b: number) => number", - "value": "() => { return a * b; }", - "isFunction": true, - "isFunctionDeclaration": true, - "isRequired": false, + "name": "prop3", + "kind": "let", + "type": "boolean", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": true, "constant": false, "reactive": false } ], "moduleExports": [], - "slots": [], + "slots": [ + { + "name": "__default__", + "default": true, + "slot_props": "{ prop: boolean, prop1: boolean | string, prop2: any, prop3: boolean }" + } + ], "events": [], "typedefs": [] }" `; -exports[`fixtures (JSON) > 'infer-basic/input.svelte' 1`] = ` +exports[`fixtures (JSON) "prop-comments/input.svelte" 1`] = ` "{ "props": [ { - "name": "ref", + "name": "prop", "kind": "let", - "value": "null", + "description": "This is a comment.\n@see https://github.com/\n@deprecated this prop will be removed in the next major release.", + "type": "boolean | string", + "value": "true", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, @@ -428,66 +570,26 @@ exports[`fixtures (JSON) > 'infer-basic/input.svelte' 1`] = ` "reactive": false }, { - "name": "propBool", + "name": "prop1", "kind": "let", + "description": "@see https://github.com/", "type": "boolean", "value": "true", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, "constant": false, - "reactive": true - }, - { - "name": "propString", - "kind": "let", - "type": "string", - "value": "\\"\\"", - "isFunction": false, - "isFunctionDeclaration": false, - "isRequired": false, - "constant": false, - "reactive": false - }, - { - "name": "name", - "kind": "let", - "isFunction": false, - "isFunctionDeclaration": false, - "isRequired": true, - "constant": false, "reactive": false }, { - "name": "id", + "name": "prop2", "kind": "let", - "type": "string", - "value": "\\"\\" + Math.random().toString(36)", - "isFunction": false, - "isFunctionDeclaration": false, - "isRequired": false, - "constant": false, - "reactive": false - }, - { - "name": "propConst", - "kind": "const", - "type": "{ [\\"1\\"]: true }", - "value": "{ [\\"1\\"]: true }", + "description": "This is a comment.", + "type": "boolean | string", + "value": "true", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": true, - "reactive": false - }, - { - "name": "fn", - "kind": "function", - "type": "() => any", - "value": "() => { localBool = !localBool; }", - "isFunction": true, - "isFunctionDeclaration": true, - "isRequired": false, "constant": false, "reactive": false } @@ -497,8 +599,7 @@ exports[`fixtures (JSON) > 'infer-basic/input.svelte' 1`] = ` { "name": "__default__", "default": true, - "fallback": "{name}", - "slot_props": "{}" + "slot_props": "{ prop: boolean | string, prop1: boolean, prop2: boolean | string }" } ], "events": [], @@ -506,13 +607,36 @@ exports[`fixtures (JSON) > 'infer-basic/input.svelte' 1`] = ` }" `; -exports[`fixtures (JSON) > 'infer-with-types/input.svelte' 1`] = ` +exports[`fixtures (JSON) "renamed-props/input.svelte" 1`] = ` "{ "props": [ { - "name": "propBool", + "name": "class", "kind": "let", - "type": "boolean", + "description": "Just your average CSS class string.", + "type": "string|null", + "value": "\"test\"", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false + } + ], + "moduleExports": [], + "slots": [], + "events": [], + "typedefs": [] +}" +`; + +exports[`fixtures (JSON) "infer-with-types/input.svelte" 1`] = ` +"{ + "props": [ + { + "name": "propBool", + "kind": "let", + "type": "boolean", "value": "true", "isFunction": false, "isFunctionDeclaration": false, @@ -524,7 +648,7 @@ exports[`fixtures (JSON) > 'infer-with-types/input.svelte' 1`] = ` "name": "propString", "kind": "let", "type": "string", - "value": "\\"\\"", + "value": "\"\"", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, @@ -545,7 +669,7 @@ exports[`fixtures (JSON) > 'infer-with-types/input.svelte' 1`] = ` "name": "id", "kind": "let", "type": "string", - "value": "\\"\\" + Math.random().toString(36)", + "value": "\"\" + Math.random().toString(36)", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, @@ -556,7 +680,7 @@ exports[`fixtures (JSON) > 'infer-with-types/input.svelte' 1`] = ` "name": "propConst", "kind": "const", "type": "{ [key: string]: boolean; }", - "value": "{ [\\"1\\"]: true }", + "value": "{ [\"1\"]: true }", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, @@ -589,190 +713,109 @@ exports[`fixtures (JSON) > 'infer-with-types/input.svelte' 1`] = ` }" `; -exports[`fixtures (JSON) > 'input-events/input.svelte' 1`] = ` -"{ - "props": [], - "moduleExports": [], - "slots": [], - "events": [ - { - "type": "forwarded", - "name": "input", - "element": "input" - }, - { - "type": "forwarded", - "name": "change", - "element": "input" - }, - { - "type": "forwarded", - "name": "paste", - "element": "input" - } - ], - "typedefs": [] -}" -`; - -exports[`fixtures (JSON) > 'mixed-events/input.svelte' 1`] = ` -"{ - "props": [], - "moduleExports": [], - "slots": [], - "events": [ - { - "type": "dispatched", - "name": "custom-focus", - "detail": "FocusEvent | number" - }, - { - "type": "dispatched", - "name": "blur", - "detail": "FocusEvent | CustomEvent" - } - ], - "typedefs": [] -}" -`; - -exports[`fixtures (JSON) > 'prop-comments/input.svelte' 1`] = ` +exports[`fixtures (JSON) "context-module/input.svelte" 1`] = ` "{ "props": [ { - "name": "prop", - "kind": "let", - "description": "This is a comment.\\n@see https://github.com/\\n@deprecated this prop will be removed in the next major release.", - "type": "boolean | string", - "value": "true", + "name": "a", + "kind": "const", + "type": "string", + "value": "\"\"", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": false, + "constant": true, "reactive": false - }, + } + ], + "moduleExports": [ { - "name": "prop1", - "kind": "let", - "description": "@see https://github.com/", - "type": "boolean", - "value": "true", + "name": "bool", + "kind": "const", + "type": "string", + "value": "\"\"", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": false, + "constant": true, "reactive": false }, { - "name": "prop2", - "kind": "let", - "description": "This is a comment.", - "type": "boolean | string", - "value": "true", + "name": "a", + "kind": "const", + "type": "{ b: 4 }", + "value": "{ b: 4 }", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": false, + "constant": true, "reactive": false - } - ], - "moduleExports": [], - "slots": [ - { - "name": "__default__", - "default": true, - "slot_props": "{ prop: boolean | string, prop1: boolean, prop2: boolean | string }" - } - ], - "events": [], - "typedefs": [] -}" -`; - -exports[`fixtures (JSON) > 'renamed-props/input.svelte' 1`] = ` -"{ - "props": [ + }, { - "name": "class", - "kind": "let", - "description": "Just your average CSS class string.", - "type": "string|null", - "value": "\\"test\\"", + "name": "e", + "kind": "const", + "description": "Description for e", + "type": "{ [key: string]: any; }", + "value": "{ b: 4 }", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, - "constant": false, + "constant": true, "reactive": false - } - ], - "moduleExports": [], - "slots": [], - "events": [], - "typedefs": [] -}" -`; - -exports[`fixtures (JSON) > 'required/input.svelte' 1`] = ` -"{ - "props": [ + }, { - "name": "prop", - "kind": "let", - "description": "@required ", - "type": "boolean", - "value": "true", - "isFunction": false, - "isFunctionDeclaration": false, + "name": "log", + "kind": "function", + "description": "Log something", + "type": "(message: string) => void", + "value": "() => { console.log(message); }", + "isFunction": true, + "isFunctionDeclaration": true, "isRequired": false, "constant": false, "reactive": false }, { - "name": "prop1", - "kind": "let", - "description": "This is a comment.\\n@required ", - "type": "boolean | string", - "value": "true", - "isFunction": false, + "name": "b", + "kind": "const", + "type": "() => {}", + "value": "() => {}", + "isFunction": true, "isFunctionDeclaration": false, "isRequired": false, - "constant": false, + "constant": true, "reactive": false }, { - "name": "prop2", - "kind": "let", - "isFunction": false, + "name": "b2", + "kind": "const", + "type": "() => () => {}", + "value": "() => () => {}", + "isFunction": true, "isFunctionDeclaration": false, - "isRequired": true, - "constant": false, + "isRequired": false, + "constant": true, "reactive": false }, { - "name": "prop3", - "kind": "let", - "type": "boolean", - "isFunction": false, + "name": "b3", + "kind": "const", + "type": "() => () => false", + "value": "() => () => false", + "isFunction": true, "isFunctionDeclaration": false, - "isRequired": true, - "constant": false, + "isRequired": false, + "constant": true, "reactive": false } ], - "moduleExports": [], - "slots": [ - { - "name": "__default__", - "default": true, - "slot_props": "{ prop: boolean, prop1: boolean | string, prop2: any, prop3: boolean }" - } - ], + "slots": [], "events": [], "typedefs": [] }" `; -exports[`fixtures (JSON) > 'rest-props/input.svelte' 1`] = ` +exports[`fixtures (JSON) "rest-props/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], @@ -786,7 +829,7 @@ exports[`fixtures (JSON) > 'rest-props/input.svelte' 1`] = ` }" `; -exports[`fixtures (JSON) > 'rest-props-multiple/input.svelte' 1`] = ` +exports[`fixtures (JSON) "rest-props-multiple/input.svelte" 1`] = ` "{ "props": [ { @@ -823,14 +866,51 @@ exports[`fixtures (JSON) > 'rest-props-multiple/input.svelte' 1`] = ` }" `; -exports[`fixtures (JSON) > 'slots-named/input.svelte' 1`] = ` +exports[`fixtures (JSON) "component-comment-single/input.svelte" 1`] = ` +"{ + "props": [], + "moduleExports": [], + "slots": [ + { + "name": "__default__", + "default": true, + "slot_props": "{}" + } + ], + "events": [], + "typedefs": [], + "componentComment": " Component comment" +}" +`; + +exports[`fixtures (JSON) "bind-this-multiple/input.svelte" 1`] = ` "{ "props": [ { - "name": "text", + "name": "ref", "kind": "let", - "type": "string", - "value": "\\"\\"", + "type": "null | HTMLButtonElement | HTMLHeadingElement", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": true, + "constant": false, + "reactive": true + }, + { + "name": "ref2", + "kind": "let", + "type": "null | HTMLDivElement", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": true, + "constant": false, + "reactive": true + }, + { + "name": "propBool", + "kind": "let", + "type": "boolean", + "value": "false", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, @@ -843,34 +923,60 @@ exports[`fixtures (JSON) > 'slots-named/input.svelte' 1`] = ` { "name": "__default__", "default": true, - "fallback": "Default text", "slot_props": "{}" - }, + } + ], + "events": [], + "typedefs": [] +}" +`; + +exports[`fixtures (JSON) "typedef/input.svelte" 1`] = ` +"{ + "props": [ { - "name": "bold heading", - "default": false, - "fallback": "{text}", - "slot_props": "{ text: string }" + "name": "id", + "kind": "let", + "type": "string", + "value": "\"id-\" + Math.random().toString(36)", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false }, { - "name": "subheading", - "default": false, - "fallback": "{text}", - "slot_props": "{ text: string }" - }, + "name": "prop1", + "kind": "let", + "type": "MyTypedef", + "value": "{ [\"1\"]: true }", + "isFunction": false, + "isFunctionDeclaration": false, + "isRequired": false, + "constant": false, + "reactive": false + } + ], + "moduleExports": [], + "slots": [ { - "name": "text", - "default": false, - "fallback": "{text}", - "slot_props": "{ text: string }" + "name": "__default__", + "default": true, + "slot_props": "{ prop1: MyTypedef }" } ], "events": [], - "typedefs": [] + "typedefs": [ + { + "type": "{ [key: string]: boolean; }", + "name": "MyTypedef", + "ts": "interface MyTypedef { [key: string]: boolean; }" + } + ] }" `; -exports[`fixtures (JSON) > 'slots-spread/input.svelte' 1`] = ` +exports[`fixtures (JSON) "anchor-props/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], @@ -878,21 +984,19 @@ exports[`fixtures (JSON) > 'slots-spread/input.svelte' 1`] = ` { "name": "__default__", "default": true, - "fallback": "Default text", - "slot_props": "{}" - }, - { - "name": "text", - "default": false, "slot_props": "{}" } ], "events": [], - "typedefs": [] + "typedefs": [], + "rest_props": { + "type": "Element", + "name": "a" + } }" `; -exports[`fixtures (JSON) > 'slots-spread-typed/input.svelte' 1`] = ` +exports[`fixtures (JSON) "component-comment-multi/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], @@ -900,116 +1004,52 @@ exports[`fixtures (JSON) > 'slots-spread-typed/input.svelte' 1`] = ` { "name": "__default__", "default": true, - "fallback": "Default text", - "slot_props": "{ a: number; }" - }, - { - "name": "text", - "default": false, - "slot_props": "{ a: number; }" + "slot_props": "{}" } ], "events": [], - "typedefs": [] + "typedefs": [], + "componentComment": "\n@example\n
\n Component comment\n
" }" `; -exports[`fixtures (JSON) > 'svg-props/input.svelte' 1`] = ` +exports[`fixtures (JSON) "slots-spread/input.svelte" 1`] = ` "{ "props": [], "moduleExports": [], - "slots": [], - "events": [], - "typedefs": [], - "rest_props": { - "type": "Element", - "name": "svg" - } -}" -`; - -exports[`fixtures (JSON) > 'typed-props/input.svelte' 1`] = ` -"{ - "props": [ - { - "name": "prop1", - "kind": "let", - "description": "prop1 description 1\\nprop1 description 2", - "type": "string", - "isFunction": false, - "isFunctionDeclaration": false, - "isRequired": true, - "constant": false, - "reactive": false - }, - { - "name": "prop2", - "kind": "let", - "description": "prop2 description 1\\nprop2 description 2", - "value": "null", - "isFunction": false, - "isFunctionDeclaration": false, - "isRequired": false, - "constant": false, - "reactive": false - }, + "slots": [ { - "name": "prop3", - "kind": "let", - "type": "4 | '4'", - "value": "4", - "isFunction": false, - "isFunctionDeclaration": false, - "isRequired": false, - "constant": false, - "reactive": false + "name": "__default__", + "default": true, + "fallback": "Default text", + "slot_props": "{}" }, { - "name": "prop4", - "kind": "let", - "type": "\\"red\\" | \\"blue\\"", - "value": "\\"red\\"", - "isFunction": false, - "isFunctionDeclaration": false, - "isRequired": false, - "constant": false, - "reactive": false + "name": "text", + "default": false, + "slot_props": "{}" } ], - "moduleExports": [], - "slots": [], "events": [], "typedefs": [] }" `; -exports[`fixtures (JSON) > 'typed-slots/input.svelte' 1`] = ` +exports[`fixtures (JSON) "slots-spread-typed/input.svelte" 1`] = ` "{ - "props": [ - { - "name": "prop", - "kind": "let", - "type": "number", - "value": "0", - "isFunction": false, - "isFunctionDeclaration": false, - "isRequired": false, - "constant": false, - "reactive": false - } - ], + "props": [], "moduleExports": [], "slots": [ { "name": "__default__", "default": true, - "slot_props": "{ prop: number; doubled: number; }" + "fallback": "Default text", + "slot_props": "{ a: number; }" }, { - "name": "description", + "name": "text", "default": false, - "slot_props": "{ props: { class?: string; } }", - "description": "description" + "slot_props": "{ a: number; }" } ], "events": [], @@ -1017,59 +1057,36 @@ exports[`fixtures (JSON) > 'typed-slots/input.svelte' 1`] = ` }" `; -exports[`fixtures (JSON) > 'typedef/input.svelte' 1`] = ` +exports[`fixtures (JSON) "typed-props/input.svelte" 1`] = ` "{ "props": [ { - "name": "id", + "name": "prop1", "kind": "let", + "description": "prop1 description 1\nprop1 description 2", "type": "string", - "value": "\\"id-\\" + Math.random().toString(36)", "isFunction": false, "isFunctionDeclaration": false, - "isRequired": false, + "isRequired": true, "constant": false, "reactive": false }, { - "name": "prop1", + "name": "prop2", "kind": "let", - "type": "MyTypedef", - "value": "{ [\\"1\\"]: true }", + "description": "prop2 description 1\nprop2 description 2", + "value": "null", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, "constant": false, "reactive": false - } - ], - "moduleExports": [], - "slots": [ - { - "name": "__default__", - "default": true, - "slot_props": "{ prop1: MyTypedef }" - } - ], - "events": [], - "typedefs": [ - { - "type": "{ [key: string]: boolean; }", - "name": "MyTypedef", - "ts": "interface MyTypedef { [key: string]: boolean; }" - } - ] -}" -`; - -exports[`fixtures (JSON) > 'typedefs/input.svelte' 1`] = ` -"{ - "props": [ + }, { - "name": "prop1", + "name": "prop3", "kind": "let", - "type": "MyTypedef", - "value": "{ [\\"1\\"]: true }", + "type": "4 | '4'", + "value": "4", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, @@ -1077,180 +1094,57 @@ exports[`fixtures (JSON) > 'typedefs/input.svelte' 1`] = ` "reactive": false }, { - "name": "prop2", + "name": "prop4", "kind": "let", - "type": "MyTypedefArray", - "value": "[]", + "type": "\"red\" | \"blue\"", + "value": "\"red\"", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, "constant": false, "reactive": false } - ], - "moduleExports": [], - "slots": [ - { - "name": "__default__", - "default": true, - "slot_props": "{ prop1: MyTypedef, prop2: MyTypedefArray }" - } - ], - "events": [], - "typedefs": [ - { - "type": "{ [key: string]: boolean; }", - "name": "MyTypedef", - "ts": "interface MyTypedef { [key: string]: boolean; }" - }, - { - "type": "MyTypedef[]", - "name": "MyTypedefArray", - "ts": "type MyTypedefArray = MyTypedef[]" - } - ] -}" -`; - -exports[`fixtures (TypeScript) > 'component-comment-single/input.svelte' 1`] = ` -"import type { SvelteComponentTyped } from "svelte"; -import type { SvelteHTMLElements } from "svelte/elements"; - -type RestProps = SvelteHTMLElements["a"]; - -export interface AnchorPropsProps extends RestProps { - [key: \`data-\${string}\`]: any; -} - -export default class AnchorProps extends SvelteComponentTyped, { default: {} }> {} -" -`; - -exports[`fixtures (TypeScript) > 'component-comment-single/input.svelte' 2`] = ` -"import type { SvelteComponentTyped } from "svelte"; - -export interface BindThisProps { - /** - * @default undefined - */ - ref: null | HTMLButtonElement; -} - -export default class BindThis extends SvelteComponentTyped, { default: {} }> {} -" -`; - -exports[`fixtures (TypeScript) > 'component-comment-single/input.svelte' 3`] = ` -"import type { SvelteComponentTyped } from "svelte"; - -export interface BindThisMultipleProps { - /** - * @default undefined - */ - ref: null | HTMLButtonElement | HTMLHeadingElement; - - /** - * @default undefined - */ - ref2: null | HTMLDivElement; - - /** - * @default false - */ - propBool?: boolean; -} - -export default class BindThisMultiple extends SvelteComponentTyped< - BindThisMultipleProps, - Record, - { default: {} } -> {} -" + ], + "moduleExports": [], + "slots": [], + "events": [], + "typedefs": [] +}" `; -exports[`fixtures (TypeScript) > 'component-comment-single/input.svelte' 4`] = ` +exports[`fixtures (TypeScript) "svg-props/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; -export interface ComponentCommentMultiProps {} - -/** - * @example - *
- * Component comment - *
- */ -export default class ComponentCommentMulti extends SvelteComponentTyped< - ComponentCommentMultiProps, - Record, - { default: {} } -> {} -" -`; - -exports[`fixtures (TypeScript) > 'component-comment-single/input.svelte' 5`] = ` -"import type { SvelteComponentTyped } from "svelte"; +type RestProps = SvelteHTMLElements["svg"]; -export interface ComponentCommentSingleProps {} +export interface SvgPropsProps extends RestProps { + [key: \`data-${string}\`]: any; +} -/** Component comment */ -export default class ComponentCommentSingle extends SvelteComponentTyped< - ComponentCommentSingleProps, - Record, - { default: {} } -> {} +export default class SvgProps extends SvelteComponentTyped, {}> {} " `; -exports[`fixtures (TypeScript) > 'context-module/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "slots-named/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; -export type bool = string; - -export type a = { b: 4 }; - -/** - * Description for e - */ -export type e = { [key: string]: any }; - -/** - * Log something - */ -export declare function log(message: string): void; - -export declare function b(): {}; - -export declare function b2(): () => {}; - -export declare function b3(): () => false; - -export interface ContextModuleProps {} - -export default class ContextModule extends SvelteComponentTyped, {}> { - a: string; +export interface SlotsNamedProps { + /** + * @default "" + */ + text?: string; } -" -`; - -exports[`fixtures (TypeScript) > 'dispatched-events/input.svelte' 1`] = ` -"import type { SvelteComponentTyped } from "svelte"; -export interface DispatchedEventsProps {} - -export default class DispatchedEvents extends SvelteComponentTyped< - DispatchedEventsProps, - { - hover: CustomEvent; - destroy: CustomEvent; - ["destroy--component"]: CustomEvent; - ["destroy:component"]: CustomEvent; - }, - { default: {} } +export default class SlotsNamed extends SvelteComponentTyped< + SlotsNamedProps, + Record, + { default: {}; ["bold heading"]: { text: string }; subheading: { text: string }; text: { text: string } } > {} " `; -exports[`fixtures (TypeScript) > 'dispatched-events-dynamic/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "dispatched-events-dynamic/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface DispatchedEventsDynamicProps {} @@ -1263,32 +1157,34 @@ export default class DispatchedEventsDynamic extends SvelteComponentTyped< " `; -exports[`fixtures (TypeScript) > 'dispatched-events-typed/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "function-declaration/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; -export interface DispatchedEventsTypedProps {} - -export default class DispatchedEventsTyped extends SvelteComponentTyped< - DispatchedEventsTypedProps, - { - /** Fired on mouseover. */ hover: CustomEvent<{ h1: boolean }>; - destroy: CustomEvent; - }, - { default: {} } -> {} -" -`; +export interface FunctionDeclarationProps { + /** + * @default () => {} + */ + fnA?: () => {}; +} -exports[`fixtures (TypeScript) > 'empty-export/input.svelte' 1`] = ` -"import type { SvelteComponentTyped } from "svelte"; +export default class FunctionDeclaration extends SvelteComponentTyped< + FunctionDeclarationProps, + Record, + {} +> { + fnB: () => {}; -export interface EmptyExportProps {} + add: () => any; -export default class EmptyExport extends SvelteComponentTyped, {}> {} + /** + * Multiplies two numbers + */ + multiply: (a: number, b: number) => number; +} " `; -exports[`fixtures (TypeScript) > 'forwarded-events/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "forwarded-events/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface ForwardedEventsProps {} @@ -1306,34 +1202,20 @@ export default class ForwardedEvents extends SvelteComponentTyped< " `; -exports[`fixtures (TypeScript) > 'function-declaration/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "mixed-events/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; -export interface FunctionDeclarationProps { - /** - * @default () => {} - */ - fnA?: () => {}; -} +export interface MixedEventsProps {} -export default class FunctionDeclaration extends SvelteComponentTyped< - FunctionDeclarationProps, - Record, +export default class MixedEvents extends SvelteComponentTyped< + MixedEventsProps, + { ["custom-focus"]: CustomEvent; blur: FocusEvent | CustomEvent }, {} -> { - fnB: () => {}; - - add: () => any; - - /** - * Multiplies two numbers - */ - multiply: (a: number, b: number) => number; -} +> {} " `; -exports[`fixtures (TypeScript) > 'infer-basic/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "infer-basic/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface InferBasicProps { @@ -1371,44 +1253,115 @@ export default class InferBasic extends SvelteComponentTyped 'infer-with-types/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "empty-export/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; -export interface InferWithTypesProps { - /** - * @default true - */ - propBool?: boolean; +export interface EmptyExportProps {} + +export default class EmptyExport extends SvelteComponentTyped, {}> {} +" +`; + +exports[`fixtures (TypeScript) "typed-slots/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; +export interface TypedSlotsProps { /** - * @default "" + * @default 0 */ - propString?: string; + prop?: number; +} + +export default class TypedSlots extends SvelteComponentTyped< + TypedSlotsProps, + Record, + { + default: { prop: number; doubled: number }; + /** description */ + description: { props: { class?: string } }; + } +> {} +" +`; + +exports[`fixtures (TypeScript) "dispatched-events/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export interface DispatchedEventsProps {} + +export default class DispatchedEvents extends SvelteComponentTyped< + DispatchedEventsProps, + { + hover: CustomEvent; + destroy: CustomEvent; + ["destroy--component"]: CustomEvent; + ["destroy:component"]: CustomEvent; + }, + { default: {} } +> {} +" +`; + +exports[`fixtures (TypeScript) "typedefs/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export interface MyTypedef { + [key: string]: boolean; +} + +export type MyTypedefArray = MyTypedef[]; +export interface TypedefsProps { /** - * @default undefined + * @default { ["1"]: true } */ - name: string; + prop1?: MyTypedef; /** - * @default "" + Math.random().toString(36) + * @default [] */ - id?: string; + prop2?: MyTypedefArray; } -export default class InferWithTypes extends SvelteComponentTyped< - InferWithTypesProps, +export default class Typedefs extends SvelteComponentTyped< + TypedefsProps, Record, - { default: {} } -> { - propConst: { [key: string]: boolean }; + { default: { prop1: MyTypedef; prop2: MyTypedefArray } } +> {} +" +`; - fn: () => any; +exports[`fixtures (TypeScript) "bind-this/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export interface BindThisProps { + /** + * @default undefined + */ + ref: null | HTMLButtonElement; } + +export default class BindThis extends SvelteComponentTyped, { default: {} }> {} +" +`; + +exports[`fixtures (TypeScript) "dispatched-events-typed/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export interface DispatchedEventsTypedProps {} + +export default class DispatchedEventsTyped extends SvelteComponentTyped< + DispatchedEventsTypedProps, + { + /** Fired on mouseover. */ hover: CustomEvent<{ h1: boolean }>; + destroy: CustomEvent; + }, + { default: {} } +> {} " `; -exports[`fixtures (TypeScript) > 'input-events/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "input-events/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface InputEventsProps {} @@ -1425,20 +1378,43 @@ export default class InputEvents extends SvelteComponentTyped< " `; -exports[`fixtures (TypeScript) > 'mixed-events/input.svelte' 1`] = ` -"import type { SvelteComponentTyped } from "svelte"; +exports[`fixtures (TypeScript) "required/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export interface RequiredProps { + /** + * @required + * @default true + */ + prop?: boolean; + + /** + * This is a comment. + * @required + * @default true + */ + prop1?: boolean | string; + + /** + * @default undefined + */ + prop2: undefined; -export interface MixedEventsProps {} + /** + * @default undefined + */ + prop3: boolean; +} -export default class MixedEvents extends SvelteComponentTyped< - MixedEventsProps, - { ["custom-focus"]: CustomEvent; blur: FocusEvent | CustomEvent }, - {} +export default class Required extends SvelteComponentTyped< + RequiredProps, + Record, + { default: { prop: boolean; prop1: boolean | string; prop2: any; prop3: boolean } } > {} " `; -exports[`fixtures (TypeScript) > 'prop-comments/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "prop-comments/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface PropCommentsProps { @@ -1471,7 +1447,7 @@ export default class PropComments extends SvelteComponentTyped< " `; -exports[`fixtures (TypeScript) > 'renamed-props/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "renamed-props/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface RenamedPropsProps { @@ -1486,57 +1462,89 @@ export default class RenamedProps extends SvelteComponentTyped 'required/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "infer-with-types/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; -export interface RequiredProps { +export interface InferWithTypesProps { /** - * @required * @default true */ - prop?: boolean; + propBool?: boolean; /** - * This is a comment. - * @required - * @default true + * @default "" */ - prop1?: boolean | string; + propString?: string; /** * @default undefined */ - prop2: undefined; + name: string; /** - * @default undefined + * @default "" + Math.random().toString(36) */ - prop3: boolean; + id?: string; } -export default class Required extends SvelteComponentTyped< - RequiredProps, +export default class InferWithTypes extends SvelteComponentTyped< + InferWithTypesProps, Record, - { default: { prop: boolean; prop1: boolean | string; prop2: any; prop3: boolean } } -> {} + { default: {} } +> { + propConst: { [key: string]: boolean }; + + fn: () => any; +} +" +`; + +exports[`fixtures (TypeScript) "context-module/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export type bool = string; + +export type a = { b: 4 }; + +/** + * Description for e + */ +export type e = { [key: string]: any }; + +/** + * Log something + */ +export declare function log(message: string): void; + +export declare function b(): {}; + +export declare function b2(): () => {}; + +export declare function b3(): () => false; + +export interface ContextModuleProps {} + +export default class ContextModule extends SvelteComponentTyped, {}> { + a: string; +} " `; -exports[`fixtures (TypeScript) > 'rest-props/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "rest-props/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type RestProps = SvelteHTMLElements["h1"]; export interface RestPropsProps extends RestProps { - [key: \`data-\${string}\`]: any; + [key: \`data-${string}\`]: any; } export default class RestProps extends SvelteComponentTyped, {}> {} " `; -exports[`fixtures (TypeScript) > 'rest-props-multiple/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "rest-props-multiple/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; @@ -1553,32 +1561,116 @@ export interface RestPropsMultipleProps extends RestProps { */ heading?: boolean; - [key: \`data-\${string}\`]: any; + [key: \`data-${string}\`]: any; } export default class RestPropsMultiple extends SvelteComponentTyped, {}> {} " `; -exports[`fixtures (TypeScript) > 'slots-named/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "component-comment-single/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; -export interface SlotsNamedProps { +export interface ComponentCommentSingleProps {} + +/** Component comment */ +export default class ComponentCommentSingle extends SvelteComponentTyped< + ComponentCommentSingleProps, + Record, + { default: {} } +> {} +" +`; + +exports[`fixtures (TypeScript) "bind-this-multiple/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export interface BindThisMultipleProps { /** - * @default "" + * @default undefined */ - text?: string; + ref: null | HTMLButtonElement | HTMLHeadingElement; + + /** + * @default undefined + */ + ref2: null | HTMLDivElement; + + /** + * @default false + */ + propBool?: boolean; } -export default class SlotsNamed extends SvelteComponentTyped< - SlotsNamedProps, +export default class BindThisMultiple extends SvelteComponentTyped< + BindThisMultipleProps, Record, - { default: {}; ["bold heading"]: { text: string }; subheading: { text: string }; text: { text: string } } + { default: {} } +> {} +" +`; + +exports[`fixtures (TypeScript) "typedef/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export interface MyTypedef { + [key: string]: boolean; +} + +export interface TypedefProps { + /** + * @default "id-" + Math.random().toString(36) + */ + id?: string; + + /** + * @default { ["1"]: true } + */ + prop1?: MyTypedef; +} + +export default class Typedef extends SvelteComponentTyped< + TypedefProps, + Record, + { default: { prop1: MyTypedef } } +> {} +" +`; + +exports[`fixtures (TypeScript) "anchor-props/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; + +type RestProps = SvelteHTMLElements["a"]; + +export interface AnchorPropsProps extends RestProps { + [key: \`data-${string}\`]: any; +} + +export default class AnchorProps extends SvelteComponentTyped, { default: {} }> {} +" +`; + +exports[`fixtures (TypeScript) "component-comment-multi/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; + +export interface ComponentCommentMultiProps {} + +/** + * @example + *
+ * Component comment + *
+ */ +export default class ComponentCommentMulti extends SvelteComponentTyped< + ComponentCommentMultiProps, + Record, + { default: {} } > {} " `; -exports[`fixtures (TypeScript) > 'slots-spread/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "slots-spread/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface SlotsSpreadProps {} @@ -1591,7 +1683,7 @@ export default class SlotsSpread extends SvelteComponentTyped< " `; -exports[`fixtures (TypeScript) > 'slots-spread-typed/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "slots-spread-typed/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface SlotsSpreadTypedProps {} @@ -1604,21 +1696,7 @@ export default class SlotsSpreadTyped extends SvelteComponentTyped< " `; -exports[`fixtures (TypeScript) > 'svg-props/input.svelte' 1`] = ` -"import type { SvelteComponentTyped } from "svelte"; -import type { SvelteHTMLElements } from "svelte/elements"; - -type RestProps = SvelteHTMLElements["svg"]; - -export interface SvgPropsProps extends RestProps { - [key: \`data-\${string}\`]: any; -} - -export default class SvgProps extends SvelteComponentTyped, {}> {} -" -`; - -exports[`fixtures (TypeScript) > 'typed-props/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "typed-props/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; export interface TypedPropsProps { @@ -1651,80 +1729,68 @@ export default class TypedProps extends SvelteComponentTyped 'typed-slots/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "svg-props/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; -export interface TypedSlotsProps { - /** - * @default 0 - */ - prop?: number; +type RestProps = SvelteHTMLElements["svg"]; + +export interface SvgPropsProps extends RestProps { + [key: \`data-${string}\`]: any; } -export default class TypedSlots extends SvelteComponentTyped< - TypedSlotsProps, - Record, - { - default: { prop: number; doubled: number }; - /** description */ - description: { props: { class?: string } }; - } -> {} +export default class SvgProps extends SvelteComponentTyped, {}> {} " `; -exports[`fixtures (TypeScript) > 'typedef/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "rest-props/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; -export interface MyTypedef { - [key: string]: boolean; +type RestProps = SvelteHTMLElements["h1"]; + +export interface RestPropsProps extends RestProps { + [key: \`data-${string}\`]: any; } -export interface TypedefProps { +export default class RestProps extends SvelteComponentTyped, {}> {} +" +`; + +exports[`fixtures (TypeScript) "rest-props-multiple/input.svelte" 1`] = ` +"import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; + +type RestProps = SvelteHTMLElements["h1"] & SvelteHTMLElements["span"]; + +export interface RestPropsMultipleProps extends RestProps { /** - * @default "id-" + Math.random().toString(36) + * @default false */ - id?: string; + edit?: boolean; /** - * @default { ["1"]: true } + * @default false */ - prop1?: MyTypedef; + heading?: boolean; + + [key: \`data-${string}\`]: any; } -export default class Typedef extends SvelteComponentTyped< - TypedefProps, - Record, - { default: { prop1: MyTypedef } } -> {} +export default class RestPropsMultiple extends SvelteComponentTyped, {}> {} " `; -exports[`fixtures (TypeScript) > 'typedefs/input.svelte' 1`] = ` +exports[`fixtures (TypeScript) "anchor-props/input.svelte" 1`] = ` "import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; -export interface MyTypedef { - [key: string]: boolean; -} - -export type MyTypedefArray = MyTypedef[]; - -export interface TypedefsProps { - /** - * @default { ["1"]: true } - */ - prop1?: MyTypedef; +type RestProps = SvelteHTMLElements["a"]; - /** - * @default [] - */ - prop2?: MyTypedefArray; +export interface AnchorPropsProps extends RestProps { + [key: \`data-${string}\`]: any; } -export default class Typedefs extends SvelteComponentTyped< - TypedefsProps, - Record, - { default: { prop1: MyTypedef; prop2: MyTypedefArray } } -> {} +export default class AnchorProps extends SvelteComponentTyped, { default: {} }> {} " `; diff --git a/tests/fixtures.test.ts b/tests/fixtures.test.ts index 4e854dc..a468426 100644 --- a/tests/fixtures.test.ts +++ b/tests/fixtures.test.ts @@ -1,32 +1,41 @@ -import fg from "fast-glob"; -import fs from "node:fs" -import fsp from "node:fs/promises"; +import { Glob } from "bun"; import path from "node:path"; import ComponentParser from "../src/ComponentParser"; import Writer from "../src/writer/Writer"; import { writeTsDefinition } from "../src/writer/writer-ts-definitions"; const folder = path.join(process.cwd(), "tests", "fixtures"); -const svelteFiles = fg.sync(["**/*.svelte"], { cwd: folder }); -const fixtures = svelteFiles.map((file) => { - return { - path: file, - source: fs.readFileSync(path.join(folder, file), "utf-8"), - }; -}); +const fixtures_map = new Map(); + +for await (const file of new Glob("**/*.svelte").scan(folder)) { + const source = await Bun.file(path.join(folder, file)).text(); + fixtures_map.set(file, source); +} + +const createMetadata = (filePath: string) => { + const { dir } = path.parse(filePath); + const moduleName = dir + .split("-") + .map((s) => s.charAt(0).toUpperCase() + s.slice(1)) + .join(""); + + return { dir, moduleName, filePath }; +}; const parser = new ComponentParser(); const writer = new Writer({ parser: "typescript", printWidth: 120 }); +const files = Array.from(fixtures_map.keys()); -const getMetadata = (fixture: (typeof fixtures)[0]) => { - const { dir } = path.parse(fixture.path); +const getMetadata = (fixture: { filePath: string; source: string }) => { + const { filePath, source } = fixture; + const { dir } = path.parse(filePath); const moduleName = dir .split("-") .map((s) => s.charAt(0).toUpperCase() + s.slice(1)) .join(""); - const metadata = { moduleName, filePath: fixture.path }; - const parsed_component = parser.parseSvelteComponent(fixture.source, { - filePath: fixture.path, + const metadata = { moduleName, filePath }; + const parsed_component = parser.parseSvelteComponent(source, { + filePath, moduleName, }); @@ -34,27 +43,33 @@ const getMetadata = (fixture: (typeof fixtures)[0]) => { }; describe("fixtures (JSON)", async () => { - test.concurrent.each(fixtures)("$path", async (fixture) => { - const { dir, parsed_component } = getMetadata(fixture); + test.each(files)("%p", async (filePath) => { + const { dir, parsed_component } = getMetadata({ + filePath, + source: fixtures_map.get(filePath)!, + }); const api_json = JSON.stringify(parsed_component, null, 2); // Snapshot the output; if the test fails, output has changed. expect(api_json).toMatchSnapshot(); // Still write to disk to manually assert types as needed. - await fsp.writeFile(path.join(folder, dir, "output.json"), api_json); + await Bun.write(path.join(folder, dir, "output.json"), api_json); }); }); describe("fixtures (TypeScript)", async () => { - test.concurrent.each(fixtures)("$path", async (fixture) => { - const { dir, metadata, parsed_component } = getMetadata(fixture); + test.each(files)("%p", async (filePath) => { + const { dir, metadata, parsed_component } = getMetadata({ + filePath, + source: fixtures_map.get(filePath)!, + }); const api_ts = writer.format(writeTsDefinition({ ...metadata, ...parsed_component })); // Snapshot the output; if the test fails, output has changed. expect(api_ts).toMatchSnapshot(); // Still write to disk to manually assert types as needed. - await fsp.writeFile(path.join(folder, dir, "output.d.ts"), api_ts); + await Bun.write(path.join(folder, dir, "output.d.ts"), api_ts); }); });