Skip to content

.load accumulates indentation #47673

Closed
@edemaine

Description

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 DanielXMoore/Civet#509

But it also affects correctness of JavaScript as illustrated above.

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions