better error for attempts to use getters/setters for methods. closes #425

pull/458/head
Rich Harris 7 years ago
parent 2e946e0e93
commit 99d6502bfd

@ -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';
@ -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 );

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

@ -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' );

@ -0,0 +1,8 @@
[{
"message": "Methods cannot use getters and setters",
"loc": {
"line": 4,
"column": 3
},
"pos": 43
}]

@ -0,0 +1,9 @@
<script>
export default {
methods: {
get foo () {
}
}
};
</script>
Loading…
Cancel
Save