node icon indicating copy to clipboard operation
node copied to clipboard

`.load` accumulates indentation

Open edemaine opened this issue 1 year ago • 1 comments

Version

v19.9.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

repl

What steps will reproduce the bug?

  1. Create a file example.js with the following contents:
function f() {
  console.log('hello')
  console.log(`goodbye
world
  !`)
}
f()
  1. Run the REPL via node, and enter the following command:
> .load example.js

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

I expect the REPL to repeat code exactly as it appears in example.js:

function f() {
  console.log('hello')
  console.log(`goodbye
world
  !`)
}
f()

And then for the code to output:

hello
goodbye
world
  !

(For example, this is the output from node example.js.)

What do you see instead?

The REPL repeats the code with accumulated indentation, where each line includes all of the indentation from all previous lines:

function f() {
  console.log('hello')
    console.log(`goodbye
    world
      !`)
      }
      f()

This results in incorrect behavior with the template string. The code outputs:

hello
goodbye
    world
      !

Additional information

This issue arose when using the repl package to make a REPL for an indentation-based language, Civet. .load is then nonfunctional; see https://github.com/DanielXMoore/Civet/issues/509

But it also affects correctness of JavaScript as illustrated above.

edemaine avatar Apr 22 '23 18:04 edemaine

I'll take a stab at this one. Open to hearing any ideas anyone may have before I dig in.

GethosTheWalrus avatar Jun 16 '23 00:06 GethosTheWalrus

hi @GethosTheWalrus If ur not working on it right now can i look into this issue

Prateek462003 avatar Jul 25 '23 16:07 Prateek462003