mirror of
https://github.com/bluetech/ng-annotate-patched.git
synced 2026-07-02 08:27:43 +08:00
Support ngInject on export [default] function functionName() {...}
This is somewhat common, even after conversion to ES5, when ES6 modules are still used (e.g. Webpack 2, rollup). So let's try to support it.
This commit is contained in:
@@ -17,6 +17,9 @@ This fork contains the following changes:
|
||||
- Added a `acornOptions` option to the API, to allow overriding or passing
|
||||
extra options to acorn.
|
||||
|
||||
- Added support for ngInject comments on `export [default] function functionName() {...}`
|
||||
declarations.
|
||||
|
||||
- Published to npm under the name `ng-annotate-patched`.
|
||||
|
||||
All work is done on the `fork` branch. The `master` branch corresponds to
|
||||
|
||||
+6
-1
@@ -795,6 +795,9 @@ function judgeInjectArraySuspect(node, ctx) {
|
||||
onode = node.$parent;
|
||||
declaratorName = node.id.name;
|
||||
node = node.init; // var foo = ___;
|
||||
} else if (is.someof(node.type, ["ExportDefaultDeclaration", "ExportNamedDeclaration"])) {
|
||||
onode = node;
|
||||
node = node.declaration;
|
||||
} else {
|
||||
onode = node;
|
||||
}
|
||||
@@ -1023,7 +1026,9 @@ function isFunctionExpressionWithArgs(node) {
|
||||
return node.type === "FunctionExpression" && node.params.length >= 1;
|
||||
}
|
||||
function isFunctionDeclarationWithArgs(node) {
|
||||
return node.type === "FunctionDeclaration" && node.params.length >= 1;
|
||||
// For `export default function() {...}`, `id` is null, which means
|
||||
// we cannot inject it. So ignore that.
|
||||
return node.type === "FunctionDeclaration" && node.params.length >= 1 && node.id !== null;
|
||||
}
|
||||
function isGenericProviderName(node) {
|
||||
return node.type === "Literal" && is.string(node.value);
|
||||
|
||||
@@ -1019,3 +1019,9 @@ myMod.service("a", MyCtrl);
|
||||
|
||||
import "foo";
|
||||
export const bar = "";
|
||||
|
||||
/* @ngInject */
|
||||
export default function exportDefaultFunction($scope) {}
|
||||
|
||||
/* @ngInject */
|
||||
export function exportFunction($scope) {}
|
||||
|
||||
@@ -1062,3 +1062,11 @@ myMod.service("a", MyCtrl);
|
||||
|
||||
import "foo";
|
||||
export const bar = "";
|
||||
|
||||
/* @ngInject */
|
||||
export default function exportDefaultFunction($scope) {}
|
||||
exportDefaultFunction.$inject = ["$scope"];
|
||||
|
||||
/* @ngInject */
|
||||
export function exportFunction($scope) {}
|
||||
exportFunction.$inject = ["$scope"];
|
||||
|
||||
Reference in New Issue
Block a user