diff --git a/src/validate/js/propValidators/onrender.js b/src/validate/js/propValidators/onrender.js index 6cc31c9cc4d7..33693be8f1fd 100644 --- a/src/validate/js/propValidators/onrender.js +++ b/src/validate/js/propValidators/onrender.js @@ -1,3 +1,9 @@ -export default function onrender () { +import usesThisOrArguments from '../utils/usesThisOrArguments.js'; +export default function onrender ( validator, prop ) { + if ( prop.value.type === 'ArrowFunctionExpression' ) { + if ( usesThisOrArguments( prop.value.body ) ) { + validator.error( `'onrender' should be a function expression, not an arrow function expression`, prop.start ); + } + } } diff --git a/src/validate/js/propValidators/onteardown.js b/src/validate/js/propValidators/onteardown.js index 96cce604f828..7ce61e223d4f 100644 --- a/src/validate/js/propValidators/onteardown.js +++ b/src/validate/js/propValidators/onteardown.js @@ -1,3 +1,9 @@ -export default function onteardown () { +import usesThisOrArguments from '../utils/usesThisOrArguments.js'; +export default function onteardown ( validator, prop ) { + if ( prop.value.type === 'ArrowFunctionExpression' ) { + if ( usesThisOrArguments( prop.value.body ) ) { + validator.error( `'onteardown' should be a function expression, not an arrow function expression`, prop.start ); + } + } } diff --git a/test/validator/onrender-arrow-no-this/errors.json b/test/validator/onrender-arrow-no-this/errors.json new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/test/validator/onrender-arrow-no-this/errors.json @@ -0,0 +1 @@ +[] diff --git a/test/validator/onrender-arrow-no-this/input.html b/test/validator/onrender-arrow-no-this/input.html new file mode 100644 index 000000000000..c82e5c37454f --- /dev/null +++ b/test/validator/onrender-arrow-no-this/input.html @@ -0,0 +1,5 @@ + diff --git a/test/validator/onrender-arrow-this/errors.json b/test/validator/onrender-arrow-this/errors.json new file mode 100644 index 000000000000..5cc9b2c78d4c --- /dev/null +++ b/test/validator/onrender-arrow-this/errors.json @@ -0,0 +1,8 @@ +[{ + "message": "'onrender' should be a function expression, not an arrow function expression", + "pos": 29, + "loc": { + "line": 3, + "column": 2 + } +}] diff --git a/test/validator/onrender-arrow-this/input.html b/test/validator/onrender-arrow-this/input.html new file mode 100644 index 000000000000..e4283e60ba91 --- /dev/null +++ b/test/validator/onrender-arrow-this/input.html @@ -0,0 +1,7 @@ + diff --git a/test/validator/onteardown-arrow-no-this/errors.json b/test/validator/onteardown-arrow-no-this/errors.json new file mode 100644 index 000000000000..fe51488c7066 --- /dev/null +++ b/test/validator/onteardown-arrow-no-this/errors.json @@ -0,0 +1 @@ +[] diff --git a/test/validator/onteardown-arrow-no-this/input.html b/test/validator/onteardown-arrow-no-this/input.html new file mode 100644 index 000000000000..a742898edba0 --- /dev/null +++ b/test/validator/onteardown-arrow-no-this/input.html @@ -0,0 +1,5 @@ + diff --git a/test/validator/onteardown-arrow-this/errors.json b/test/validator/onteardown-arrow-this/errors.json new file mode 100644 index 000000000000..0596578b9577 --- /dev/null +++ b/test/validator/onteardown-arrow-this/errors.json @@ -0,0 +1,8 @@ +[{ + "message": "'onteardown' should be a function expression, not an arrow function expression", + "pos": 29, + "loc": { + "line": 3, + "column": 2 + } +}] diff --git a/test/validator/onteardown-arrow-this/input.html b/test/validator/onteardown-arrow-this/input.html new file mode 100644 index 000000000000..ac2f1d7e8b4b --- /dev/null +++ b/test/validator/onteardown-arrow-this/input.html @@ -0,0 +1,7 @@ +