-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
error if method is an arrow function expression and uses
this
or `a…
…rguments` (#179)
- Loading branch information
1 parent
fd77efa
commit a6c648b
Showing
6 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<button on:click='foo()'></button> | ||
|
||
<script> | ||
export default { | ||
methods: { | ||
foo: () => console.log( 'foo' ) | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[{ | ||
"message": "Method 'foo' should be a function expression, not an arrow function expression", | ||
"pos": 79, | ||
"loc": { | ||
"line": 6, | ||
"column": 3 | ||
} | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<button on:click='foo()'></button> | ||
|
||
<script> | ||
export default { | ||
methods: { | ||
foo: () => { | ||
this.set({ a: 1 }); | ||
} | ||
} | ||
}; | ||
</script> |