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
6 changes: 5 additions & 1 deletion packages/svelte2tsx/src/svelte2tsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,11 @@ export function svelte2tsx(
processModuleScriptTag(
str,
moduleScriptTag,
new ImplicitStoreValues(implicitStoreValues.getAccessedStores(), renderFunctionStart)
new ImplicitStoreValues(
implicitStoreValues.getAccessedStores(),
renderFunctionStart,
scriptTag ? undefined : (input) => `</>;${input}<>`
)
);
}

Expand Down
10 changes: 7 additions & 3 deletions packages/svelte2tsx/src/svelte2tsx/nodes/ImplicitStoreValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class ImplicitStoreValues {
public addReactiveDeclaration = this.reactiveDeclarations.push.bind(this.reactiveDeclarations);
public addImportStatement = this.importStatements.push.bind(this.importStatements);

constructor(storesResolvedInTemplate: string[] = [], private renderFunctionStart: number) {
constructor(
storesResolvedInTemplate: string[] = [],
private renderFunctionStart: number,
private storeFromImportsWrapper = (input: string) => input
) {
storesResolvedInTemplate.forEach(this.addStoreAcess);
}

Expand Down Expand Up @@ -103,8 +107,8 @@ export class ImplicitStoreValues {
return;
}

const storeDeclarations = surroundWithIgnoreComments(
this.createStoreDeclarations(storeNames)
const storeDeclarations = this.storeFromImportsWrapper(
surroundWithIgnoreComments(this.createStoreDeclarations(storeNames))
);

str.appendRight(this.renderFunctionStart, storeDeclarations);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
///<reference types="svelte" />
<></>;
import { store1 } from './somewhere';
const store2 = ''/*Ωignore_startΩ*/;let $store2 = __sveltets_1_store_get(store2);/*Ωignore_endΩ*/;
;<></>;function render() {
<></>;/*Ωignore_startΩ*/;let $store1 = __sveltets_1_store_get(store1);/*Ωignore_endΩ*/<>

{(__sveltets_1_store_get(store1), $store1)}
{(__sveltets_1_store_get(store2), $store2)}</>
return { props: {}, slots: {}, getters: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script context="module">
import { store1 } from './somewhere';
const store2 = '';
</script>

{$store1}
{$store2}