Skip to content

[JavaScript] Fix nested template strings#4566

Open
deathaxe wants to merge 2 commits into
sublimehq:masterfrom
deathaxe:pr/javascript/nested-templates-light
Open

[JavaScript] Fix nested template strings#4566
deathaxe wants to merge 2 commits into
sublimehq:masterfrom
deathaxe:pr/javascript/nested-templates-light

Conversation

@deathaxe

Copy link
Copy Markdown
Collaborator

Resolves #4220

This PR splits changes of #4318 into two initial commits to better track required changes to achieve proper handling of nested template strings.

Step 1:

Rename existing syntaxes to <name> (Plain) and scopes to source.<...>.plain. Adjust includes to keep everything working.

Step 2:

  1. (Re-)Create JavaScript, TypeScript, JSX, TSX syntaxes by extending the plain ones from Step 1.
  2. Move literal template string related contexts to those new syntaxes.
  3. Refactor and directly include CSS, HTML, JS, ... syntaxes in order to properly handle nested template strings.

Notes:

  1. Nested template strings don't highlight any syntax to keep syntax cache size in sane limits.
  2. Any 3rd-party package continues to only see JavaScript, TypeScript, JSX and TSX syntaxes with unchanged scopes. Hence this change has no side effects for those.
  3. 3rd-party packages could make use of .plain variants to prevent syntax highlighted template strings cause infinite include loops.

deathaxe added 2 commits June 11, 2026 20:21
This commit ...

1. renames existing syntax definitions to `<name> (Plain).sublime-syntax`
2. changes main scopes to `source.<name>.plain`
3. adjusts all references, accordingly
This commit...

1. adds new syntax definitions `<name>.sublime-syntax` which extend previously
   renamed `<name> (Plain).sublime-syntax` files.
2. moves file_extensions and first_line_match patterns to public syntaxes
3. moves `literal-string-template-<lang>` contexts to new syntaxes
4. refactors literal template strings to directly include embedded languages,
   which need to support nested literal strings.
5: adjust embedded syntaxes to include contexts with lookaheads to make sure
   to properly terminate parsing at template string end punctuation.
@jrappen

jrappen commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

I wasn't sure if adding explicit child scope match tests would make sense (requires 4201 or later), it'd work on the dev channel test binary only.

@michaelblyons
michaelblyons requested a review from Thom1729 July 3, 2026 17:54
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.

[JavaScript] Template string inside tag function breaks syntax highlighting

2 participants