Skip to content

bug createTemplateMiddle() and createTemplateTail() do not work with escaped chars #35374

Closed

Description

See a74f109#r36149273

When creating tagged template literals programmatically one can pass in cooked and raw text.
The raw text is then checked by rescanning it and checking it is the same as the cooked text.

There is a bug in this check. After an expression the next part will start with a closing brace }, which triggers the scanner to then search to the next ${ or to the end of the the backticked string. But the current code is looking for a ] rather than a }.

Search Terms:
rawText, tagged template literals, createTemplateMiddle, getCookedText

Code

const ts = require('typescript');
ts.createTemplateMiddle('a\nb', 'a\\nb');

Expected behavior:
Should not throw

Actual behavior:

Thrown:
Error: Debug Failure. Invalid raw text
    at createTemplateLiteralLikeNode (/Users/pete/dev/angular/angular/node_modules/typescript/lib/typescript.js:64078:33)
    at Object.createTemplateMiddle (/Users/pete/dev/angular/angular/node_modules/typescript/lib/typescript.js:64092:20)

Activity

  1. added
    Domain: API
    on Oct 16, 2025
  2. RyanCavanaugh commented on Sep 3, 2026

    @RyanCavanaugh
    Member

    This affects the pre-TypeScript-7 JavaScript Compiler API (createTemplateMiddle). That API has been superseded by the TypeScript 7 API and is no longer being developed, so this issue cannot be addressed there.

  3. added
    Needs Human Review
    on Sep 3, 2026
  4. removed
    Needs Human Review
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDomain: API

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions