Skip to content

Formatting error when JSX element contains invalid JS identifier #4636

@myitcv

Description

@myitcv

If tests/cases/fourslash/formattingJsxElements.ts is amended as follows (adding data-id="test" to the <div>):

/// <reference path='fourslash.ts' />

//@Filename: file.tsx
////function () {
////    return (
////        <div className="commentBox" data-id="test">
////Hello, World!/*autoformat*/
/////*indent*/
////        </div>
////    )
////}
////


format.document();
goTo.marker("autoformat");
verify.currentLineContentIs('            Hello, World!');
goTo.marker("indent");
verify.indentationIs(12);

and then run, we see a failure:

$ jake runtests tests=tests/cases/fourslash/formattingJsxElements.ts
rm -rf tests/baselines/local/
rm -rf internal/baselines/rwc/local
Running test(s): tests/cases/fourslash/formattingJsxElements.ts
mocha -R mocha-fivemat-progress-reporter -g tests/cases/fourslash/formattingJsxElements.ts --colors  -t 20000 built/local/run.js

    fourslash tests

Test failure:
fourslash test formattingJsxElements.ts runs correctly
  [․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․]

  0 passing (196ms)
  1 failing

  1) fourslash tests tests/cases/fourslash/formattingJsxElements.ts fourslash test formattingJsxElements.ts runs correctly:
     Error: Debug Failure. False expression:
      at Object.assert (eval at <anonymous> (built/local/run.js:54637:13), <anonymous>:1558:23)

This backs up what we're seeing in actual .tsx files that are being formatted with typescript-formatter, i.e. that non-valid JS identifier attributes are causing the formatter to fall over.

This feels like something the formatter should be able to handle.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions