Add a builder definition including name for tsTypeParameter (#10319)

This commit is contained in:
Even Alander 2019-08-15 19:59:08 +02:00 committed by Nicolò Ribaudo
parent f0c2364d01
commit eb3767d58b
3 changed files with 49 additions and 0 deletions

View File

@ -494,6 +494,7 @@ defineType("TSTypeParameterDeclaration", {
});
defineType("TSTypeParameter", {
builder: ["constraint", "default", "name"],
visitor: ["constraint", "default"],
fields: {
name: {

View File

@ -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",
}
`;

View File

@ -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");
});
});
});
});