You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/compiler/validate/js/propValidators/methods.js

28 lines
707 B

import checkForDupes from '../utils/checkForDupes.js';
import checkForComputedKeys from '../utils/checkForComputedKeys.js';
const builtin = {
set: true,
get: true,
on: true,
fire: true,
observe: true,
teardown: true
};
export default function methods ( validator, prop ) {
if ( prop.value.type !== 'ObjectExpression' ) {
validator.error( `The 'methods' property must be an object literal`, prop.start );
return;
}
checkForDupes( validator, prop.value.properties );
checkForComputedKeys( validator, prop.value.properties );
prop.value.properties.forEach( prop => {
if ( builtin[ prop.key.name ] ) {
validator.error( `Cannot overwrite built-in method '${prop.key.name}'` );
}
});
}