Skip to content

Commit aa20cd7

Browse files
Incorporated feedback from pull request
- Simplified logic for testing return assignments - Added additional test
1 parent 323ccb5 commit aa20cd7

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

lib/rules/entry-points.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,14 @@ module.exports = {
6262
}
6363

6464
if (returnArgument && returnArgument.type === 'Identifier') {
65-
for (let i = 0; i < callbackBody.length; i++) {
66-
const childNode = callbackBody[i];
67-
68-
if (childNode.type !== 'ExpressionStatement') {
69-
continue;
70-
}
71-
72-
const expressionLeft = childNode.expression.left;
73-
74-
if (
75-
expressionLeft.object.name === returnArgument.name &&
76-
scriptTypeMap[scriptType].entryPoints.includes(expressionLeft.property.name) &&
77-
(expressionLeft.property.type === 'Identifier' ||
78-
expressionLeft.property.type === 'FunctionExpression')
79-
) {
80-
hasValidEntryPoint = true;
81-
break;
82-
}
65+
const returnAssignments = callbackBody.filter(n =>
66+
n.type === 'ExpressionStatement' &&
67+
n.expression.left.type === 'MemberExpression' &&
68+
n.expression.left.object.name === returnArgument.name &&
69+
scriptTypeMap[scriptType].entryPoints.includes(n.expression.left.property.name)
70+
);
71+
if (returnAssignments.length > 0) {
72+
hasValidEntryPoint = true;
8373
}
8474
}
8575

tests/rules/entry-points.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ ruleTester.run('entry-points', rule, {
162162
'});'
163163
].join('\n'),
164164
errors: [{ messageId: 'returnEntryPoint', data: { type: 'ClientScript' }}]
165+
},
166+
{
167+
code: [
168+
'/**',
169+
' * @NScriptType ClientScript',
170+
' */',
171+
'define([], function() {',
172+
' var exports = {};',
173+
' var notTheReturnObject = {};',
174+
' notTheReturnObject.pageInit = x;',
175+
' return exports;',
176+
'});'
177+
].join('\n'),
178+
errors: [{ messageId: 'returnEntryPoint', data: { type: 'ClientScript' }}]
165179
}
166180
]
167181
});

0 commit comments

Comments
 (0)