Skip to content

Incorrect formatter behavior: missing space after opening template string brace #19385

Description

TypeScript Version: 2.7.0-dev.20171020

Code

const a = `
    ${123}${123}
`;

With formatting option "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces" set to "true." I did this in VSCode with:

{"typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": true}

Open the .ts file in VSCode and run the "Format document" command. (If requested, I can make a reproduction that uses TypeScript's formatting API directly)

Expected behavior:

"Format document" inserts four spaces adjacent to the opening and closing curly braces:

const a = `
    ${ 123 }${ 123 }
`;

Actual behavior:

There is no whitespace before the first 123.

const a = `
    ${123 }${ 123 }
`;

Activity

  1. ghost added
    BugA bug in TypeScript
    on Oct 20, 2017
  2. ghost added
    Domain: FormatterThe issue relates to the built-in formatter
    on Oct 20, 2017
  3. added this to the milestone on Oct 23, 2017
  4. cspotcode commented on Oct 23, 2017

    @cspotcode
    Author

    I think I've traced the problem to this bit of code:
    https://github.com/Microsoft/TypeScript/blob/master/src/services/formatting/formatting.ts#L1139-L1142

    The rule to insert a space is being skipped because previousStartLine is different than currentStartLine. However, in this particular situation, the newline occurs within the templateHead token, so it really shouldn't be skipping the rule.

  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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

    BugA bug in TypeScriptDomain: FormatterThe issue relates to the built-in formatterHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions