chore: directly export function in non-HMR mode (#11333)

* chore: directly export function in non-HMR mode

* remove some more noise

* update snapshots

* Update sites/svelte-5-preview/src/lib/workers/compiler/index.js

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
pull/11340/head
Rich Harris 8 months ago committed by GitHub
parent 8e17428316
commit 9a887f8dab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -430,18 +430,17 @@ export function client_component(source, analysis, options) {
component_block.body.unshift(b.const('$$slots', b.call('$.sanitize_slots', b.id('$$props'))));
}
const body = [
...state.hoisted,
...module.body,
b.function_declaration(
b.id(analysis.name),
[b.id('$$anchor'), b.id('$$props')],
component_block
)
];
const body = [...state.hoisted, ...module.body];
const component = b.function_declaration(
b.id(analysis.name),
[b.id('$$anchor'), b.id('$$props')],
component_block
);
if (options.hmr) {
body.push(
component,
b.if(
b.id('import.meta.hot'),
b.block([
@ -459,12 +458,14 @@ export function client_component(source, analysis, options) {
)
)
])
)
),
b.export_default(b.id(analysis.name))
);
} else {
body.push(b.export_default(component));
}
body.push(b.export_default(b.id(analysis.name)));
if (options.dev) {
if (options.filename) {
let filename = options.filename;

@ -30,20 +30,6 @@ export function transform_component(analysis, source, options) {
? server_component(analysis, options)
: client_component(source, analysis, options);
const basename = (options.filename ?? 'Component').split(/[/\\]/).at(-1);
if (program.body.length > 0) {
program.body[0].leadingComments = [
{
type: 'Line',
value: ` ${basename} (Svelte v${VERSION})`
},
{
type: 'Line',
value: ' Note: compiler output will change before 5.0 is released!'
}
];
}
const js_source_name = get_source_name(options.filename, options.outputFilename, 'input.svelte');
const js = print(program, {
// include source content; makes it easier/more robust looking up the source map code

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
import TextInput from './Child.svelte';
@ -7,7 +5,7 @@ import TextInput from './Child.svelte';
var root_1 = $.template(`Something`, 1);
var root = $.template(`<!> `, 1);
function Bind_component_snippet($$anchor, $$props) {
export default function Bind_component_snippet($$anchor, $$props) {
$.push($$props, true);
let value = $.source('');
@ -36,6 +34,4 @@ function Bind_component_snippet($$anchor, $$props) {
$.render_effect(() => $.set_text(text, ` value: ${$.stringify($.get(value))}`));
$.append($$anchor, fragment_1);
$.pop();
}
export default Bind_component_snippet;
}

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
import TextInput from './Child.svelte';

@ -1,9 +1,7 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
function Bind_this($$anchor, $$props) {
export default function Bind_this($$anchor, $$props) {
$.push($$props, false);
$.init();
@ -13,6 +11,4 @@ function Bind_this($$anchor, $$props) {
$.bind_this(Foo(node, {}), ($$value) => foo = $$value, () => foo);
$.append($$anchor, fragment);
$.pop();
}
export default Bind_this;
}

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Bind_this($$payload, $$props) {

@ -1,9 +1,7 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
function Class_state_field_constructor_assignment($$anchor, $$props) {
export default function Class_state_field_constructor_assignment($$anchor, $$props) {
$.push($$props, true);
class Foo {
@ -26,6 +24,4 @@ function Class_state_field_constructor_assignment($$anchor, $$props) {
}
$.pop();
}
export default Class_state_field_constructor_assignment;
}

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Class_state_field_constructor_assignment($$payload, $$props) {

@ -1,11 +1,9 @@
// main.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
var root = $.template(`<div></div> <svg></svg> <custom-element></custom-element> <div></div> <svg></svg> <custom-element></custom-element>`, 3);
function Main($$anchor, $$props) {
export default function Main($$anchor, $$props) {
$.push($$props, true);
// needs to be a snapshot test because jsdom does auto-correct the attribute casing
@ -35,6 +33,4 @@ function Main($$anchor, $$props) {
$.append($$anchor, fragment);
$.pop();
}
export default Main;
}

@ -1,5 +1,3 @@
// main.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Main($$payload, $$props) {

@ -1,9 +1,7 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
function Each_string_template($$anchor, $$props) {
export default function Each_string_template($$anchor, $$props) {
$.push($$props, false);
$.init();
@ -19,6 +17,4 @@ function Each_string_template($$anchor, $$props) {
$.append($$anchor, fragment);
$.pop();
}
export default Each_string_template;
}

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Each_string_template($$payload, $$props) {

@ -1,9 +1,7 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
function Function_prop_no_getter($$anchor, $$props) {
export default function Function_prop_no_getter($$anchor, $$props) {
$.push($$props, true);
let count = $.source(0);
@ -30,6 +28,4 @@ function Function_prop_no_getter($$anchor, $$props) {
$.append($$anchor, fragment);
$.pop();
}
export default Function_prop_no_getter;
}

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Function_prop_no_getter($$payload, $$props) {

@ -1,11 +1,9 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
var root = $.template(`<h1>hello world</h1>`);
function Hello_world($$anchor, $$props) {
export default function Hello_world($$anchor, $$props) {
$.push($$props, false);
$.init();
@ -13,6 +11,4 @@ function Hello_world($$anchor, $$props) {
$.append($$anchor, h1);
$.pop();
}
export default Hello_world;
}

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Hello_world($$payload, $$props) {

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
@ -25,4 +23,4 @@ if (import.meta.hot) {
});
}
export default Hmr;
export default Hmr;

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Hmr($$payload, $$props) {

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
@ -12,7 +10,7 @@ function reset(_, str, tpl) {
var root = $.template(`<input> <input> <button>reset</button>`, 1);
function State_proxy_literal($$anchor, $$props) {
export default function State_proxy_literal($$anchor, $$props) {
$.push($$props, true);
let str = $.source('');
@ -35,6 +33,4 @@ function State_proxy_literal($$anchor, $$props) {
$.pop();
}
export default State_proxy_literal;
$.delegate(["click"]);

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function State_proxy_literal($$payload, $$props) {

@ -1,9 +1,7 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal/client";
function Svelte_element($$anchor, $$props) {
export default function Svelte_element($$anchor, $$props) {
$.push($$props, true);
let tag = $.prop($$props, "tag", 3, 'hr');
@ -13,6 +11,4 @@ function Svelte_element($$anchor, $$props) {
$.element(node, tag, false);
$.append($$anchor, fragment);
$.pop();
}
export default Svelte_element;
}

@ -1,5 +1,3 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Svelte_element($$payload, $$props) {

@ -59,7 +59,8 @@ function compile({ id, source, options, return_ast }) {
const compiled = svelte.compile(source, {
filename: options.filename,
generate: options.generate,
dev: options.dev
dev: options.dev,
discloseVersion: false // less visual noise in the output tab
});
const { js, css, warnings, metadata } = compiled;

Loading…
Cancel
Save