bublejs / buble

https://buble.surge.sh
MIT License
869 stars 67 forks source link

Variable name clash in `A = class extends A` #196

Closed goto-bus-stop closed 5 years ago

goto-bus-stop commented 5 years ago

Code like this:

A = class extends A {}

Is transpiled like this:

A = (function(A) {
  function A() {
    A.apply(this, arguments)
  }
  if (A) A.__proto__ = A
})(A)

Which crashes:

    if ( A ) A.__proto__ = A;
                         ^

TypeError: Cyclic __proto__ value
    at Function.set __proto__ [as __proto__] (<anonymous>)

A possible fix could be to rename the temporary A function argument to something different if the name is already in use inside the function.

A = (function(A$0) {
  function A() {
    A$0.apply(this, arguments)
  }
  if (A$0) A.__proto__ = A$0
})(A)