Skip to content

Commit

Permalink
Merge pull request #115 from nikku/validate-computed-prop
Browse files Browse the repository at this point in the history
Verify computed property dependencies
  • Loading branch information
Rich-Harris authored Dec 5, 2016
2 parents 6f2ce42 + 65cdead commit 3935d05
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/validate/js/propValidators/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ export default function computed ( validator, prop ) {
return;
}

computation.value.params.forEach( param => {
const params = computation.value.params;

if ( params.length === 0 ) {
validator.error( `A computed value must depend on at least one property`, computation.value.start );
return;
}

params.forEach( param => {
const valid = param.type === 'Identifier' || param.type === 'AssignmentPattern' && param.left.type === 'Identifier';

if ( !valid ) {
Expand Down
8 changes: 8 additions & 0 deletions test/validator/computed-values/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"message": "A computed value must depend on at least one property",
"pos": 49,
"loc": {
"line": 4,
"column": 8
}
}]
7 changes: 7 additions & 0 deletions test/validator/computed-values/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
export default {
computed: {
foo: () => {}
}
};
</script>

0 comments on commit 3935d05

Please sign in to comment.