Skip to content
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

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

Merged
merged 4 commits into from
Apr 25, 2024
Merged

Conversation

Rich-Harris
Copy link
Member

this is vain, but it'd be cool if the 'JS output' tab had as little noise as possible. Right now a <h1>Hello world!</h1> component yields this:

// App.svelte (Svelte v5.0.0-next.115)
// 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 App($$anchor, $$props) {
	$.push($$props, false);
	$.init();

	var h1 = root();

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

export default App;

Between this PR and #11319, it becomes this:

import * as $ from "svelte/internal/client";

var root = $.template(`<h1>Hello world!</h1>`);

export default function App($$anchor) {
	var h1 = root();

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

Copy link

changeset-bot bot commented Apr 25, 2024

⚠️ No Changeset found

Latest commit: 0f16183

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

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

MrHBS commented Apr 25, 2024

I was wondering why the extra assignment and not simply $.append($$anchor, root);

@Rich-Harris Rich-Harris merged commit 9a887f8 into main Apr 25, 2024
8 checks passed
@Rich-Harris Rich-Harris deleted the direct-export branch April 25, 2024 15:36
@Rich-Harris
Copy link
Member Author

That would be ideal but it would involve jumping through a bunch of extra hoops — I haven't tried it, but I would expect it to add a fair chunk of complexity. Minifiers will take care of it, so at the very least we're not adding overhead to prod bundles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants