Skip to content

Commit 2b03aca

Browse files
committed
more robust detection of existing Foo.$injects array
1 parent a938352 commit 2b03aca

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

nginject-comments.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,20 @@ function visitNodeFollowingNgInjectComment(node, ctx) {
4545

4646

4747
function addRemoveInjectsArray(params, posAfterFunctionDeclaration, name) {
48-
const str1 = fmt("{0}.$injects", name);
49-
const str2 = fmt(" = {0};", ctx.stringify(params, ctx.quot));
50-
const str = "\n" + str1 + str2;
48+
const str = fmt("\n{0}.$injects = {1};", name, ctx.stringify(params, ctx.quot));
5149

5250
ctx.triggers.add({
5351
pos: posAfterFunctionDeclaration,
5452
fn: visitNodeFollowingFunctionDeclaration,
5553
});
5654

5755
function visitNodeFollowingFunctionDeclaration(nextNode) {
58-
const hasInjectsArray = (str1 === ctx.src.slice(nextNode.range[0], nextNode.range[0] + str1.length));
56+
const assignment = nextNode.expression;
57+
let lvalue;
58+
const hasInjectsArray = (nextNode.type === "ExpressionStatement" && assignment.type === "AssignmentExpression" &&
59+
assignment.operator === "=" &&
60+
(lvalue = assignment.left).type === "MemberExpression" &&
61+
lvalue.computed === false && lvalue.object.name === name && lvalue.property.name === "$injects");
5962

6063
if (ctx.mode === "rebuild" && hasInjectsArray) {
6164
ctx.fragments.push({

0 commit comments

Comments
 (0)