diff --git a/src/compile/wrapModule.ts b/src/compile/wrapModule.ts
index d4f8198bc0..05d33f7fd4 100644
--- a/src/compile/wrapModule.ts
+++ b/src/compile/wrapModule.ts
@@ -41,6 +41,12 @@ export default function wrapModule(
throw new Error(`options.format is invalid (must be ${list(Object.keys(wrappers))})`);
}
+function editSource(source, sveltePath) {
+ return source === 'svelte' || source.startsWith('svelte/')
+ ? source.replace('svelte', sveltePath)
+ : source;
+}
+
function esm(
code: string,
name: string,
@@ -60,7 +66,7 @@ function esm(
const importBlock = imports.length > 0 && (
imports
.map((declaration: Node) => {
- const import_source = declaration.source.value === 'svelte' ? sveltePath : declaration.source.value;
+ const import_source = editSource(declaration.source.value, sveltePath);
return (
source.slice(declaration.start, declaration.source.start) +
@@ -117,9 +123,7 @@ function cjs(
lhs = `{ ${properties.join(', ')} }`;
}
- const source = node.source.value === 'svelte'
- ? sveltePath
- : node.source.value;
+ const source = editSource(node.source.value, sveltePath);
return `const ${lhs} = require("${source}");`
});
diff --git a/test/runtime/samples/context-api/Tab.html b/test/runtime/samples/context-api/Tab.html
new file mode 100644
index 0000000000..720d5da9de
--- /dev/null
+++ b/test/runtime/samples/context-api/Tab.html
@@ -0,0 +1,17 @@
+
+
+
\ No newline at end of file
diff --git a/test/runtime/samples/context-api/TabList.html b/test/runtime/samples/context-api/TabList.html
new file mode 100644
index 0000000000..08c86216ae
--- /dev/null
+++ b/test/runtime/samples/context-api/TabList.html
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/test/runtime/samples/context-api/TabPanel.html b/test/runtime/samples/context-api/TabPanel.html
new file mode 100644
index 0000000000..7802ffac26
--- /dev/null
+++ b/test/runtime/samples/context-api/TabPanel.html
@@ -0,0 +1,16 @@
+
+
+{#if $selected === panel}
+
+{/if}
\ No newline at end of file
diff --git a/test/runtime/samples/context-api/Tabs.html b/test/runtime/samples/context-api/Tabs.html
new file mode 100644
index 0000000000..8bbe89a017
--- /dev/null
+++ b/test/runtime/samples/context-api/Tabs.html
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/runtime/samples/context-api/_config.js b/test/runtime/samples/context-api/_config.js
new file mode 100644
index 0000000000..0a8c2f1780
--- /dev/null
+++ b/test/runtime/samples/context-api/_config.js
@@ -0,0 +1,73 @@
+export default {
+ html: `
+
+
+
+
+
+
+
Small panel
+
+ `,
+
+ async test({ assert, component, target, window }) {
+ const click = new window.MouseEvent('click');
+ let buttons = target.querySelectorAll('button');
+
+ await buttons[1].dispatchEvent(click);
+
+ assert.htmlEqual(target.innerHTML, `
+
+
+
+
+
+
+
Large panel
+
+ `);
+
+ component.show_medium = true;
+
+ assert.htmlEqual(target.innerHTML, `
+
+
+
+
+
+
+
+
Large panel
+
+ `);
+
+ buttons = target.querySelectorAll('button');
+
+ await buttons[1].dispatchEvent(click);
+
+ assert.htmlEqual(target.innerHTML, `
+
+
+
+
+
+
+
+
Medium panel
+
+ `);
+
+ component.show_medium = false;
+
+ assert.htmlEqual(target.innerHTML, `
+
+
+
+
+
+
+
Large panel
+
+ `);
+ }
+};
\ No newline at end of file
diff --git a/test/runtime/samples/context-api/main.html b/test/runtime/samples/context-api/main.html
new file mode 100644
index 0000000000..ef3ee996d5
--- /dev/null
+++ b/test/runtime/samples/context-api/main.html
@@ -0,0 +1,30 @@
+
+
+
+
+ small
+ {#if show_medium}medium{/if}
+ large
+
+
+
+ Small panel
+
+
+ {#if show_medium}
+
+ Medium panel
+
+ {/if}
+
+
+ Large panel
+
+
\ No newline at end of file