Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with binary operators in REPL #1363

Closed
ColonelJ opened this issue Jun 4, 2021 · 1 comment · Fixed by #1480
Closed

Bug with binary operators in REPL #1363

ColonelJ opened this issue Jun 4, 2021 · 1 comment · Fixed by #1480
Labels
you can do this Good candidate for a pull request.
Milestone

Comments

@ColonelJ
Copy link

ColonelJ commented Jun 4, 2021

Expected Behavior

It should produce a syntax error.

Actual Behavior

It seems to combine what you typed with the expression you entered previously.

Steps to reproduce the problem

$ npx ts-node
> 100 + 10
110
> * 4
140

Minimal reproduction

See above.

Specifications

  • ts-node version: v10.0.0
  • node version: v12.16.1
  • TypeScript version: v4.3.2
  • tsconfig.json, if you're using one: problem still occurs when none present
  • Operating system and version: Ubuntu 18.04.5 LTS
  • If Windows, are you using WSL or WSL2?: N/A
@cspotcode cspotcode added the you can do this Good candidate for a pull request. label Jun 4, 2021
@cspotcode
Copy link
Collaborator

cspotcode commented Jun 4, 2021

Makes sense. This probably has to do with how we convert TS to JS. We append each line of REPL input into a "virtual" file, then compile the entire thing. Then we diff the emitted JS from our previous compilation with the current compilation to see which lines are new. We run the new lines.

Probably the first line compiles from 100 + 10 into 100 + 10; and we run that.

Then the next line compiles from 100 + 10\n* 4 into 100 + 10 * 4;. The diff tells us that 100 + 10 was removed and 100 + 10 * 4 was added. We run the added code. https://github.com/TypeStrong/ts-node/blob/main/src/repl.ts#L206-L217

This may not be as simple as adding semicolons after every line of input, because there are cases where the user intentionally wants to split input across multiple lines. For example invokeFunction( [enter] and then arguments go on the next line.

I've marked this as "help wanted" to indicate that we will accept a pull request which fixes it.

Although this is a bug, I think it is low severity. I suspect that most users, given the choice between fixing this bug and merely avoiding it when they use the REPL, would opt to avoid it. But if any users feel differently and invest the time in a bugfix, we will certainly accept it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
you can do this Good candidate for a pull request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants