-
-
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.
Browse files
Browse the repository at this point in the history
error if method is an arrow function expression and uses `this` or `arguments`
- Loading branch information
Showing
16 changed files
with
116 additions
and
2 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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export default function onrender () { | ||
import usesThisOrArguments from '../utils/usesThisOrArguments.js'; | ||
|
||
export default function onrender ( validator, prop ) { | ||
if ( prop.value.type === 'ArrowFunctionExpression' ) { | ||
if ( usesThisOrArguments( prop.value.body ) ) { | ||
validator.error( `'onrender' should be a function expression, not an arrow function expression`, prop.start ); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export default function onteardown () { | ||
import usesThisOrArguments from '../utils/usesThisOrArguments.js'; | ||
|
||
export default function onteardown ( validator, prop ) { | ||
if ( prop.value.type === 'ArrowFunctionExpression' ) { | ||
if ( usesThisOrArguments( prop.value.body ) ) { | ||
validator.error( `'onteardown' should be a function expression, not an arrow function expression`, prop.start ); | ||
} | ||
} | ||
} |
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> |
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,5 @@ | ||
<script> | ||
export default { | ||
onrender: () => console.log( 'rendering' ) | ||
}; | ||
</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": "'onrender' should be a function expression, not an arrow function expression", | ||
"pos": 29, | ||
"loc": { | ||
"line": 3, | ||
"column": 2 | ||
} | ||
}] |
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,7 @@ | ||
<script> | ||
export default { | ||
onrender: () => { | ||
this.set({ a: 1 }); | ||
} | ||
}; | ||
</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 @@ | ||
[] |
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,5 @@ | ||
<script> | ||
export default { | ||
onteardown: () => console.log( 'tearing down' ) | ||
}; | ||
</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": "'onteardown' should be a function expression, not an arrow function expression", | ||
"pos": 29, | ||
"loc": { | ||
"line": 3, | ||
"column": 2 | ||
} | ||
}] |
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,7 @@ | ||
<script> | ||
export default { | ||
onteardown: () => { | ||
this.set({ a: 1 }); | ||
} | ||
}; | ||
</script> |