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

Cannot access 'variableName' before initialization... #5749

Closed
MarkTanashchuk opened this issue Dec 7, 2020 · 2 comments · Fixed by #5837
Closed

Cannot access 'variableName' before initialization... #5749

MarkTanashchuk opened this issue Dec 7, 2020 · 2 comments · Fixed by #5837
Labels

Comments

@MarkTanashchuk
Copy link

MarkTanashchuk commented Dec 7, 2020

In this REPL:
https://svelte.dev/repl/0cf61fcb843c47b7a9ba4bd6d6a891f7?version=3.31.0

this code:

let someData = {
  Home: "HomeData",
  // ...
};
$: currentData = someData["NotHome"] || "DefaultData";

let myText = "Bugged ;("
function fetch() {
  if(currentData != "DefaultData") console.log(myText)
};
fetch();

compiles into this code, where currentData declared after fetch():

let someData = { Home: "HomeData" }; // ...
function fetch() {
  if (currentData != "DefaultData") console.log(myText);
}
fetch();
let currentData;
$: currentData = someData["NotHome"] || "DefaultData";

And leads to an error `Cannot access 'currentData' before initialization'

@Conduitry Conduitry added the bug label Dec 7, 2020
@arackaf
Copy link
Contributor

arackaf commented Dec 10, 2020

Here's another example:

	import store from "./store";
	let name = 'world';
	
	$: theValue = $store;
	
	let numbersSeen = {
		[theValue]: true
	}

REPL: https://svelte.dev/repl/1753fac08700444985259933d4b58518?version=3.31.0

That code's obviously foolish and silly - the goal is to do something with that initial, original value of "theValue" which, in this circumstance, leads to a ReferenceError

@Conduitry
Copy link
Member

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.

3 participants