Skip to content

fix: don't count javascript template strings as atoms#956

Open
paperclover wants to merge 1 commit intoWilfred:masterfrom
paperclover:js-template-string
Open

fix: don't count javascript template strings as atoms#956
paperclover wants to merge 1 commit intoWilfred:masterfrom
paperclover:js-template-string

Conversation

@paperclover
Copy link
Copy Markdown

if template strings are atoms, changing the indentation of a block of code containing one counts that as a change, which is bad. instead, recurse the expression as normal.

not very happy with adding a special case to atom_from_cursor but i'm not familiar enough to know the right strategy.

test case

let x = `hello ${y
  ? 1
  : 2
}`;
{
  let x = `hello ${y
    ? 1
    : 2
  }`;
}

if template strings are atoms, changing the indentation of a block of
code containing one counts that as a change, which is bad. instead,
recurse the expression as normal.

not very happy with adding a special case to `atom_from_cursor` but i'm
not familiar enough to know the right strategy.

test case
```ts
let x = `hello ${y
  ? 1
  : 2
}`;
```
```ts
{
  let x = `hello ${y
    ? 1
    : 2
  }`;
}
```
@hmknhovgd-boop
Copy link
Copy Markdown

إذا كانت سلاسل القوالب عبارة عن ذرات، فإن تغيير مسافة بادئة لكتلة من التعليمات البرمجية تحتوي على واحدة منها يُعتبر تغييرًا، وهذا غير مقبول. بدلاً من ذلك، قم بتكرار التعبير كالمعتاد.

لستُ سعيدًا جدًا بإضافة حالة خاصة، atom_from_cursorلكنني لستُ على دراية كافية بمعرفة الاستراتيجية الصحيحة.

حالة اختبار

let x = `hello ${y
  ? 1
  : 2
}`;
{
  let x = `hello ${y
    ? 1
    : 2
  }`;
}

#954

@Wilfred
Copy link
Copy Markdown
Owner

Wilfred commented Mar 15, 2026

This usually doesn't work, unfortunately, which is why strings with interpolated expressions are treated as atoms in most cases.

The problem is that the text before and after the interpolation needs to be present in the AST, or difftastic won't understand that the following string literals are different.

`foo${name}`;
`foo ${name} `;

@paperclover
Copy link
Copy Markdown
Author

The problem is that the text before and after the interpolation needs to be present in the AST, or difftastic won't understand that the following string literals are different.

works in the diff

CleanShot 2026-03-20 at 21 10 38@2x

though it does make whitespace only changes a bit harder to parse
CleanShot 2026-03-20 at 21 14 05@2x

actually, this one is tough. the underlines no longer appear

CleanShot 2026-03-20 at 21 15 27@2x

i do wonder whats a reasonable solution to this. the indentation showing up as a changed node is very unsatisfying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants