Skip to content

Commit

Permalink
Add static parameter to class property builder
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-karadzhov committed Jul 22, 2019
1 parent fced5ce commit 68d8ca4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/babel-types/src/definitions/experimental.js
Expand Up @@ -33,7 +33,14 @@ defineType("BindExpression", {

defineType("ClassProperty", {
visitor: ["key", "value", "typeAnnotation", "decorators"],
builder: ["key", "value", "typeAnnotation", "decorators", "computed"],
builder: [
"key",
"value",
"typeAnnotation",
"decorators",
"computed",
"static",
],
aliases: ["Property"],
fields: {
...classMethodOrPropertyCommon,
Expand Down
@@ -0,0 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`builders experimental classProperty should validate 1`] = `
Object {
"computed": false,
"decorators": null,
"key": Object {
"type": "StringLiteral",
"value": "test",
},
"static": null,
"type": "ClassProperty",
"typeAnnotation": null,
"value": Object {
"type": "NumericLiteral",
"value": 1,
},
}
`;

exports[`builders experimental classProperty should validate 2`] = `
Object {
"computed": false,
"decorators": null,
"key": Object {
"type": "StringLiteral",
"value": "test",
},
"static": true,
"type": "ClassProperty",
"typeAnnotation": null,
"value": Object {
"type": "NumericLiteral",
"value": 1,
},
}
`;
24 changes: 24 additions & 0 deletions packages/babel-types/test/builders/experimental/classProperty.js
@@ -0,0 +1,24 @@
import * as t from "../../..";

describe("builders", function() {
describe("experimental", function() {
describe("classProperty", function() {
it("should validate", function() {
expect(
t.classProperty(t.stringLiteral("test"), t.numericLiteral(1)),
).toMatchSnapshot();

expect(
t.classProperty(
t.stringLiteral("test"),
t.numericLiteral(1),
null,
null,
false,
true,
),
).toMatchSnapshot();
});
});
});
});

0 comments on commit 68d8ca4

Please sign in to comment.