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

Add a builder definition including name for tsTypeParameter #10319

Merged
merged 1 commit into from Aug 15, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/babel-types/src/definitions/typescript.js
Expand Up @@ -494,6 +494,7 @@ defineType("TSTypeParameterDeclaration", {
});

defineType("TSTypeParameter", {
builder: ["constraint", "default", "name"],
visitor: ["constraint", "default"],
fields: {
name: {
Expand Down
@@ -0,0 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`builders typescript tsTypeParameter accept name as argument for tsTypeParameter 1`] = `
Object {
"constraint": Object {
"type": "TSTypeReference",
"typeName": Object {
"name": "bar",
"type": "Identifier",
},
"typeParameters": null,
},
"default": Object {
"type": "TSTypeReference",
"typeName": Object {
"name": "baz",
"type": "Identifier",
},
"typeParameters": null,
},
"name": "foo",
"type": "TSTypeParameter",
}
`;
24 changes: 24 additions & 0 deletions packages/babel-types/test/builders/typescript/tsTypeParameter.js
@@ -0,0 +1,24 @@
import * as t from "../../..";

describe("builders", function() {
describe("typescript", function() {
describe("tsTypeParameter", function() {
it("accept name as argument for tsTypeParameter", function() {
const tsTypeParameter = t.tsTypeParameter(
t.tsTypeReference(t.identifier("bar")),
t.tsTypeReference(t.identifier("baz")),
"foo",
);
expect(tsTypeParameter).toMatchSnapshot();
});
it("throws when name is missing", function() {
expect(() => {
t.tsTypeParameter(
t.tsTypeReference(t.identifier("bar")),
t.tsTypeReference(t.identifier("baz")),
);
}).toThrow("Property name expected type of string but got null");
});
});
});
});