Skip to content

Formatter: Newlines collapsed inside javascript_tag block #1702

@kudoas

Description

@kudoas

Input:

<%= javascript_tag do %>
  const a = 1
  console.log(a)
<% end %>

Output:

<%= javascript_tag do %>
  const a = 1 console.log(a)
<% end %>

Expected:

<%= javascript_tag do %>
  const a = 1
  console.log(a)
<% end %>

Playground:

https://herb-tools.dev/playground/#DwUgvABAVghgbjAzgYwE4EsAOAXA+tmAcwgBMB7CEAPgCgIJkyA7RbCGCSARgecTIA2AUwB0AsoQAUMAJQ1QEIUxKUqQA

Additional context:

The formatter collapses newlines inside a javascript_tag do block, merging separate JavaScript statements onto a single line. This changes the semantics of the JavaScript code and can cause syntax errors depending on the statements involved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions