Open mourner opened 4 years ago
You can sidestep this issue for now by using var instead of let or const, or by using assignment like for([a] of b) a()
The problem seems to be that in BlockStatement.js
a new alias is created but the Node is kept the same. Then later when destructure
is called in ForOfStatement.js
the resolveName
is passed that node in destructure.js
at destructureIdentifier
causing the old identifier to be used.
I can create a fix this but I need a little guidance. I don't quite understand where this needs to be changed. I see two parts that I think might be important:
destructureIdentifier
in destructure.js
:
resolveName should take into account the either an updated Node or receive the declaration with the rewritten = true property set.BlockStatement.js
at transpileBlockScopedIdentifiers
:
declaration.name = alias
could be changed to declaration.node.name
. But this is not a full solution because it creates problems in other places (such as property access).
Minimal test case:
Produces:
Note that the
a$1
reference at the end is incorrect, since this symbol is not defined.