From 6b01f932b6f9197f2567d8bdf12d5e329b4d8cbf Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 9 Feb 2023 18:59:25 +0200 Subject: [PATCH] feature: add nginject condition --- nginject.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/nginject.js b/nginject.js index 2685788..298d996 100644 --- a/nginject.js +++ b/nginject.js @@ -198,6 +198,31 @@ function matchPrologueDirectives(path) { let matches = directives.map(dir => dir.value.value) .filter(val => prologueDirectives.indexOf(val) !== -1); + const programPath = path.scope.getProgramParent().path; + + let isInjectAdded = false; + + programPath.traverse({ + AssignmentExpression(path) { + const leftPath = path.get('left'); + + if (!leftPath.isMemberExpression()) + return; + + if (!leftPath.get('object').isIdentifier({name: 'run'})) + return; + + if (!leftPath.get('property').isIdentifier({name: '$inject'})) + return; + + isInjectAdded = true; + path.stop(); + } + }); + + if (isInjectAdded) + return false; + if(matches.length){ let match = matches[0].trim(); if(match === "ngInject") return true;