Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions packages/svelte2tsx/src/svelte2tsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte2tsx/src/svelte2tsx/nodes/exportgetters.ts
Original file line number Diff line number Diff line change
@@ -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<string>) => {
return Array.from(names).map(createClassGetter).join('');
};
Expand Down
5 changes: 2 additions & 3 deletions packages/svelte2tsx/src/svelte2tsx/nodes/exportsetters.ts
Original file line number Diff line number Diff line change
@@ -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<string>) => {
return Array.from(names).map(createClassSetter).join('');
Expand All @@ -9,4 +8,4 @@ export const createClassSetters = (names: Set<string>) => {
export function createRenderFunctionSetterStr(setters: Set<string>) {
const properties = Array.from(setters).map((name) => `${name}: ${name}`);
return `{${properties.join(', ')}}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{...__sveltets_ensureAnimation((__sveltets_store_get(animateStore), $animateStore)(__sveltets_mapElementTag('div'),__sveltets_AnimationMove,{}))}
>
</div></>);
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))) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function render() {
() => (<>

<input onfocus={undefined} /></>);
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))) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}