Ask questionsDestructure shadow mis-reference
$ grep swc package.json
"@swc/cli": "0.1.18",
"@swc/core": "1.0.45",
"swc-loader": "0.1.6",
function foo(bar) {
const { foo } = bar;
return foo;
}
function _throw(e) {
throw e;
}
function foo(bar) {
var ref = bar ? bar :
_throw(new TypeError("Cannot destructure 'undefined' or 'null'")),
foo1 = ref.foo1;
return foo1;
}
After destructuring, the variable foo
is undefined
.
Rather than allowing the inner foo
to shadow the outer foo
function, and getting its value from ref.foo
, it references a non-existent ref.foo1
.
Answer
questions
kdy1
@Austaras
why generate _throw though?
What do you mean?
throw
is a reserved word and throw
will be changed to _throw if you target es3.
(Anyway, I found a bug. _throw
is the name of a helper in swc)