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

Shorthand methods in object literals disappear #2906

Closed
trbrc opened this issue May 30, 2019 · 1 comment · Fixed by #3151
Closed

Shorthand methods in object literals disappear #2906

trbrc opened this issue May 30, 2019 · 1 comment · Fixed by #3151
Labels

Comments

@trbrc
Copy link
Contributor

trbrc commented May 30, 2019

This works fine:

<script>
	import Greeter from './Greeter.svelte';
	const object = {
		getName() {
			return 'foo';
		}
	};
</script>
<Greeter thing={object} />

This breaks:

<script>
	import Greeter from './Greeter.svelte';
</script>
<Greeter thing={{
	getName() {
		return 'foo';
	}
}} />
Can't find variable: getNamefunc_1

Looks like there's some too greedy function hoisting going on.

REPL: https://svelte.dev/repl/d1fcf63ccfea462f948fcc4cc16c3028?version=3.4.4


EDIT: Another example of shorthand methods breaking in a different way:

<script>
	import Greeter from './Greeter.svelte';
	let name = 'foo';
</script>

<Greeter thing={{
	getName() {
		return name;
	}
}} />

Compiler refuses to compile and says: Unexpected token (Note that you need plugins to import files that are not JavaScript)

https://svelte.dev/repl/6e2cf0c00f85488195f4a47eee22c1e0?version=3.4.4

@Conduitry Conduitry added the bug label May 30, 2019
@Conduitry
Copy link
Member

"Unexpected token (Note that you need plugins to import files that are not JavaScript)" is an error from Rollup actually, which generally indicates that the Svelte compiler is outputting invalid js, in this case { getNamectx.func }.

Rich-Harris added a commit that referenced this issue Jul 3, 2019
correctly transform inline shorthand methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants