From 691bb7692883758c672209a73abbcef8704ece37 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 19 Mar 2021 14:16:14 +0100 Subject: [PATCH 1/2] (chore) fix tests + lint --- packages/svelte2tsx/src/svelte2tsx/index.ts | 20 ++++++++++++++----- .../src/svelte2tsx/nodes/exportsetters.ts | 2 +- .../samples/$store-as-directive/expected.tsx | 2 +- .../event-and-forwarded-event/expected.tsx | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/svelte2tsx/src/svelte2tsx/index.ts b/packages/svelte2tsx/src/svelte2tsx/index.ts index 6d8a7e1b3..72ee25cb5 100644 --- a/packages/svelte2tsx/src/svelte2tsx/index.ts +++ b/packages/svelte2tsx/src/svelte2tsx/index.ts @@ -329,16 +329,20 @@ function addComponentExport({ ? uses$$propsOr$$restProps ? `__sveltets_with_any(${eventsDef})` : eventsDef - : `__sveltets_partial${isTsFile ? '_ts' : ''}${uses$$propsOr$$restProps ? '_with_any' : '' - }(${eventsDef})`; + : `__sveltets_partial${isTsFile ? '_ts' : ''}${ + uses$$propsOr$$restProps ? '_with_any' : '' + }(${eventsDef})`; const doc = componentDocumentation.getFormatted(); const className = fileName && classNameFromFilename(fileName); const statement = - `\n\n${doc}export default class${className ? ` ${className}` : '' + `\n\n${doc}export default class${ + className ? ` ${className}` : '' } extends createSvelte2TsxComponent(${propDef}) {` + - createClassGetters(getters) + createClassSetters(setters) + '\n}'; + createClassGetters(getters) + + createClassSetters(setters) + + '\n}'; str.append(statement); } @@ -501,7 +505,13 @@ export function svelte2tsx( if (scriptTag.start != instanceScriptTarget) { str.move(scriptTag.start, scriptTag.end, instanceScriptTarget); } - const res = processInstanceScriptContent(str, scriptTag, events, implicitStoreValues, usesAccessors); + const res = processInstanceScriptContent( + str, + scriptTag, + events, + implicitStoreValues, + usesAccessors + ); uses$$props = uses$$props || res.uses$$props; uses$$restProps = uses$$restProps || res.uses$$restProps; uses$$slots = uses$$slots || res.uses$$slots; diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts index 13e673d13..8dd9de048 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts @@ -9,4 +9,4 @@ export const createClassSetters = (names: Set) => { export function createRenderFunctionSetterStr(setters: Set) { const properties = Array.from(setters).map((name) => `${name}: ${name}`); return `{${properties.join(', ')}}`; -} \ No newline at end of file +} diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/$store-as-directive/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/$store-as-directive/expected.tsx index 9208f1ff9..bdfcab9c3 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/$store-as-directive/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/$store-as-directive/expected.tsx @@ -17,7 +17,7 @@ {...__sveltets_ensureAnimation((__sveltets_store_get(animateStore), $animateStore)(__sveltets_mapElementTag('div'),__sveltets_AnimationMove,{}))} > ); -return { props: {}, slots: {}, getters: {}, events: {} }} +return { props: {}, slots: {}, getters: {}, setters: {}, events: {} }} export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { } \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/event-and-forwarded-event/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/event-and-forwarded-event/expected.tsx index 0514ab40f..f27cf9c62 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/event-and-forwarded-event/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/event-and-forwarded-event/expected.tsx @@ -11,7 +11,7 @@ function render() { () => (<> ); -return { props: {}, slots: {}, getters: {}, events: {'focus':__sveltets_mapElementEvent('focus'), 'mount': __sveltets_customEvent} }} +return { props: {}, slots: {}, getters: {}, setters: {}, events: {'focus':__sveltets_mapElementEvent('focus'), 'mount': __sveltets_customEvent} }} export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { } \ No newline at end of file From 3cc71dd4c674f3713c5cccf4eb7a26f8c484aefd Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 19 Mar 2021 14:19:54 +0100 Subject: [PATCH 2/2] codestyle --- packages/svelte2tsx/src/svelte2tsx/nodes/exportgetters.ts | 2 +- packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts | 3 +-- .../samples/uses-accessors-attr-present/expected.tsx | 1 - .../samples/uses-accessors-mustachetag-true/expected.tsx | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/exportgetters.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/exportgetters.ts index 63edf45cd..93947be33 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/exportgetters.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/exportgetters.ts @@ -1,5 +1,5 @@ export const createClassGetter = (name: string) => - `\n${' '.repeat(4)}get ${name}() { return render().getters.${name} }`; + `\n get ${name}() { return render().getters.${name} }`; export const createClassGetters = (names: Set) => { return Array.from(names).map(createClassGetter).join(''); }; diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts index 8dd9de048..8331ef887 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts @@ -1,6 +1,5 @@ export const createClassSetter = (name: string) => - `\n - /**accessor*/\n${' '.repeat(4)}set ${name}(${name}) {}`; + `\n /**accessor*/\n set ${name}(${name}) {}`; export const createClassSetters = (names: Set) => { return Array.from(names).map(createClassSetter).join(''); diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-accessors-attr-present/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-accessors-attr-present/expected.tsx index dd62d9557..463521165 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-accessors-attr-present/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-accessors-attr-present/expected.tsx @@ -11,7 +11,6 @@ return { props: {foo: foo , bar: bar}, slots: {}, getters: {foo: foo, bar: bar}, export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { get foo() { return render().getters.foo } get bar() { return render().getters.bar } - /**accessor*/ set foo(foo) {} } \ No newline at end of file diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/uses-accessors-mustachetag-true/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/uses-accessors-mustachetag-true/expected.tsx index 4bc45690b..dfdf2208c 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/uses-accessors-mustachetag-true/expected.tsx +++ b/packages/svelte2tsx/test/svelte2tsx/samples/uses-accessors-mustachetag-true/expected.tsx @@ -11,7 +11,6 @@ return { props: {foo: foo , bar: bar}, slots: {}, getters: {foo: foo, bar: bar}, export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { get foo() { return render().getters.foo } get bar() { return render().getters.bar } - /**accessor*/ set foo(foo) {} } \ No newline at end of file