Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsfmt and JSX #4127

Closed
myitcv opened this issue Aug 3, 2015 · 4 comments
Closed

tsfmt and JSX #4127

myitcv opened this issue Aug 3, 2015 · 4 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@myitcv
Copy link

myitcv commented Aug 3, 2015

I've been using tsfmt to format TypeScript code. I believe this uses the pretty-printer from core compiler service.

But I've hit upon the following issue when formatting:

/// <reference path="typings/tsd.d.ts" />

import React = require("react");

function test(): any {
    return <span>This is a test</span>;
}

the output is:

/// <reference path="typings/tsd.d.ts" />

import React = require("react");

function test(): any {
    return <span>This is a test< /span>;
}

Notice the problematic < /span>.

The former compiles, the latter does not:

$ ./node_modules/.bin/tsc --jsx react --module system test.tsx
test.tsx(6,34): error TS1003: Identifier expected.
test.tsx(6,35): error TS1005: '>' expected.
test.tsx(9,1): error TS17002: Expected corresponding JSX closing tag for 'span'.

Any thoughts?

@myitcv
Copy link
Author

myitcv commented Aug 3, 2015

Another related example:

/// <reference path="typings/tsd.d.ts" />

import React = require("react");

function test(): any {
        let v: number = 5;
    return <span>{ v }</span>;
}

is formatted as:

/// <reference path="typings/tsd.d.ts" />

import React = require("react");

function test(): any {
    let v: number = 5;
    return <span>{ v } < /span>;
}

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label Aug 3, 2015
@RyanCavanaugh
Copy link
Member

This is a tsfmt bug.

Here: https://github.com/vvakame/typescript-formatter/blob/master/lib/formatter.ts#L14

The source file the compiler gets is being created with the '.ts' extension, which means it's consumed using the regular TypeScript grammar. tsfmt needs to be able to support passing a '.tsx' file extension when appropriate so that expressions of the form <T>x are interpreted as JSX tags rather than type assertions.

@myitcv
Copy link
Author

myitcv commented Aug 3, 2015

@RyanCavanaugh - thanks very much.

@vvakame
Copy link
Contributor

vvakame commented Aug 4, 2015

ah, I understand. thank you!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants