@@ -73,7 +73,7 @@ module.exports = {
73
73
74
74
create ( context ) {
75
75
const forbiddenNodes = [ ]
76
- const allowedScopes = [ ]
76
+ let scopeStack = { upper : null , body : null }
77
77
78
78
const expressionTypes = {
79
79
promise : 'asynchronous action' ,
@@ -87,65 +87,54 @@ module.exports = {
87
87
if ( node . async ) {
88
88
forbiddenNodes . push ( {
89
89
node : node ,
90
- type : 'async'
90
+ type : 'async' ,
91
+ targetBody : node . body
91
92
} )
92
- } else if ( node . parent . type === 'ReturnStatement' ) {
93
- allowedScopes . push ( node )
94
93
}
94
+
95
+ scopeStack = { upper : scopeStack , body : node . body }
95
96
}
96
97
98
+ function onFunctionExit ( ) {
99
+ scopeStack = scopeStack . upper
100
+ }
97
101
return Object . assign ( { } ,
98
102
{
99
- FunctionDeclaration : onFunctionEnter ,
100
-
101
- FunctionExpression : onFunctionEnter ,
102
-
103
- ArrowFunctionExpression : onFunctionEnter ,
103
+ ':function' : onFunctionEnter ,
104
+ ':function:exit' : onFunctionExit ,
104
105
105
106
NewExpression ( node ) {
106
107
if ( node . callee . name === 'Promise' ) {
107
108
forbiddenNodes . push ( {
108
109
node : node ,
109
- type : 'new'
110
+ type : 'new' ,
111
+ targetBody : scopeStack . body
110
112
} )
111
- } else if ( node . parent . type === 'ReturnStatement' ) {
112
- allowedScopes . push ( node )
113
113
}
114
114
} ,
115
115
116
116
CallExpression ( node ) {
117
117
if ( isPromise ( node ) ) {
118
118
forbiddenNodes . push ( {
119
119
node : node ,
120
- type : 'promise'
120
+ type : 'promise' ,
121
+ targetBody : scopeStack . body
121
122
} )
122
123
} else if ( isTimedFunction ( node ) ) {
123
124
forbiddenNodes . push ( {
124
125
node : node ,
125
- type : 'timed'
126
+ type : 'timed' ,
127
+ targetBody : scopeStack . body
126
128
} )
127
- } else if ( node . parent . type === 'ReturnStatement' ) {
128
- allowedScopes . push ( node )
129
129
}
130
130
} ,
131
131
132
132
AwaitExpression ( node ) {
133
133
forbiddenNodes . push ( {
134
134
node : node ,
135
- type : 'await'
135
+ type : 'await' ,
136
+ targetBody : scopeStack . body
136
137
} )
137
- } ,
138
-
139
- 'ReturnStatement' ( node ) {
140
- if (
141
- node . argument &&
142
- (
143
- node . argument . type === 'ObjectExpression' ||
144
- node . argument . type === 'ArrayExpression'
145
- )
146
- ) {
147
- allowedScopes . push ( node . argument )
148
- }
149
138
}
150
139
} ,
151
140
utils . executeOnVue ( context , ( obj ) => {
@@ -157,10 +146,7 @@ module.exports = {
157
146
cp . value &&
158
147
el . node . loc . start . line >= cp . value . loc . start . line &&
159
148
el . node . loc . end . line <= cp . value . loc . end . line &&
160
- ! allowedScopes . some ( scope =>
161
- scope . range [ 0 ] < el . node . range [ 0 ] &&
162
- scope . range [ 1 ] > el . node . range [ 1 ]
163
- )
149
+ el . targetBody === cp . value
164
150
) {
165
151
context . report ( {
166
152
node : el . node ,
0 commit comments