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

better error for attempts to use getters/setters for methods #458

Merged
merged 1 commit into from
Apr 10, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/validate/js/propValidators/methods.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import checkForAccessors from '../utils/checkForAccessors.js';
import checkForDupes from '../utils/checkForDupes.js';
import checkForComputedKeys from '../utils/checkForComputedKeys.js';
import usesThisOrArguments from '../utils/usesThisOrArguments.js';
Expand All @@ -10,6 +11,7 @@ export default function methods ( validator, prop ) {
return;
}

checkForAccessors( validator, prop.value.properties, 'Methods' );
checkForDupes( validator, prop.value.properties );
checkForComputedKeys( validator, prop.value.properties );

Expand Down
7 changes: 7 additions & 0 deletions src/validate/js/utils/checkForAccessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function checkForAccessors ( validator, properties, label ) {
properties.forEach( prop => {
if ( prop.kind !== 'init' ) {
validator.error( `${label} cannot use getters and setters`, prop.start );
}
});
}
5 changes: 3 additions & 2 deletions test/validator/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as fs from 'fs';
import assert from 'assert';
import { svelte, exists, tryToLoadJson } from '../helpers.js';
import { svelte, tryToLoadJson } from '../helpers.js';

describe( 'validate', () => {
fs.readdirSync( 'test/validator/samples' ).forEach( dir => {
if ( dir[0] === '.' ) return;

const solo = exists( `test/validator/samples/${dir}/solo` );
// add .solo to a sample directory name to only run that test
const solo = /\.solo/.test( dir );

if ( solo && process.env.CI ) {
throw new Error( 'Forgot to remove `solo: true` from test' );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"message": "Methods cannot use getters and setters",
"loc": {
"line": 4,
"column": 3
},
"pos": 43
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
export default {
methods: {
get foo () {

}
}
};
</script>