Skip to content

Bug: Invalid indentation allowed after do #5458

@edemaine

Description

@edemaine

Bug report (minor)

Input Code

foo = do
  bar = getBar()
  indented
  indented
notIndented
notIndented

Expected Behavior

Compilation error: unexpected indentation of indented on line 3

Current Behavior

var bar, foo;

foo = (bar = getBar())();

indented;

indented;

notIndented;

notIndented;

Analysis

The token stream incorrectly has no DEDENT token:

[IDENTIFIER foo] [= =] [DO do] [IDENTIFIER bar] [= =] [IDENTIFIER getBar] [CALL_START (] [CALL_END )] [TERMINATOR \n] [IDENTIFIER indented] [TERMINATOR \n] [IDENTIFIER notIndented] [TERMINATOR \n]

Hopefully not too hard a fix...

Context

The current behavior (pointed out by a user) could lead users to write buggy code, because it seems like the indented code is executed "within" the do, but it isn't. (Unlike e.g. if the do was followed by -> as is usual.)

Environment

  • CoffeeScript version: 2.7.0
  • Node.js version: 19.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions