Add static parameter to class property builder (#10248)

This commit is contained in:
Yuri Karadzhov 2019-07-25 09:55:03 +02:00 committed by Nicolò Ribaudo
parent 1e7ed5c461
commit 4506590557
4 changed files with 70 additions and 2 deletions

View File

@ -403,8 +403,8 @@ export const classMethodOrPropertyCommon = {
optional: true,
},
static: {
default: false,
validate: assertValueType("boolean"),
optional: true,
},
computed: {
default: false,

View File

@ -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,

View File

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

View File

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