diff --git a/src/validate/js/propValidators/data.ts b/src/validate/js/propValidators/data.ts index b49931cf21..10b0195d53 100644 --- a/src/validate/js/propValidators/data.ts +++ b/src/validate/js/propValidators/data.ts @@ -1,14 +1,12 @@ import { Validator } from '../../'; import { Node } from '../../../interfaces'; -const disallowed = new Set(['Literal', 'ObjectExpression', 'ArrayExpression']); +const allowed = new Set(['FunctionExpression', 'ArrowFunctionExpression']) export default function data(validator: Validator, prop: Node) { while (prop.type === 'ParenthesizedExpression') prop = prop.expression; - // TODO should we disallow references and expressions as well? - - if (disallowed.has(prop.value.type)) { + if (!allowed.has(prop.value.type)) { validator.error(`'data' must be a function`, prop.value.start); } } diff --git a/test/validator/samples/properties-data-no-call-expression/errors.json b/test/validator/samples/properties-data-no-call-expression/errors.json new file mode 100644 index 0000000000..4f27fe8c15 --- /dev/null +++ b/test/validator/samples/properties-data-no-call-expression/errors.json @@ -0,0 +1,8 @@ +[{ + "message": "'data' must be a function", + "loc": { + "line": 10, + "column": 8 + }, + "pos": 131 +}] diff --git a/test/validator/samples/properties-data-no-call-expression/input.html b/test/validator/samples/properties-data-no-call-expression/input.html new file mode 100644 index 0000000000..d58079dc2f --- /dev/null +++ b/test/validator/samples/properties-data-no-call-expression/input.html @@ -0,0 +1,12 @@ +
+ + diff --git a/test/validator/samples/properties-data-must-be-function/errors.json b/test/validator/samples/properties-data-no-object-expression/errors.json similarity index 100% rename from test/validator/samples/properties-data-must-be-function/errors.json rename to test/validator/samples/properties-data-no-object-expression/errors.json diff --git a/test/validator/samples/properties-data-must-be-function/input.html b/test/validator/samples/properties-data-no-object-expression/input.html similarity index 100% rename from test/validator/samples/properties-data-must-be-function/input.html rename to test/validator/samples/properties-data-no-object-expression/input.html diff --git a/test/validator/samples/properties-data-no-references/errors.json b/test/validator/samples/properties-data-no-references/errors.json new file mode 100644 index 0000000000..928e7ece84 --- /dev/null +++ b/test/validator/samples/properties-data-no-references/errors.json @@ -0,0 +1,8 @@ +[{ + "message": "'data' must be a function", + "loc": { + "line": 6, + "column": 2 + }, + "pos": 76 +}] diff --git a/test/validator/samples/properties-data-no-references/input.html b/test/validator/samples/properties-data-no-references/input.html new file mode 100644 index 0000000000..ddf39d80f3 --- /dev/null +++ b/test/validator/samples/properties-data-no-references/input.html @@ -0,0 +1,8 @@ +
+ +