Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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;
Expand Down
14 changes: 0 additions & 14 deletions packages/svelte/src/compiler/phases/3-transform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
Copy link
Member

@dummdidumm dummdidumm Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should stay if discloseVersion is true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? feels like a semantic overload. i'm not sure the comment has much value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, historical reasons I guess - Svelte always had a comment about it at the top historically. But I realize that's a silly argument and the actual discloseVersion probably does a better job at communicating the version, so I'm ok with it now.

},
{
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// 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';

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('');
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -26,6 +24,4 @@ function Class_state_field_constructor_assignment($$anchor, $$props) {
}

$.pop();
}

export default Class_state_field_constructor_assignment;
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,6 +33,4 @@ function Main($$anchor, $$props) {

$.append($$anchor, fragment);
$.pop();
}

export default Main;
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -19,6 +17,4 @@ function Each_string_template($$anchor, $$props) {

$.append($$anchor, fragment);
$.pop();
}

export default Each_string_template;
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -30,6 +28,4 @@ function Function_prop_no_getter($$anchor, $$props) {

$.append($$anchor, fragment);
$.pop();
}

export default Function_prop_no_getter;
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// 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();

var h1 = root();

$.append($$anchor, h1);
$.pop();
}

export default Hello_world;
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -25,4 +23,4 @@ if (import.meta.hot) {
});
}

export default Hmr;
export default Hmr;
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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('');
Expand All @@ -35,6 +33,4 @@ function State_proxy_literal($$anchor, $$props) {
$.pop();
}

export default State_proxy_literal;

$.delegate(["click"]);
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -13,6 +11,4 @@ function Svelte_element($$anchor, $$props) {
$.element(node, tag, false);
$.append($$anchor, fragment);
$.pop();
}

export default Svelte_element;
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion sites/svelte-5-preview/src/lib/workers/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down