# Fix the parser extraction agent failing on template literals with nested interpolation

## TL;DR

Nested template literals confuse the extractor's parser, so simplify the expression or extract the inner literal first. Two levels of backticks with ${} inside ${} is valid JS but too clever for most extraction parsers. Pull the inner template into a variable, then the extractor sees one clean level.

## The error

```text
Parser extraction agent: failed to parse template literal
src/labels.js line 42: `Total: ${fmt(`${n} items`)}`
```

## Fix it

### Step 1: Find the nested literal

```bash
grep -n '`.*${.*`' src/labels.js | head -5
```

Expected: You see the nested backticks.

### Step 2: Hoist the inner template to a variable

```bash
node -e "console.log('const inner = `${n} items`; then `Total: ${fmt(inner)}` -- one nesting level')"
```

Expected: The code has a single template level.

### Step 3: Re-run extraction

```bash
node scripts/extract-strings.js | tail -3
```

Expected: The parser handles the file.

### Step 4: Confirm both strings extracted

```bash
grep -n "Total:\|items" locale/en.json | head -4
```

Expected: Both the outer and inner strings are in the catalog.

## When to use this

- Extraction fails on nested template literals
- The parser points at a line with backticks inside ${}

## When NOT to use this

- The literal parses but the string is missing, check the extraction markers
- Single-level templates fail, that is a different parser issue

## Tool and version compatibility

- Any AST-based extraction parser
- Nested template literals in message code

## Variant phrasings

### nested inside a tagged template

Same fix. Hoist first, the tag function still receives the same value.

### three levels deep

Hoist twice. If you need three levels, the code needs refactoring anyway.

## Why it happens

Extraction parsers walk template literals to find translatable strings, and nesting makes the boundary ambiguous: which backtick closes which literal. Most parsers give up rather than guess wrong.

## Edge cases

- Hoisting changes nothing at runtime, it is purely for the parser
- Lint for nested templates in message files to catch this early
- Some parsers handle nesting, but your translators tools may not, keep it simple

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_AyJXOuYykgbCCVD7f37oAg
