Skip to content

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

Closed
paperclover wants to merge 1 commit into
Wilfred:masterfrom
paperclover:js-template-string
Closed

fix: don't count javascript template strings as atoms#956
paperclover wants to merge 1 commit into
Wilfred: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

Wilfred commented Mar 15, 2026

Copy link
Copy Markdown
Owner

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.

@paperclover

Copy link
Copy Markdown
Author

closing as stale on my part, not really sure of a good solution.

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