Skip to content

Fix an invalid template literal in the Node file-watcher example - #2650

Open
rinceyuan wants to merge 1 commit into
github:mainfrom
rinceyuan:fix/nodejs-docs-template-literal
Open

rinceyuan wants to merge 1 commit into
github:mainfrom
rinceyuan:fix/nodejs-docs-template-literal

Conversation

@rinceyuan

Copy link
Copy Markdown
Contributor

The file-watcher example in nodejs/docs/examples.md escapes the backticks around the path twice, so the snippet is a syntax error if you copy it.

prompt: `The user edited \\`${relPath}\\`.`,

\\ is an escaped backslash, so the backtick that follows it terminates the template literal, and ${relPath} then sits outside any string.

Proof

$ node -e "const relPath='src/app.ts'; eval('\`The user edited \\\\\\\\\`\${relPath}\\\\\\\\\`.\`')"
SyntaxError: Unexpected identifier '$'

With a single backslash it parses and produces what the example intends:

$ node -e "const relPath='src/app.ts'; console.log(eval('\`The user edited \\\\\`\${relPath}\\\\\`.\`'))"
The user edited `src/app.ts`.

Scope

One character removed from each of the two escapes, on one line. This is the only occurrence in the repository:

$ git grep -rn '\\\\`' -- nodejs/docs docs '*/README.md'
nodejs/docs/examples.md:527:            prompt: `The user edited \\`${relPath}\\`.`,

Why it was not caught

scripts/docs-validation only scans the repository-root docs/ directory — const DOCS_DIR = path.resolve(import.meta.dirname, "../../docs") — so the 54 code blocks under nodejs/docs/ are never extracted or type-checked.

While I was there I checked the rest of that directory by extracting the 12 blocks that carry imports and type-checking them against nodejs/src. After this fix, the only remaining failures are three bare object-literal fragments that end mid-structure and are not meant to compile standalone — the same class extract.ts already skips deliberately for TypeScript. nodejs/examples/basic-example.ts type-checks cleanly too.

I have not tried to extend the validation tooling to cover nodejs/docs/, since whether those pages should be in scope looked like your call.

The backticks around the path were escaped twice, which closes the template literal early and makes the snippet a syntax error when copied.
Copilot AI balanced review requested due to automatic review settings September 14, 2026 04:02
@rinceyuan
rinceyuan requested a review from a team as a code owner September 14, 2026 04:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues remain.

Pull request overview

Fixes invalid backtick escaping in the Node file-watcher documentation example.

Changes:

  • Removes the extra backslashes around relPath.
File summaries
File Description
nodejs/docs/examples.md Corrects the file-watcher template literal.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite (auto)

Note

Copilot is running an experiment and ran this review at Lite.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants