Skip to content

Commit

Permalink
Add a builder definition including name for tsTypeParameter (#10319)
Browse files Browse the repository at this point in the history
  • Loading branch information
deificx authored and nicolo-ribaudo committed Aug 15, 2019
1 parent f0c2364 commit eb3767d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
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");
});
});
});
});

0 comments on commit eb3767d

Please sign in to comment.