mirror of https://github.com/sveltejs/svelte
parent
0698525f1b
commit
c199407db2
@ -1,3 +1,19 @@
|
||||
import checkForDupes from '../utils/checkForDupes.js';
|
||||
import checkForComputedKeys from '../utils/checkForComputedKeys.js';
|
||||
|
||||
export default function components ( validator, prop ) {
|
||||
if ( prop.value.type !== 'ObjectExpression' ) {
|
||||
validator.error( `The 'components' property must be an object literal`, prop.start );
|
||||
return;
|
||||
}
|
||||
|
||||
checkForDupes( validator, prop.value.properties );
|
||||
checkForComputedKeys( validator, prop.value.properties );
|
||||
|
||||
prop.value.properties.forEach( component => {
|
||||
const char = component.key.name[0];
|
||||
if ( char === char.toLowerCase() ) {
|
||||
validator.warn( `Component names should be capitalised`, component.start );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,3 +1,15 @@
|
||||
const disallowed = {
|
||||
Literal: true,
|
||||
ObjectExpression: true,
|
||||
ArrayExpression: true
|
||||
};
|
||||
|
||||
export default function data ( validator, prop ) {
|
||||
while ( prop.type === 'ParenthesizedExpression' ) prop = prop.expression;
|
||||
|
||||
// TODO should we disallow references and expressions as well?
|
||||
|
||||
if ( disallowed[ prop.value.type ] ) {
|
||||
validator.error( `'data' must be a function`, prop.value.start );
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,12 @@
|
||||
import checkForDupes from '../utils/checkForDupes.js';
|
||||
import checkForComputedKeys from '../utils/checkForComputedKeys.js';
|
||||
|
||||
export default function events ( validator, prop ) {
|
||||
if ( prop.value.type !== 'ObjectExpression' ) {
|
||||
validator.error( `The 'events' property must be an object literal`, prop.start );
|
||||
return;
|
||||
}
|
||||
|
||||
checkForDupes( validator, prop.value.properties );
|
||||
checkForComputedKeys( validator, prop.value.properties );
|
||||
}
|
||||
|
@ -1,3 +1,12 @@
|
||||
import checkForDupes from '../utils/checkForDupes.js';
|
||||
import checkForComputedKeys from '../utils/checkForComputedKeys.js';
|
||||
|
||||
export default function helpers ( validator, prop ) {
|
||||
if ( prop.value.type !== 'ObjectExpression' ) {
|
||||
validator.error( `The 'helpers' property must be an object literal`, prop.start );
|
||||
return;
|
||||
}
|
||||
|
||||
checkForDupes( validator, prop.value.properties );
|
||||
checkForComputedKeys( validator, prop.value.properties );
|
||||
}
|
||||
|
@ -1,3 +1,27 @@
|
||||
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}'` );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
<div></div>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
components: {
|
||||
foo
|
||||
}
|
||||
};
|
||||
</script>
|
@ -0,0 +1,8 @@
|
||||
[{
|
||||
"message": "Component names should be capitalised",
|
||||
"loc": {
|
||||
"line": 6,
|
||||
"column": 3
|
||||
},
|
||||
"pos": 59
|
||||
}]
|
@ -0,0 +1,8 @@
|
||||
[{
|
||||
"message": "'data' must be a function",
|
||||
"loc": {
|
||||
"line": 5,
|
||||
"column": 8
|
||||
},
|
||||
"pos": 48
|
||||
}]
|
@ -0,0 +1,9 @@
|
||||
<div></div>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: {
|
||||
foo: 42
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue