princejwesley / Mancy

>_ Electron based NodeJS REPL :see_no_evil:
http://mancy-re.pl
MIT License
2.63k stars 133 forks source link

Redclare const / class #150

Open MarkusPfundstein opened 8 years ago

MarkusPfundstein commented 8 years ago

Hi Prince,

awesome REPL! Thanks for the job. I wonder if it is possible to implement a feature so that we can redclare const variables or classes. Right now this fails:

class F {
  constructor(A) {
    this.a = A;
  }
}

class F {
  constructor(a) {
    this.a = a*a;
  }
}
TypeError: Identifier 'F' has already been declared

as well as:

const g = x /0             // <- ERROR
ReferenceError: x is not defined     
const g = x => x /0   // <- oh, lets fix it
TypeError: Identifier 'g' has already been declared

Which is kinda annoying if you just want to play around with some data types. The fix in the later example is to just say g = x => x/0 without let/const, but that is a bit weird.. For the class example. I don't know a fix...

Would be go cool if this can be solved somehow or maybe theres a workaround?

Greetings Markus

princejwesley commented 8 years ago

@MarkusPfundstein const and class are not really working well within REPL context. Worst case solution is to provide a way to clear the context or a way to traverse the context backwards.

princejwesley commented 8 years ago

Or an icon in each execution output which will reset the context to that checkpoint.