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

Proper variable/function hoisting #39

Closed
y21 opened this issue Oct 24, 2022 · 0 comments · Fixed by #40
Closed

Proper variable/function hoisting #39

y21 opened this issue Oct 24, 2022 · 0 comments · Fixed by #40
Labels
A-compiler bug Something isn't working

Comments

@y21
Copy link
Owner

y21 commented Oct 24, 2022

Declaration hoisting partly works already (you can refer to a var before it is used, containing the undefined value if uninitialized). Function declarations work different however in that they are immediately initialized with the function and you can call them even before their declarations are "reached":

(function() {
  return b();

  var a = c();
  function b() {
    return c();
  }
  function c() {
    return 3;
  }
})()

Semantics should be equivalent to this:

(function() {
  // Functions declarations
  var b;
  var c;
  // Variable declarations
  var a;
  // Function initialization
  b = function() {
    return c();
  }
  c = function() {
    return 3;
  }

  return b();
  // Definition stays
  a = c();
})();
@y21 y21 added bug Something isn't working A-compiler labels Oct 24, 2022
@y21 y21 closed this as completed in #40 Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiler bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant