diff --git a/lib/printer.ts b/lib/printer.ts index 5b3f9618..df020115 100644 --- a/lib/printer.ts +++ b/lib/printer.ts @@ -1331,6 +1331,8 @@ function genericPrintNoParens(path: any, options: any, print: any) { case "JSXOpeningElement": { parts.push("<", path.call(print, "name")); + const typeDefPart = path.call(print, "typeParameters"); + if (typeDefPart.length) parts.push(typeDefPart); const attrParts: any[] = []; path.each(function (attrPath: any) { diff --git a/test/run.ts b/test/run.ts index 39534ed8..293ea586 100644 --- a/test/run.ts +++ b/test/run.ts @@ -14,4 +14,5 @@ import "./printer"; import "./syntax"; import "./flow"; import "./typescript"; +import "./tsx"; import "./visit"; diff --git a/test/tsx.ts b/test/tsx.ts new file mode 100644 index 00000000..5f288fe8 --- /dev/null +++ b/test/tsx.ts @@ -0,0 +1,23 @@ +"use strict"; + +const nodeMajorVersion = parseInt(process.versions.node, 10); +import * as parser from "../parsers/babel-ts"; +import { EOL as eol } from "os"; +import * as recast from "../main"; +import assert from "assert"; + +(nodeMajorVersion >= 6 ? describe : xdescribe)( + "Babel TSX Compatibility", + function () { + function check(lines: string[]) { + const code = lines.join(eol); + const ast = recast.parse(code, { parser }); + const output = recast.prettyPrint(ast, { tabWidth: 2 }).code; + assert.strictEqual(code, output); + } + + it("should parse and print typed JSX elements", function () { + check([" />;"]); + }); + }, +);