Skip to content

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

@petebacondarwin

Description

@petebacondarwin

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: APIRelates to the public API for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions