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

printer: Support type parameters on JSX components in TSX #1397

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> />;"]);
});
},
);
Loading