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 static to class property builder #10248

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
2 changes: 1 addition & 1 deletion packages/babel-types/src/definitions/es2015.js
Expand Up @@ -403,8 +403,8 @@ export const classMethodOrPropertyCommon = {
optional: true,
},
static: {
default: false,
validate: assertValueType("boolean"),
optional: true,
},
computed: {
default: false,
Expand Down
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": false,
"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();
});
});
});
});