Skip to content

Shouldn't allow binding to globals referenced in script #2295

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

Closed
Conduitry opened this issue Mar 22, 2019 · 2 comments
Closed

Shouldn't allow binding to globals referenced in script #2295

Conduitry opened this issue Mar 22, 2019 · 2 comments
Labels

Comments

@Conduitry
Copy link
Member

<script>
	console.log(foo);
</script>

<input bind:value={foo}>

Binding to foo - a global - shouldn't be allowed, but the compiler allows this if it has been referenced in the script.

@Conduitry Conduitry added the bug label Mar 22, 2019
@Conduitry
Copy link
Member Author

Somewhat relatedly:

<script>
	console.log(foo);
</script>

{foo}

Since foo is referenced in the script, this does not produce a warning about {foo} in the template. I'm not sure whether this should also be considered a bug.

@thgh
Copy link
Contributor

thgh commented Mar 22, 2019

I'm not sure if Svelte should allow access to globals in templates/components.
Related: #2139 (comment)

I would make it explicit:

<script>
  let foo = window.foo
  console.log(foo);
</script>

{foo}

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

No branches or pull requests

2 participants