pvdz / tenko

An 100% spec compliant ES2021 JavaScript parser written in JS

Home Page:https://pvdz.github.io/tenko/repl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Block scoped func decl id scoping

pvdz opened this issue · comments

I think Tenko currently doesn't properly scope the id of a function declaration that's inside a block (or switch).

If I understand properly now then in strict mode it becomes a let that is hoisted within the block and if not strict mode then it becomes a var that is hoisted within the block.

So:

{
  f();
  function f(){}
}

In context of where f binds, is really

{
  var f = function(){}
  f();
}

(Note the discrepancies with .name and some other things. This is only supposed to illustrate how f binds.)

While

"use strict";
{
  function f(){}
  f();
}

Is really

"use strict";
{
  let f = function(){}
  f();
}

Works the same in global, in functions, and in switches.