Add a builder definition including name for tsTypeParameter (#10319)
This commit is contained in:
parent
f0c2364d01
commit
eb3767d58b
@ -494,6 +494,7 @@ defineType("TSTypeParameterDeclaration", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
defineType("TSTypeParameter", {
|
defineType("TSTypeParameter", {
|
||||||
|
builder: ["constraint", "default", "name"],
|
||||||
visitor: ["constraint", "default"],
|
visitor: ["constraint", "default"],
|
||||||
fields: {
|
fields: {
|
||||||
name: {
|
name: {
|
||||||
|
|||||||
@ -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",
|
||||||
|
}
|
||||||
|
`;
|
||||||
@ -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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user