diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index ba78e51afa..763e13abc1 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -270,13 +270,16 @@ export default function dom( addToSet(all_reactive_dependencies, d.dependencies); }); + const user_code = component.javascript || ( + component.ast.js.length === 0 && filtered_props.length > 0 + ? `let { ${filtered_props.map(x => x.name === x.as ? x.as : `${x.as}: ${x.name}`).join(', ')} } = $$props;` + : null + ); + if (has_definition) { builder.addBlock(deindent` function ${definition}(${args.join(', ')}) { - ${component.javascript || ( - filtered_props.length > 0 && - `let { ${filtered_props.map(x => x.name === x.as ? x.as : `${x.as}: ${x.name}`).join(', ')} } = $$props;` - )} + ${user_code} ${component.partly_hoisted.length > 0 && component.partly_hoisted.join('\n\n')} diff --git a/src/compile/render-ssr/index.ts b/src/compile/render-ssr/index.ts index 71bc2f0155..28d47475a5 100644 --- a/src/compile/render-ssr/index.ts +++ b/src/compile/render-ssr/index.ts @@ -22,18 +22,18 @@ export default function ssr( { code: null, map: null } : component.stylesheet.render(options.filename, true); - let setup; + let user_code; if (component.javascript) { - setup = component.javascript; - } else if (component.props.length > 0) { + user_code = component.javascript; + } else if (component.ast.js.length === 0 && component.props.length > 0) { const props = component.props.map(prop => { return prop.as === prop.name ? prop.as : `${prop.as}: ${prop.name}` }); - setup = `let { ${props.join(', ')} } = $$props;` + user_code = `let { ${props.join(', ')} } = $$props;` } // TODO only do this for props with a default value @@ -64,7 +64,7 @@ export default function ssr( return \`${renderer.code}\`;`; const blocks = [ - setup, + user_code, parent_bindings.join('\n'), css.code && `$$result.css.add(#css);`, main diff --git a/test/runtime/samples/module-context/_config.js b/test/runtime/samples/module-context/_config.js new file mode 100644 index 0000000000..0ea26ee446 --- /dev/null +++ b/test/runtime/samples/module-context/_config.js @@ -0,0 +1,3 @@ +export default { + html: `
42
` +}; \ No newline at end of file diff --git a/test/runtime/samples/module-context/main.html b/test/runtime/samples/module-context/main.html new file mode 100644 index 0000000000..851d98bea3 --- /dev/null +++ b/test/runtime/samples/module-context/main.html @@ -0,0 +1,5 @@ + + +{foo}
\ No newline at end of file