Skip to content

Commit

Permalink
Merge pull request #1397 from PartMan7/support-typedef-tsx
Browse files Browse the repository at this point in the history
printer: Support type parameters on JSX components in TSX
  • Loading branch information
eventualbuddha authored May 11, 2024
2 parents 51d5c89 + ec2d873 commit b7beb30
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ import "./printer";
import "./syntax";
import "./flow";
import "./typescript";
import "./tsx";
import "./visit";
23 changes: 23 additions & 0 deletions test/tsx.ts
Original file line number Diff line number Diff line change
@@ -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(["<Foo<Bar> />;"]);
});
},
);

0 comments on commit b7beb30

Please sign in to comment.