mirror of https://github.com/sveltejs/svelte
error if method is an arrow function expression and uses `this` or `arguments` (#179)
parent
fd77efa633
commit
a6c648b086
@ -0,0 +1,24 @@
|
|||||||
|
import { walk } from 'estree-walker';
|
||||||
|
import isReference from '../../../utils/isReference.js';
|
||||||
|
|
||||||
|
export default function usesThisOrArguments ( node ) {
|
||||||
|
let result = false;
|
||||||
|
|
||||||
|
walk( node, {
|
||||||
|
enter ( node ) {
|
||||||
|
if ( result || node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' ) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( node.type === 'ThisExpression' ) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( node.type === 'Identifier' && isReference( node ) && node.name === 'arguments' ) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
[]
|
@ -0,0 +1,9 @@
|
|||||||
|
<button on:click='foo()'></button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
foo: () => console.log( 'foo' )
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,8 @@
|
|||||||
|
[{
|
||||||
|
"message": "Method 'foo' should be a function expression, not an arrow function expression",
|
||||||
|
"pos": 79,
|
||||||
|
"loc": {
|
||||||
|
"line": 6,
|
||||||
|
"column": 3
|
||||||
|
}
|
||||||
|
}]
|
@ -0,0 +1,11 @@
|
|||||||
|
<button on:click='foo()'></button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
foo: () => {
|
||||||
|
this.set({ a: 1 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Reference in new issue