slipHQ / run-wasm

Run WASM based code executions in the browser easily
https://www.runwasm.com
Apache License 2.0
469 stars 47 forks source link

If there are TS errors then the output isn't cleared #102

Closed mcintyre94 closed 3 years ago

mcintyre94 commented 3 years ago

Describe the bug

When we run TS code that has type errors, the code doesn't run but the logs also aren't cleared:

{
    // The first time we run code, the fetch request for the lib data may still be pending.
    const libData = await this.libData
    const typeErrors = getTSTypeErrors(code, this.ts, libData)
    if (typeErrors.length === 0) {
      // If there are no errors, we can run the code
      this.logs = []

      // eslint-disable-next-line no-eval
      eval((await this.ts.transpile(code)) as string)
    }

    return { errors: typeErrors, output: this.logs }
  }

I think this is confusing and it might make more sense to clear the logs if there are type errors

To Reproduce Steps to reproduce the behavior:

  1. Go to https://www.runwasm.com/ts
  2. Run the code console.log("hello")
  3. The output will be set to hello
  4. Run the code:
    abc
    console.log("world")
  5. An error will be displayed: "Cannot find name 'abc'." This message comes from the latest code
  6. The output will remain "hello". This is confusing because this message comes from the previous code, the latest has not actually run

Expected behavior A clear and concise description of what you expected to happen.

I think it'd be clearer if we cleared the output logs when there are type errors. This way the errors + output will always both match the latest running code.

Screenshots If applicable, add screenshots to help explain your problem.

Screenshot 2021-10-20 at 23 55 39

Desktop (please complete the following information):